本文整理匯總了Java中org.springframework.ldap.core.DirContextOperations.setAttributeValue方法的典型用法代碼示例。如果您正苦於以下問題:Java DirContextOperations.setAttributeValue方法的具體用法?Java DirContextOperations.setAttributeValue怎麽用?Java DirContextOperations.setAttributeValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.ldap.core.DirContextOperations
的用法示例。
在下文中一共展示了DirContextOperations.setAttributeValue方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mapToContext
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
protected void mapToContext(final UserOrg entry, final DirContextOperations context) {
context.setAttributeValue("cn", entry.getFirstName() + " " + entry.getLastName());
context.setAttributeValue("sn", entry.getLastName());
context.setAttributeValue("givenName", entry.getFirstName());
context.setAttributeValue(uidAttribute, Normalizer.normalize(entry.getId()));
context.setAttributeValues("mail", entry.getMails().toArray(), true);
// Special and also optional attributes
Optional.ofNullable(departmentAttribute).ifPresent(a -> context.setAttributeValue(a, entry.getDepartment()));
Optional.ofNullable(localIdAttribute).ifPresent(a -> context.setAttributeValue(a, entry.getLocalId()));
}
示例2: mapToContext
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
* Map {@link GroupOrg} to LDAP
*/
@Override
protected void mapToContext(final GroupOrg entry, final DirContextOperations context) {
context.setAttributeValue("cn", entry.getName());
// Dummy member for initial group, due to LDAP compliance of class "groupOfUniqueNames"
context.setAttributeValue(UNIQUE_MEMBER, DEFAULT_MEMBER_DN);
}
示例3: loadUserByUsername
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
@Override
public User loadUserByUsername(Authentication authentication) {
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
DirContextOperations authenticate;
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
// authenticate user
authenticate = authenticator.authenticate(new UsernamePasswordAuthenticationToken(
authentication.getPrincipal(), authentication.getCredentials()));
// fetch user groups
try {
List<String> groups = authoritiesPopulator
.getGrantedAuthorities(authenticate, authenticate.getNameInNamespace()).stream()
.map(a -> a.getAuthority())
.collect(Collectors.toList());
authenticate.setAttributeValue(MEMBEROF_ATTRIBUTE, groups);
} catch (Exception e) {
LOGGER.warn("No group found for user {}", authenticate.getNameInNamespace(), e);
}
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
return createUser(authenticate);
} catch (UsernameNotFoundException notFound) {
throw notFound;
} catch (NamingException ldapAccessFailure) {
throw new InternalAuthenticationServiceException(
ldapAccessFailure.getMessage(), ldapAccessFailure);
}
}
示例4: checkMapping
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
private void checkMapping() {
DirContextOperations ldapUserData = new DirContextAdapter();
for (String scimAttribute : scimToLdapAttributes.keySet()) {
if (scimAttribute.equalsIgnoreCase("password")) {
throw new LdapConfigurationException(
"The password can not be mapped to the SCIM user. Please delete the password mapping from"
+ "the configuration!"
);
}
ldapUserData.setAttributeValue(scimToLdapAttributes.get(scimAttribute), "[email protected]");
}
OsiamLdapUserContextMapper contextMapper = new OsiamLdapUserContextMapper(this);
User user = contextMapper.mapUser(ldapUserData);
contextMapper.mapUpdateUser(user, ldapUserData);
}
示例5: mapToContext
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
* Map a customer to LDAP
*/
protected void mapToContext(final String customer, final DirContextOperations context) {
context.setAttributeValue("ou", customer);
}
示例6: mapToContext
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
* Map {@link CompanyOrg} to LDAP
*/
@Override
protected void mapToContext(final CompanyOrg entry, final DirContextOperations context) {
context.setAttributeValue("ou", entry.getName());
}
示例7: setAmbariAdminAttr
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
* Checks weather user is a member of ambari administrators group in LDAP. If
* yes, sets user's ambari_admin attribute to true
* @param user
* @return
*/
private DirContextOperations setAmbariAdminAttr(DirContextOperations user) {
LdapServerProperties ldapServerProperties =
configuration.getLdapServerProperties();
String baseDn = ldapServerProperties.getBaseDN().toLowerCase();
String groupBase = ldapServerProperties.getGroupBase().toLowerCase();
String groupObjectClass = ldapServerProperties.getGroupObjectClass();
String groupMembershipAttr = ldapServerProperties.getGroupMembershipAttr();
String adminGroupMappingRules =
ldapServerProperties.getAdminGroupMappingRules();
final String groupNamingAttribute =
ldapServerProperties.getGroupNamingAttr();
String groupSearchFilter = ldapServerProperties.getGroupSearchFilter();
//If groupBase is set incorrectly or isn't set - search in BaseDn
int indexOfBaseDn = groupBase.indexOf(baseDn);
groupBase = indexOfBaseDn <= 0 ? "" : groupBase.substring(0,indexOfBaseDn - 1);
StringBuilder filterBuilder = new StringBuilder();
filterBuilder.append("(&(");
filterBuilder.append(groupMembershipAttr);
filterBuilder.append("=");
filterBuilder.append(user.getNameInNamespace());//DN
if ((groupSearchFilter == null) || groupSearchFilter.equals("") ) {
//If groupSearchFilter is not specified, build it from other authorization
// group properties
filterBuilder.append(")(objectclass=");
filterBuilder.append(groupObjectClass);
filterBuilder.append(")(|");
String[] adminGroupMappingRegexs = adminGroupMappingRules.split(",");
for (String adminGroupMappingRegex : adminGroupMappingRegexs) {
filterBuilder.append("(");
filterBuilder.append(groupNamingAttribute);
filterBuilder.append("=");
filterBuilder.append(adminGroupMappingRegex);
filterBuilder.append(")");
}
filterBuilder.append(")");
} else {
filterBuilder.append(")");
filterBuilder.append(groupSearchFilter);
}
filterBuilder.append(")");
AttributesMapper attributesMapper = new AttributesMapper() {
public Object mapFromAttributes(Attributes attrs)
throws NamingException {
return attrs.get(groupNamingAttribute).get();
}
};
LdapTemplate ldapTemplate = new LdapTemplate((getContextSource()));
ldapTemplate.setIgnorePartialResultException(true);
ldapTemplate.setIgnoreNameNotFoundException(true);
List<String> ambariAdminGroups = ldapTemplate.search(
groupBase,filterBuilder.toString(),attributesMapper);
//user has admin role granted, if user is a member of at least 1 group,
// which matches the rules in configuration
if (ambariAdminGroups.size() > 0) {
user.setAttributeValue(AMBARI_ADMIN_LDAP_ATTRIBUTE_KEY, true);
}
return user;
}