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

The following examples show how to use org.springframework.ldap.core.DirContextOperations#getStringAttribute() . 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: SpringLdapExternalUidTranslation.java    From unitime with Apache License 2.0 6 votes vote down vote up
public String ext2uid(String externalUserId) {
 	String externalIdAttribute = ApplicationProperty.AuthenticationLdapIdAttribute.value();
 	if ("uid".equals(externalIdAttribute)) return externalUserId; // Nothing to translate
     try {
     	
     	ContextSource source = (ContextSource)SpringApplicationContextHolder.getBean("unitimeLdapContextSource");

String query = ApplicationProperty.AuthenticationLdapUserId2Login.value().replace("%", externalIdAttribute);

SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(source);
DirContextOperations user = template.retrieveEntry(query.replaceAll("\\{0\\}", externalIdAttribute), new String[] {"uid"});

return user == null ? null : user.getStringAttribute("uid");

     } catch (Exception e) {
     	sLog.warn("Unable to translate " + externalIdAttribute + " to uid: " + e.getMessage());
     }
     return null;
 }
 
Example 2
Source File: EntityTypeContactInfoMapper.java    From rice with Educational Community License v2.0 6 votes vote down vote up
EntityTypeContactInfo.Builder mapBuilderFromContext(DirContextOperations context) {
    final String entityId       = (String) context.getStringAttribute(getConstants().getKimLdapIdProperty());
    final String entityTypeCode = (String ) getConstants().getPersonEntityTypeCode();

    final EntityTypeContactInfo.Builder builder = EntityTypeContactInfo.Builder.create(entityId, entityTypeCode); 
    final EntityAddress.Builder address = getAddressMapper().mapBuilderFromContext(context);
    final List<EntityAddress.Builder> addresses = new ArrayList<EntityAddress.Builder>();
    addresses.add(address);
    final List<EntityEmail.Builder> email = new ArrayList<EntityEmail.Builder>();
    email.add(getEmailMapper().mapBuilderFromContext(context));
    final List<EntityPhone.Builder> phone = new ArrayList<EntityPhone.Builder>();
    phone.add(getPhoneMapper().mapBuilderFromContext(context));
    builder.setAddresses(addresses);
    builder.setEmailAddresses(email);
    builder.setPhoneNumbers(phone);
    debug("Created Entity Type with code ", builder.getEntityTypeCode());                

    return builder;
}
 
Example 3
Source File: EntityPhoneMapper.java    From rice with Educational Community License v2.0 6 votes vote down vote up
EntityPhone.Builder mapBuilderFromContext(DirContextOperations context, boolean isdefault) {        
    final EntityPhone.Builder builder = EntityPhone.Builder.create();
    debug("Looking up attribute from context ", getConstants().getEmployeePhoneLdapProperty());
    final String pn = context.getStringAttribute(getConstants().getEmployeePhoneLdapProperty());
    
    if (isBlank(pn) || equalsIgnoreCase("NA", pn)) {
        debug("Got nothing. Giving nothing back.");
        return null;
    }
    
    String phoneNumber = pn;
    if (pn.length() >= 10) {
        phoneNumber = pn.substring(0, 3) + "-" + pn.substring(3, 6) + "-" + pn.substring(6);
    } else if (pn.length() >= 6) {
                phoneNumber = pn.substring(0, 3) + "-" + pn.substring(3);
    }
    final String countryCode = getConstants().getDefaultCountryCode();
    
    builder.setCountryCode(countryCode);
    builder.setPhoneNumber(phoneNumber);
    builder.setPhoneType(CodedAttribute.Builder.create("WORK"));
    builder.setActive(true);
    builder.setDefaultValue(isdefault);

    return builder;
}
 
