Java Code Examples for org.springframework.ldap.core.DirContextOperations#getStringAttributes()

The following examples show how to use org.springframework.ldap.core.DirContextOperations#getStringAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActiveDirectoryLdapAuthoritiesPopulator.java    From maven-framework-project with MIT License 5 votes vote down vote up
@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;
}
 
Example 2
Source File: DefaultController.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example 3
Source File: DefaultController.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example 4
Source File: GatekeeperOpenLDAPAuthorizationService.java    From Gatekeeper with Apache License 2.0 4 votes vote down vote up
@Override
protected Object doMapFromContext(DirContextOperations ctx) {
    return ctx.getStringAttributes("memberOf");
}
 
Example 5
Source File: EntityAffiliationMapper.java    From rice with Educational Community License v2.0 4 votes vote down vote up
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;
}