本文整理匯總了Java中org.springframework.ldap.core.DirContextOperations.getStringAttributes方法的典型用法代碼示例。如果您正苦於以下問題:Java DirContextOperations.getStringAttributes方法的具體用法?Java DirContextOperations.getStringAttributes怎麽用?Java DirContextOperations.getStringAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.ldap.core.DirContextOperations
的用法示例。
在下文中一共展示了DirContextOperations.getStringAttributes方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mapFromContext
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
public LdapUser mapFromContext(DirContextOperations ctx) throws NamingException,
UnsupportedMemberAffiliationException {
Optional.ofNullable(ctx.getStringAttribute(identifierAttribute)).orElseThrow(() ->
new InvalidSecurityConfigurationException(
"Can not get a username using '" + identifierAttribute + "' attribute to identify the user."));
String username = ctx.getStringAttribute(identifierAttribute);
Optional<String> firstName = Optional.ofNullable(ctx.getStringAttribute(firstNameAttribute));
Optional<String> lastName = Optional.ofNullable(ctx.getStringAttribute(lastNameAttribute));
Optional<String> email = Optional.ofNullable(ctx.getStringAttribute(mailAddressAttribute));
if (StringUtils.hasText(memberOfFilter)) {
String[] memberOf = ctx.getStringAttributes(MEMBER_OF_ATTRIBUTE);
if (!Arrays.asList(memberOf).contains(memberOfFilter)) {
throw new UnsupportedMemberAffiliationException("User '" + username + "' is not a member of '"
+ memberOfFilter + "'");
}
return new LdapUser(username, firstName, lastName, email, memberOf);
}
return new LdapUser(username, firstName, lastName, email);
}
示例2: loadUserAuthorities
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
* Creates the user authority list from the values of the {@code memberOf} attribute
* obtained from the user's Active Directory entry.
*/
@Override
protected Collection<? extends GrantedAuthority> loadUserAuthorities(
DirContextOperations userData, String username, String password) {
String[] groups = userData.getStringAttributes("memberOf");
if (groups == null) {
logger.debug("No values for 'memberOf' attribute.");
return AuthorityUtils.NO_AUTHORITIES;
}
if (logger.isDebugEnabled()) {
logger.debug("'memberOf' attribute values: " + Arrays.asList(groups));
}
ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(
groups.length);
for (String group : groups) {
authorities.add(new SimpleGrantedAuthority(new DistinguishedName(group).removeLast().getValue()));
}
return authorities;
}
示例3: getGrantedAuthorities
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
@Override
public Collection<? extends GrantedAuthority> getGrantedAuthorities(DirContextOperations userData, String username) {
String[] groups = userData.getStringAttributes(memberAttribute);
if (groups == null) {
return Collections.emptySet();
}
return Stream.of(groups)
.map(LdapUtils::newLdapName)
.map(name -> (String)LdapUtils.getValue(name, nameAttribute))
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toSet());
}
示例4: getGrantedAuthorities
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
@Override
public Collection<? extends GrantedAuthority> getGrantedAuthorities(DirContextOperations userData, String username) {
String[] groups = userData.getStringAttributes("memberOf");
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
for (String group : groups) {
LdapRdn authority = new DistinguishedName(group).removeLast();
authorities.add(new SimpleGrantedAuthority(authority.getValue()));
}
return authorities;
}
開發者ID:v5developer,項目名稱:maven-framework-project,代碼行數:12,代碼來源:ActiveDirectoryLdapAuthoritiesPopulator.java
示例5: getLinkForNode
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
@Override
protected String getLinkForNode(DirContextOperations node) {
String[] objectClassValues = node.getStringAttributes("objectClass");
if (containsValue(objectClassValues, "person")) {
Name dn = node.getDn();
String country = encodeValue(LdapUtils.getStringValue(dn, "c"));
String company = encodeValue(LdapUtils.getStringValue(dn, "ou"));
String fullName = encodeValue(LdapUtils.getStringValue(dn, "cn"));
return "showPerson.do?country=" + country + "&company=" + company + "&fullName=" + fullName;
}
else {
return super.getLinkForNode(node);
}
}
示例6: mapBuilderFromContext
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
List<EntityAffiliation.Builder> mapBuilderFromContext(DirContextOperations context) {
List<EntityAffiliation.Builder> retval = new ArrayList<EntityAffiliation.Builder>();
final String primaryAffiliationProperty = getConstants().getPrimaryAffiliationLdapProperty();
final String affiliationProperty = getConstants().getAffiliationLdapProperty();
debug("Got affiliation ", context.getStringAttribute(primaryAffiliationProperty));
debug("Got affiliation ", context.getStringAttribute(affiliationProperty));
String primaryAffiliation = context.getStringAttribute(primaryAffiliationProperty);
int affiliationId = 1;
String affiliationCode = getAffiliationTypeCodeForName(primaryAffiliation);
final EntityAffiliation.Builder aff1 = EntityAffiliation.Builder.create();
aff1.setAffiliationType(EntityAffiliationType.Builder.create(affiliationCode == null ? "AFLT" : affiliationCode));
aff1.setCampusCode(getConstants().getDefaultCampusCode());
aff1.setId("" + affiliationId++);
aff1.setDefaultValue(true);
aff1.setActive(true);
retval.add(aff1);
String[] affiliations = context.getStringAttributes(affiliationProperty);
// Create an empty array to prevent NPE
if (affiliations == null) {
affiliations = new String[] {};
}
for (String affiliation : affiliations) {
if (!StringUtils.equals(affiliation, primaryAffiliation)) {
affiliationCode = getAffiliationTypeCodeForName(affiliation);
if (affiliationCode != null && !hasAffiliation(retval, affiliationCode)) {
final EntityAffiliation.Builder aff = EntityAffiliation.Builder.create();
aff.setAffiliationType(EntityAffiliationType.Builder.create(affiliationCode));
aff.setCampusCode(getConstants().getDefaultCampusCode());
aff.setId("" + affiliationId++);
aff.setDefaultValue(false);
aff.setActive(true);
retval.add(aff);
}
}
}
return retval;
}
示例7: extendUserDetails
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
protected UserDetails extendUserDetails(DirContextOperations ctx, LdapUserDetails userDetails) {
// Full name
String fullNameAttribute = settings.getFullNameAttribute();
if (StringUtils.isBlank(fullNameAttribute)) {
fullNameAttribute = "cn";
}
String fullName = ctx.getStringAttribute(fullNameAttribute);
// Email
String emailAttribute = settings.getEmailAttribute();
if (StringUtils.isBlank(emailAttribute)) {
emailAttribute = "email";
}
String email = ctx.getStringAttribute(emailAttribute);
// Groups
String groupAttribute = settings.getGroupAttribute();
if (StringUtils.isBlank(groupAttribute)) {
groupAttribute = "memberOf";
}
String groupFilter = settings.getGroupFilter();
String[] groups = ctx.getStringAttributes(groupAttribute);
Set<String> parsedGroups;
if (groups != null && groups.length > 0) {
parsedGroups = Arrays.asList(groups).stream()
// Parsing of the group
.map(DistinguishedName::new)
// Filter on OU
.filter(dn -> {
String ou = getValue(dn, "OU");
return StringUtils.isBlank(groupFilter) || StringUtils.equalsIgnoreCase(ou, groupFilter);
})
// Getting the common name
.map(dn -> getValue(dn, "CN"))
// Keeps only the groups being filled in
.filter(StringUtils::isNotBlank)
// As a set
.collect(Collectors.toSet());
} else {
parsedGroups = Collections.emptySet();
}
// OK
return new ExtendedLDAPUserDetails(userDetails, fullName, email, parsedGroups);
}