Artifactory 中与 LDAP 用户关联的组会在用户登录时进行更新。以下是示例代码,以配置 Artifactory 与 LDAP 集成以及检查用户组是否已更新:
import org.artifactory.security.ArtifactoryAuthenticationFilter
import org.artifactory.security.ArtifactoryLdapAuthenticationProvider
// 配置 Artifactory 与 LDAP 集成
def ldapAuthProvider = ArtifactoryLdapAuthenticationProvider.create(params)
ArtifactoryAuthenticationFilter.addAuthenticationProvider(ldapAuthProvider)
// 绑定用户并检查其关联的组是否已更新
def userName = "user"
def password = "password"
def groups = []
def authentication = ldapAuthProvider.authenticate(userName, password)
if (authentication != null) {
groups = authentication.getAuthorities().collect { it.getAuthority() }
}
println "用户 ${userName} 所在的组为: ${groups}"