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


Java DirContextOperations.getStringAttribute方法代碼示例

本文整理匯總了Java中org.springframework.ldap.core.DirContextOperations.getStringAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java DirContextOperations.getStringAttribute方法的具體用法?Java DirContextOperations.getStringAttribute怎麽用?Java DirContextOperations.getStringAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.ldap.core.DirContextOperations的用法示例。


在下文中一共展示了DirContextOperations.getStringAttribute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: uid2ext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
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;
 }
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:21,代碼來源:SpringLdapExternalUidTranslation.java

示例2: ext2uid

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
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;
 }
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:20,代碼來源:SpringLdapExternalUidTranslation.java

示例3: createUser

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
private User createUser(DirContextOperations authenticate) {
    DefaultUser user = new DefaultUser(authenticate.getStringAttribute(identifierAttribute));

    // add additional information
    Map<String, Object> claims = new HashMap<>();
    if (mapper.getMappers() != null) {
        mapper.getMappers().forEach((k, v) -> {
            claims.put(k, authenticate.getStringAttribute(v));
        });
    } else {
        // default values
        claims.put("sub", authenticate.getStringAttribute("uid"));
        claims.put("email", authenticate.getStringAttribute("mail"));
        claims.put("name", authenticate.getStringAttribute("displayname"));
        claims.put("given_name", authenticate.getStringAttribute("givenname"));
        claims.put("family_name", authenticate.getStringAttribute("sn"));
    }
    user.setAdditonalInformation(claims);

    // set user roles
    user.setRoles(getUserRoles(authenticate));

    return user;
}
 
開發者ID:gravitee-io,項目名稱:graviteeio-access-management,代碼行數:25,代碼來源:LdapAuthenticationProvider.java

示例4: mapUserFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
 * Mapper for custom role
 *
 * @param dirContextOperations
 * @param username
 * @param authorities
 * @return
 */
@Override
public UserDetails mapUserFromContext(DirContextOperations dirContextOperations, String username, Collection<? extends GrantedAuthority> authorities) {
    logger.debug("Mapping user from context");

    UserDetails userDetails = null;

    try {
        userDetails = userDetailsServiceImpl.loadUserByUsername(username);
    } catch (UsernameNotFoundException e) {
        // 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");

        userDetails = userDetailsServiceImpl.createBasicUser(username, givenName, surname, commonName);
    }

    return userDetails;
}
 
開發者ID:box,項目名稱:mojito,代碼行數:29,代碼來源:UserDetailsContextMapperImpl.java

示例5: mapUserFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) {
    User user = userRepository.findOne(username);
    if (user != null)
        return user;

    String employeeType = ctx.getStringAttribute("employeeType");
    if (employeeType.equals("PDIPAS"))
        user = new Professor();
    else
        user = new Student();
    user.setUsername(username);
    user.setEmail(ctx.getStringAttribute("mail"));

    return userRepository.save(user);
}
 
開發者ID:UdL-EPS-SoftArch,項目名稱:entsoftarch-1516-server,代碼行數:17,代碼來源:WebSecurityConfig.java

示例6: mapBuilderFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
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;
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:19,代碼來源:EntityAddressMapper.java

示例7: mapBuilderFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
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;
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:26,代碼來源:EntityNameMapper.java

示例8: mapBuilderFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
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;
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:20,代碼來源:EntityTypeContactInfoMapper.java

示例9: mapBuilderFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
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;
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:27,代碼來源:EntityPhoneMapper.java

示例10: mapUserFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
@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("role-mapper."+granted.getAuthority());
			if (!StringUtils.isEmpty(mappedAuthority)) {
				mappedAuthorities.add(new SimpleGrantedAuthority(mappedAuthority));
			}
		}
	} catch (Exception e){
		LOGGER.error("Failed to load mapped authorities", e);
	}

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

	userDetails.setFirstname(ctx.getStringAttribute("sn"));
	userDetails.setLastname(ctx.getStringAttribute("givenName"));
	userDetails.setEmail(ctx.getStringAttribute("mail"));
	userDetails.setSource(LdapIdentityProvider.PROVIDER_TYPE);
	userDetails.setSourceId(ctx.getNameInNamespace());

	return userDetails;
}
 
開發者ID:gravitee-io,項目名稱:gravitee-management-rest-api,代碼行數:27,代碼來源:UserDetailsContextPropertiesMapper.java

示例11: mapUserFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
 * Main overridden function, maps specific fields from the context object to
 * the user details object.
 * 
 * @param ctx
 *            - directory context
    * @param username - The username
    * @param authority - Authorities that this user has been determined to have
 * @return userDetails object
 */
   @Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authority) {
	OWFUserDetailsImpl userDetails = null;


       Collection<OwfGroup> groups = determineOwfGroups(ctx.getDn()
               .toString());

       userDetails = new OWFUserDetailsImpl(ctx
               .getStringAttribute("cn"), ctx.getObjectAttribute(
               "userpassword").toString(), authority, groups);

       userDetails.setDisplayName(ctx.getStringAttribute("givenname"));
       userDetails.setEmail(ctx.getStringAttribute("mail"));

       log.debug("user details [" + userDetails.toString() + "].");

	return userDetails;
}
 
開發者ID:ozoneplatform,項目名稱:owf-security,代碼行數:30,代碼來源:OWFUserDetailsContextMapper.java

示例12: mapBuilderFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
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;
}
 
開發者ID:kuali,項目名稱:rice,代碼行數:19,代碼來源:EntityEmploymentMapper.java

示例13: mapBuilderFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
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;
}
 
開發者ID:kuali,項目名稱:rice,代碼行數:17,代碼來源:PrincipalMapper.java

示例14: 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

示例15: mapUserFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
@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);
  }
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:16,代碼來源:UniTimeUserContextMapper.java


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