Example 4
Source File: EntityNameMapper.java    From rice with Educational Community License v2.0 6 votes vote down vote up
EntityName.Builder mapBuilderFromContext(DirContextOperations context, boolean isdefault) {        
    final EntityName.Builder person = EntityName.Builder.create();
    person.setEntityId(context.getStringAttribute(getConstants().getKimLdapIdProperty()));
    person.setId(context.getStringAttribute(getConstants().getKimLdapIdProperty()));
    
    final String fullName = (String) context.getStringAttribute(getConstants().getGivenNameLdapProperty());
    
    if (fullName != null) {
        final String[] name = fullName.split(" ");
        person.setFirstName(name[0]);
        if (name.length > 1) {
            person.setMiddleName(name[1]);
        }
    }
    else {
        person.setFirstName(fullName);
    }
    
    person.setLastName(context.getStringAttribute(getConstants().getSnLdapProperty()));
    person.setDefaultValue(isdefault);
    person.setActive(true);
    person.setNameType(CodedAttribute.Builder.create("PRI"));
    
    return person;
}
 
Example 5
Source File: PrincipalMapper.java    From rice with Educational Community License v2.0 6 votes vote down vote up
Principal.Builder mapBuilderFromContext(DirContextOperations context) {
    final String entityId      = context.getStringAttribute(getConstants().getKimLdapIdProperty());
    final String principalName = context.getStringAttribute(getConstants().getKimLdapNameProperty());
    final Principal.Builder person = Principal.Builder.create(principalName);
    
    if (entityId == null) {
        throw new InvalidLdapEntityException("LDAP Search Results yielded an invalid result with attributes " 
                                             + context.getAttributes());
    }
    
    person.setPrincipalId(entityId);
    person.setEntityId(entityId);
    person.setActive(isPersonActive(context));

    return person;
}
 
Example 6
Source File: EntityEmploymentMapper.java    From rice with Educational Community License v2.0 6 votes vote down vote up
EntityEmployment.Builder mapBuilderFromContext(DirContextOperations context) {
    final String departmentCode = context.getStringAttribute(getConstants().getDepartmentLdapProperty());
    
    if (departmentCode == null) {
        return null;
    }

    final EntityEmployment.Builder employee = EntityEmployment.Builder.create();
    employee.setId(context.getStringAttribute(getConstants().getEmployeeIdProperty()));
    employee.setEmployeeStatus(
            CodedAttribute.Builder.create(context.getStringAttribute(getConstants().getEmployeeStatusProperty())));
    //employee.setEmployeeTypeCode(context.getStringAttribute(getConstants().getEmployeeTypeProperty()));
    employee.setEmployeeType(CodedAttribute.Builder.create("P"));
    employee.setBaseSalaryAmount(KualiDecimal.ZERO);
    
    employee.setActive(true);
    return employee;
}
 
Example 7
Source File: EntityAddressMapper.java    From rice with Educational Community License v2.0 6 votes vote down vote up
EntityAddress.Builder mapBuilderFromContext(DirContextOperations context, boolean isdefault) {        
    final EntityAddress.Builder builder = EntityAddress.Builder.create();
    final String line1              = context.getStringAttribute("employeePrimaryDeptName");
    final String line2              = context.getStringAttribute("employeePoBox");
    final String city               = context.getStringAttribute("employeeCity");
    final String stateProvinceCode  = context.getStringAttribute("employeeState");
    final String postalCode         = context.getStringAttribute("employeeZip");
    
    builder.setAddressType(CodedAttribute.Builder.create("WORK"));
    builder.setLine1(line1);
    builder.setLine2(line2);
    builder.setCity(city);
    builder.setStateProvinceCode(stateProvinceCode);
    builder.setPostalCode(postalCode);
    builder.setDefaultValue(isdefault);
    builder.setActive(true);
    return builder;
}
 
Example 8
Source File: SpringLdapExternalUidTranslation.java    From unitime with Apache License 2.0 6 votes vote down vote up
public String uid2ext(String uid) {
 	String externalIdAttribute = ApplicationProperty.AuthenticationLdapIdAttribute.value();
 	if ("uid".equals(externalIdAttribute)) return uid; // Nothing to translate
     try {
     	
ContextSource source = (ContextSource)SpringApplicationContextHolder.getBean("unitimeLdapContextSource");

String query = ApplicationProperty.AuthenticationLdapLogin2UserId.value();

SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(source);
DirContextOperations user = template.retrieveEntry(query.replaceAll("\\{0\\}", uid), new String[] {externalIdAttribute});

return user == null ? null : user.getStringAttribute(externalIdAttribute);

     } catch (Exception e) {
     	sLog.warn("Unable to translate uid to " + externalIdAttribute + ": " + e.getMessage());
     }
     
     return null;
 }
 
