當前位置: 首頁>>代碼示例>>Java>>正文


Java DirContextOperations.getStringAttributes方法代碼示例

本文整理匯總了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);
}
 
開發者ID:synyx,項目名稱:urlaubsverwaltung,代碼行數:27,代碼來源:LdapUserMapper.java

示例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;
}
 
開發者ID:gustajz,項目名稱:parking-api,代碼行數:29,代碼來源:ActiveDirectoryAliasLdapAuthenticationProvider.java

示例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());
}
 
開發者ID:LIBCAS,項目名稱:ARCLib,代碼行數:15,代碼來源:ADAuthoritiesPopulator.java

示例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);
	}
}
 
開發者ID:spring-projects,項目名稱:spring-ldap,代碼行數:16,代碼來源:DefaultController.java

示例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;
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:44,代碼來源:EntityAffiliationMapper.java

示例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);
}
 
開發者ID:nemerosa,項目名稱:ontrack,代碼行數:43,代碼來源:ConfigurableUserDetailsContextMapper.java


注:本文中的org.springframework.ldap.core.DirContextOperations.getStringAttributes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。