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


Java DirContextOperations.setAttributeValue方法代碼示例

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


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

示例1: mapToContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
protected void mapToContext(final UserOrg entry, final DirContextOperations context) {
	context.setAttributeValue("cn", entry.getFirstName() + " " + entry.getLastName());
	context.setAttributeValue("sn", entry.getLastName());
	context.setAttributeValue("givenName", entry.getFirstName());
	context.setAttributeValue(uidAttribute, Normalizer.normalize(entry.getId()));
	context.setAttributeValues("mail", entry.getMails().toArray(), true);

	// Special and also optional attributes
	Optional.ofNullable(departmentAttribute).ifPresent(a -> context.setAttributeValue(a, entry.getDepartment()));
	Optional.ofNullable(localIdAttribute).ifPresent(a -> context.setAttributeValue(a, entry.getLocalId()));
}
 
開發者ID:ligoj,項目名稱:plugin-id-ldap,代碼行數:12,代碼來源:UserLdapRepository.java

示例2: mapToContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
 * Map {@link GroupOrg} to LDAP
 */
@Override
protected void mapToContext(final GroupOrg entry, final DirContextOperations context) {
	context.setAttributeValue("cn", entry.getName());
	// Dummy member for initial group, due to LDAP compliance of class "groupOfUniqueNames"
	context.setAttributeValue(UNIQUE_MEMBER, DEFAULT_MEMBER_DN);
}
 
開發者ID:ligoj,項目名稱:plugin-id-ldap,代碼行數:10,代碼來源:GroupLdapRepository.java

示例3: loadUserByUsername

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
@Override
public User loadUserByUsername(Authentication authentication) {
    try {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        DirContextOperations authenticate;
        try {
            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

            // authenticate user
            authenticate = authenticator.authenticate(new UsernamePasswordAuthenticationToken(
                    authentication.getPrincipal(), authentication.getCredentials()));

            // fetch user groups
            try {
                List<String> groups = authoritiesPopulator
                        .getGrantedAuthorities(authenticate, authenticate.getNameInNamespace()).stream()
                        .map(a -> a.getAuthority())
                        .collect(Collectors.toList());
                authenticate.setAttributeValue(MEMBEROF_ATTRIBUTE, groups);
            } catch (Exception e) {
                LOGGER.warn("No group found for user {}", authenticate.getNameInNamespace(), e);
            }
        } finally {
            Thread.currentThread().setContextClassLoader(classLoader);
        }

        return createUser(authenticate);
    } catch (UsernameNotFoundException notFound) {
        throw notFound;
    } catch (NamingException ldapAccessFailure) {
        throw new InternalAuthenticationServiceException(
                ldapAccessFailure.getMessage(), ldapAccessFailure);
    }
}
 
開發者ID:gravitee-io,項目名稱:graviteeio-access-management,代碼行數:35,代碼來源:LdapAuthenticationProvider.java

示例4: checkMapping

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
private void checkMapping() {
    DirContextOperations ldapUserData = new DirContextAdapter();
    for (String scimAttribute : scimToLdapAttributes.keySet()) {
        if (scimAttribute.equalsIgnoreCase("password")) {
            throw new LdapConfigurationException(
                    "The password can not be mapped to the SCIM user. Please delete the password mapping from"
                            + "the configuration!"
            );
        }
        ldapUserData.setAttributeValue(scimToLdapAttributes.get(scimAttribute), "[email protected]");
    }
    OsiamLdapUserContextMapper contextMapper = new OsiamLdapUserContextMapper(this);
    User user = contextMapper.mapUser(ldapUserData);
    contextMapper.mapUpdateUser(user, ldapUserData);
}
 
開發者ID:osiam,項目名稱:auth-server,代碼行數:16,代碼來源:ScimToLdapAttributeMapping.java

示例5: mapToContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
 * Map a customer to LDAP
 */