Example 9
Source File: SpringLdapExternalUidLookup.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public UserInfo doLookup(String uid) throws Exception {
	try {
		ContextSource source = (ContextSource)SpringApplicationContextHolder.getBean("unitimeLdapContextSource");
		
		String query = ApplicationProperty.AuthenticationLdapIdentify.value(); 
		String idAttributeName = ApplicationProperty.AuthenticationLdapIdAttribute.value();

		SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(source);
		DirContextOperations user = template.retrieveEntry(query.replaceAll("\\{0\\}", uid), new String[] {"uid", idAttributeName, "cn", "givenName", "sn", "mail"});

		if (user == null || user.getStringAttribute(idAttributeName) == null)
			return null;
           
       	UserInfo info = new UserInfo();
       	info.setExternalId(user.getStringAttribute(idAttributeName));
       	
       	info.setUserName(user.getStringAttribute("uid"));
       	if (info.getUserName() == null) info.setUserName(uid);
       	info.setName(user.getStringAttribute("cn"));
       	info.setFirstName(user.getStringAttribute("givenName"));
       	info.setLastName(user.getStringAttribute("sn"));
       	info.setEmail(user.getStringAttribute("mail"));

       	if (info.getEmail() == null) {
           	String email = info.getUserName() + "@";
       		for (String x: user.getNameInNamespace().split(","))
       			if (x.startsWith("dc=")) email += (email.endsWith("@") ? "" : ".") + x.substring(3);
           	if (!email.endsWith("@")) info.setEmail(email);
       	}
       	
       	return info;
	} catch (Exception e) {
		sLog.warn("Lookup for " + uid + " failed: " + e.getMessage());
	}

	return null;
}
 
Example 10
Source File: UniTimeUserContextMapper.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
  public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) {
String userId = username;

if (!authorities.isEmpty())
	userId = authorities.iterator().next().getAuthority();

if (iTranslation != null && ApplicationProperty.AuthenticationLdapIdTranslate.isTrue())
	userId = iTranslation.translate(userId, Source.LDAP, Source.User);

if (ApplicationProperty.AuthenticationLdapIdTrimLeadingZeros.isTrue())
	while (userId.startsWith("0")) userId = userId.substring(1);

return new UniTimeUserContext(userId, username, ctx.getStringAttribute("cn"), null);
  }
 
Example 11
Source File: LdapClient.java    From taskana with Apache License 2.0 5 votes vote down vote up
@Override
public AccessIdRepresentationModel doMapFromContext(final DirContextOperations context) {
  final AccessIdRepresentationModel accessId = new AccessIdRepresentationModel();
  accessId.setAccessId(context.getStringAttribute(getUserIdAttribute()));
  String firstName = context.getStringAttribute(getUserFirstnameAttribute());
  String lastName = context.getStringAttribute(getUserLastnameAttribute());
  accessId.setName(String.format("%s, %s", lastName, firstName));
  return accessId;
}
 
Example 12
Source File: OsiamLdapUserContextMapper.java    From osiam with MIT License 5 votes vote down vote up
private Name getName(DirContextOperations ldapUserData) {
    Name name = null;
    Name.Builder builder = new Name.Builder();
    boolean nameFound = false;

    for (String scimAttribute : scimLdapAttributes.scimAttributes()) {
        String ldapValue = ldapUserData.getStringAttribute(scimLdapAttributes.toLdapAttribute(scimAttribute));
        if (!scimAttribute.startsWith("name.")) {
            continue;
        }
        nameFound = true;
        switch (scimAttribute) {
        case "name.familyName":
            builder.setFamilyName(ldapValue);
            break;
        case "name.formatted":
            builder.setFormatted(ldapValue);
            break;
        case "name.givenName":
            builder.setGivenName(ldapValue);
            break;
        case "name.honorificPrefix":
            builder.setHonorificPrefix(ldapValue);
            break;
        case "name.honorificSuffix":
            builder.setHonorificSuffix(ldapValue);
            break;
        case "name.middleName":
            builder.setMiddleName(ldapValue);
            break;
        default:
            throw createAttributeNotRecognizedException(scimAttribute);
        }
    }

    if (nameFound) {
        name = builder.build();
    }
    return name;
}
 
Example 13
Source File: UserDetailsContextPropertiesMapper.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) {
	List<GrantedAuthority> mappedAuthorities = new ArrayList<>();
	try {
		for (GrantedAuthority granted : authorities) {
			String mappedAuthority = environment.getProperty("authentication.group.role.mapper."+granted.getAuthority());
			if (mappedAuthority != null && !mappedAuthority.isEmpty()) {
				mappedAuthorities.add(new SimpleGrantedAuthority(mappedAuthority));
			}
		}
	} catch (Exception e){
		LOGGER.error("Failed to load mapped authorities", e);
	}

	io.gravitee.rest.api.idp.api.authentication.UserDetails userDetails =
			new io.gravitee.rest.api.idp.api.authentication.UserDetails(
					ctx.getStringAttribute(identifierAttribute), "", mappedAuthorities);

	String userPhotoAttribute = environment.getProperty("authentication.user.photo-attribute");
       if(userPhotoAttribute == null) {
           userPhotoAttribute = "jpegPhoto";
       }

	userDetails.setFirstname(ctx.getStringAttribute(LDAP_ATTRIBUTE_FIRSTNAME));
	userDetails.setLastname(ctx.getStringAttribute(LDAP_ATTRIBUTE_LASTNAME));
	userDetails.setEmail(ctx.getStringAttribute(LDAP_ATTRIBUTE_MAIL));
	userDetails.setSource(LdapIdentityProvider.PROVIDER_TYPE);
	userDetails.setSourceId(ctx.getNameInNamespace());
	userDetails.setPicture((byte [])ctx.getObjectAttribute(userPhotoAttribute));

	return userDetails;
}
 
Example 14
Source File: UserDetailsContextMapperImpl.java    From mojito with Apache License 2.0 5 votes vote down vote up
User getOrCreateUser(DirContextOperations dirContextOperations, String username) {
    User user = userRepository.findByUsername(username);

    if (user == null || user.getPartiallyCreated()) {
        // THese are pretty standard LDAP attributes so we can expect them to be here
        // https://tools.ietf.org/html/rfc4519
        String givenName = dirContextOperations.getStringAttribute("givenname");
        String surname = dirContextOperations.getStringAttribute("sn");
        String commonName = dirContextOperations.getStringAttribute("cn");

        user = userService.createOrUpdateBasicUser(user, username, givenName, surname, commonName);
    }

    return user;
}
 
Example 15
Source File: ApolloLdapAuthenticationProvider.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
  Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, this.messages
      .getMessage("LdapAuthenticationProvider.onlySupports",
          "Only UsernamePasswordAuthenticationToken is supported"));
  UsernamePasswordAuthenticationToken userToken = (UsernamePasswordAuthenticationToken) authentication;
  String username = userToken.getName();
  String password = (String) authentication.getCredentials();
  if (this.logger.isDebugEnabled()) {
    this.logger.debug("Processing authentication request for user: " + username);
  }

  if (!StringUtils.hasLength(username)) {
    throw new BadCredentialsException(
        this.messages.getMessage("LdapAuthenticationProvider.emptyUsername", "Empty Username"));
  }
  if (!StringUtils.hasLength(password)) {
    throw new BadCredentialsException(this.messages
        .getMessage("AbstractLdapAuthenticationProvider.emptyPassword", "Empty Password"));
  }
  Assert.notNull(password, "Null password was supplied in authentication token");
  DirContextOperations userData = this.doAuthentication(userToken);
  String loginId = userData.getStringAttribute(properties.getMapping().getLoginId());
  UserDetails user = this.userDetailsContextMapper.mapUserFromContext(userData, loginId,
      this.loadUserAuthorities(userData, loginId, (String) authentication.getCredentials()));
  return this.createSuccessfulAuthentication(userToken, user);
}
 