protected void mapToContext(final String customer, final DirContextOperations context) {
	context.setAttributeValue("ou", customer);
}
 
開發者ID:ligoj,項目名稱:plugin-id-ldap,代碼行數:7,代碼來源:ProjectCustomerLdapRepository.java

示例6: mapToContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
 * Map {@link CompanyOrg} to LDAP
 */
@Override
protected void mapToContext(final CompanyOrg entry, final DirContextOperations context) {
	context.setAttributeValue("ou", entry.getName());
}
 
開發者ID:ligoj,項目名稱:plugin-id-ldap,代碼行數:8,代碼來源:CompanyLdapRepository.java

示例7: setAmbariAdminAttr

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
 *  Checks weather user is a member of ambari administrators group in LDAP. If
 *  yes, sets user's ambari_admin attribute to true
 * @param user
 * @return
 */
private DirContextOperations setAmbariAdminAttr(DirContextOperations user) {
  LdapServerProperties ldapServerProperties =
      configuration.getLdapServerProperties();

  String baseDn = ldapServerProperties.getBaseDN().toLowerCase();
  String groupBase = ldapServerProperties.getGroupBase().toLowerCase();
  String groupObjectClass = ldapServerProperties.getGroupObjectClass();
  String groupMembershipAttr = ldapServerProperties.getGroupMembershipAttr();
  String adminGroupMappingRules =
      ldapServerProperties.getAdminGroupMappingRules();
  final String groupNamingAttribute =
      ldapServerProperties.getGroupNamingAttr();
  String groupSearchFilter = ldapServerProperties.getGroupSearchFilter();

  //If groupBase is set incorrectly or isn't set - search in BaseDn
  int indexOfBaseDn = groupBase.indexOf(baseDn);
  groupBase = indexOfBaseDn <= 0 ? "" : groupBase.substring(0,indexOfBaseDn - 1);

  StringBuilder filterBuilder = new StringBuilder();

  filterBuilder.append("(&(");
  filterBuilder.append(groupMembershipAttr);
  filterBuilder.append("=");
  filterBuilder.append(user.getNameInNamespace());//DN

  if ((groupSearchFilter == null) || groupSearchFilter.equals("") ) {
    //If groupSearchFilter is not specified, build it from other authorization
    // group properties
    filterBuilder.append(")(objectclass=");
    filterBuilder.append(groupObjectClass);
    filterBuilder.append(")(|");
    String[] adminGroupMappingRegexs = adminGroupMappingRules.split(",");
    for (String adminGroupMappingRegex : adminGroupMappingRegexs) {
      filterBuilder.append("(");
      filterBuilder.append(groupNamingAttribute);
      filterBuilder.append("=");
      filterBuilder.append(adminGroupMappingRegex);
      filterBuilder.append(")");
    }
    filterBuilder.append(")");
  } else {
    filterBuilder.append(")");
    filterBuilder.append(groupSearchFilter);
  }
  filterBuilder.append(")");

  AttributesMapper attributesMapper = new AttributesMapper() {
    public Object mapFromAttributes(Attributes attrs)
        throws NamingException {
      return attrs.get(groupNamingAttribute).get();
    }
  };

  LdapTemplate ldapTemplate = new LdapTemplate((getContextSource()));
  ldapTemplate.setIgnorePartialResultException(true);
  ldapTemplate.setIgnoreNameNotFoundException(true);

  List<String> ambariAdminGroups = ldapTemplate.search(
      groupBase,filterBuilder.toString(),attributesMapper);

  //user has admin role granted, if user is a member of at least 1 group,
  // which matches the rules in configuration
  if (ambariAdminGroups.size() > 0) {
    user.setAttributeValue(AMBARI_ADMIN_LDAP_ATTRIBUTE_KEY, true);
  }

  return user;
}
 
開發者ID:telefonicaid,項目名稱:fiware-cosmos-ambari,代碼行數:75,代碼來源:AmbariLdapBindAuthenticator.java


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