Example 16
Source File: OsiamLdapUserContextMapper.java    From osiam with MIT License 4 votes vote down vote up
private List<Address> getAddresses(DirContextOperations ldapUserData) {
    List<Address> addresses = new ArrayList<>();
    Address.Builder builder = new Address.Builder();
    boolean addressFound = false;

    for (String scimAttribute : scimLdapAttributes.scimAttributes()) {
        String ldapValue = ldapUserData.getStringAttribute(scimLdapAttributes.toLdapAttribute(scimAttribute));
        if (!scimAttribute.startsWith("address.")) {
            continue;
        }
        addressFound = true;
        switch (scimAttribute) {
        case "address.country":
            builder.setCountry(ldapValue);
            break;
        case "address.formatted":
            builder.setFormatted(ldapValue);
            break;
        case "address.locality":
            builder.setLocality(ldapValue);
            break;
        case "address.postalCode":
            builder.setPostalCode(ldapValue);
            break;
        case "address.region":
            builder.setRegion(ldapValue);
            break;
        case "address.streetAddress":
            builder.setStreetAddress(ldapValue);
            break;
        default:
            throw createAttributeNotRecognizedException(scimAttribute);
        }
    }

    if (addressFound) {
        builder.setType(new Address.Type(LdapAuthentication.LDAP_PROVIDER));
        addresses.add(builder.build());
    }
    return addresses;
}
 
Example 17
Source File: OsiamLdapUserContextMapper.java    From osiam with MIT License 4 votes vote down vote up
public UpdateUser mapUpdateUser(User user, DirContextOperations ldapUserData) {

        UpdateUser.Builder updateBuilder = new UpdateUser.Builder();

        for (String scimAttribute : scimLdapAttributes.scimAttributes()) {
            String ldapValue = ldapUserData.getStringAttribute(scimLdapAttributes.toLdapAttribute(scimAttribute));

            if (ldapValue == null) {
                ldapValue = "";
            }

            switch (scimAttribute) {
            case "userName":
                break;
            case "displayName":
                updateBuilder.updateDisplayName(ldapValue);
                break;
            case "email":
                updateEmail(updateBuilder, user.getEmails(), ldapValue);
                break;
            case "entitlement":
                updateEntitlement(updateBuilder, user.getEntitlements(), ldapValue);
                break;
            case "externalId":
                updateBuilder.updateExternalId(ldapValue);
                break;
            case "im":
                updateIm(updateBuilder, user.getIms(), ldapValue);
                break;
            case "locale":
                updateBuilder.updateLocale(ldapValue);
                break;
            case "nickName":
                updateBuilder.updateNickName(ldapValue);
                break;
            case "phoneNumber":
                updatePhoneNumber(updateBuilder, user.getPhoneNumbers(), ldapValue);
                break;
            case "photo":
                updatePhoto(updateBuilder, user.getPhotos(), ldapValue, scimAttribute);
                break;
            case "preferredLanguage":
                updateBuilder.updatePreferredLanguage(ldapValue);
                break;
            case "profileUrl":
                updateBuilder.updateProfileUrl(ldapValue);
                break;
            case "role":
                updateRole(updateBuilder, user.getRoles(), ldapValue);
                break;
            case "timezone":
                updateBuilder.updateTimezone(ldapValue);
                break;
            case "title":
                updateBuilder.updateTitle(ldapValue);
                break;
            case "userType":
                updateBuilder.updateUserType(ldapValue);
                break;
            case "x509Certificate":
                updateX509Certificate(updateBuilder, user.getX509Certificates(), ldapValue);
                break;
            default:
                if (!scimAttribute.startsWith("address.") && !scimAttribute.startsWith("name.")) {
                    throw createAttributeNotRecognizedException(scimAttribute);
                }
            }
        }

        updateAddress(updateBuilder, user.getAddresses(), ldapUserData);
        updateName(updateBuilder, ldapUserData);

        return updateBuilder.build();
    }
 
Example 18
Source File: EntityDefaultMapper.java    From rice with Educational Community License v2.0 4 votes vote down vote up
EntityDefault.Builder mapBuilderFromContext(DirContextOperations context) {
    
    final String entityId = context.getStringAttribute(getConstants().getKimLdapIdProperty());
    final String principalName = context.getStringAttribute(getConstants().getKimLdapNameProperty());

    final EntityDefault.Builder person = EntityDefault.Builder.create(entityId);
    
    if (entityId == null) {
        throw new InvalidLdapEntityException("LDAP Search Results yielded an invalid result with attributes " 
                                             + context.getAttributes());
    }
    
    person.setAffiliations(new ArrayList<EntityAffiliation.Builder>());
    person.setExternalIdentifiers(new ArrayList<EntityExternalIdentifier.Builder>());
    
    final EntityExternalIdentifier.Builder externalId = EntityExternalIdentifier.Builder.create();
    externalId.setExternalIdentifierTypeCode(getConstants().getTaxExternalIdTypeCode());
    externalId.setExternalId(entityId);
    person.getExternalIdentifiers().add(externalId);
    
    person.setAffiliations(getAffiliationMapper().mapBuilderFromContext(context));
    
    person.setEntityTypeContactInfos(new ArrayList<EntityTypeContactInfoDefault.Builder>());
    person.getEntityTypeContactInfos().add(getEntityTypeContactInfoDefaultMapper().mapBuilderFromContext(context));
    
    person.setName(getDefaultNameMapper().mapBuilderFromContext(context));
    person.setEntityId(entityId);
    
    person.setEmployment(getEmploymentMapper().mapBuilderFromContext(context));

    person.setEntityId(entityId);
    person.setPrincipals(new ArrayList<Principal.Builder>()); 
    //inactivate unless we find a matching affiliation
    person.setActive(true);
    
    final Principal.Builder defaultPrincipal = Principal.Builder.create(principalName);
    defaultPrincipal.setPrincipalId(entityId);
    defaultPrincipal.setEntityId(entityId);

    person.getPrincipals().add(defaultPrincipal);
    
    return person;
}
 
Example 19
Source File: EntityMapper.java    From rice with Educational Community License v2.0 4 votes vote down vote up
Entity.Builder mapBuilderFromContext(DirContextOperations context) {
    
    final String entityId      = context.getStringAttribute(getConstants().getKimLdapIdProperty());
    final String principalName = context.getStringAttribute(getConstants().getKimLdapNameProperty());

    final Entity.Builder person = Entity.Builder.create();
    person.setId(entityId);
    
    if (entityId == null) {
        throw new InvalidLdapEntityException("LDAP Search Results yielded an invalid result with attributes " 
                                             + context.getAttributes());
    }
    
    person.setAffiliations(new ArrayList<EntityAffiliation.Builder>());
    person.setExternalIdentifiers(new ArrayList<EntityExternalIdentifier.Builder>());
    
    final EntityExternalIdentifier.Builder externalId = EntityExternalIdentifier.Builder.create();
    externalId.setExternalIdentifierTypeCode(getConstants().getTaxExternalIdTypeCode());
    externalId.setExternalId(entityId);
    person.getExternalIdentifiers().add(externalId);
    
    person.setAffiliations(getAffiliationMapper().mapBuilderFromContext(context));
    
    person.setEntityTypes(new ArrayList<EntityTypeContactInfo.Builder>());
    person.getEntityTypeContactInfos().add(getEntityTypeContactInfoMapper().mapBuilderFromContext(context));
    
    final List<EntityName.Builder> names = new ArrayList<EntityName.Builder>();
    final EntityName.Builder name = getDefaultNameMapper().mapBuilderFromContext(context);
    names.add(name);
    name.setDefaultValue(true);
    person.setNames(names);
    person.setId(entityId);
    
    final EntityEmployment.Builder employmentInfo = (EntityEmployment.Builder) getEmploymentMapper().mapFromContext(context);
    final EntityAffiliation.Builder employeeAffiliation = getAffiliation(getConstants().getEmployeeAffiliationCodes(), person);
    
    //only add employee information if we have an employee affiliation, otherwise ignore
    if (employeeAffiliation != null && employmentInfo != null) {
        employeeAffiliation.getAffiliationType().setEmploymentAffiliationType(true);
        employmentInfo.setEntityAffiliation(employeeAffiliation);
        person.getEmploymentInformation().add(employmentInfo);
    }
    
    person.setPrincipals(new ArrayList<Principal.Builder>());
    person.setActive(true);
    
    final Principal.Builder defaultPrincipal = Principal.Builder.create(principalName);
    defaultPrincipal.setPrincipalId(entityId);
    defaultPrincipal.setEntityId(entityId);
    
    person.getPrincipals().add(defaultPrincipal);
    
    return person;
}
 
Example 20
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;
}