当前位置: 首页>>代码示例>>Java>>正文


Java SearchResultEntry.getDN方法代码示例

本文整理汇总了Java中com.unboundid.ldap.sdk.SearchResultEntry.getDN方法的典型用法代码示例。如果您正苦于以下问题:Java SearchResultEntry.getDN方法的具体用法?Java SearchResultEntry.getDN怎么用?Java SearchResultEntry.getDN使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.unboundid.ldap.sdk.SearchResultEntry的用法示例。


在下文中一共展示了SearchResultEntry.getDN方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rolesFromDN

import com.unboundid.ldap.sdk.SearchResultEntry; //导入方法依赖的package包/类
private Set<String> rolesFromDN(String userDN) throws LDAPException, GeneralSecurityException {
  SearchRequest searchRequest = new SearchRequest(config.getRoleBaseDN(),
      SearchScope.SUB, Filter.createEqualityFilter("uniqueMember", userDN));
  Set<String> roles = Sets.newLinkedHashSet();

  LDAPConnection connection = connectionFactory.getLDAPConnection();
  try {
    SearchResult sr = connection.search(searchRequest);

    for (SearchResultEntry sre : sr.getSearchEntries()) {
      X500Name x500Name = new X500Name(sre.getDN());
      RDN[] rdns = x500Name.getRDNs(BCStyle.CN);
      if (rdns.length == 0) {
        logger.error("Could not create X500 Name for role:" + sre.getDN());
      } else {
        String commonName = IETFUtils.valueToString(rdns[0].getFirst().getValue());
        roles.add(commonName);
      }
    }
  } finally {
    connection.close();
  }

  return roles;
}
 
开发者ID:square,项目名称:keywhiz,代码行数:26,代码来源:LdapAuthenticator.java

示例2: setAccountRoles

import com.unboundid.ldap.sdk.SearchResultEntry; //导入方法依赖的package包/类
private void setAccountRoles(LDAPConnection ldapConnection, SearchResultEntry accountSearchResult, Account account) {
    String accountDN = accountSearchResult.getDN();

    String groupMemberPattern = this.groupMemberPattern.replace("${dn}", escapeLDAPSearchFilter(accountDN));
    groupMemberPattern = groupMemberPattern.replace("${username}", escapeLDAPSearchFilter(account.getUsername()));

    // Fill in attributes into groupMemberPattern
    for (Attribute attribute : accountSearchResult.getAttributes()) {
        groupMemberPattern = groupMemberPattern.replace("${" + attribute.getName() + "}", escapeLDAPSearchFilter(attribute.getValue()));
    }

    SearchResult groupsSearchResult = doSearch(ldapConnection, groupBase, true, groupMemberPattern, Arrays.asList("cn"));
    if (groupsSearchResult != null && groupsSearchResult.getEntryCount() > 0) {
        for (int i = 0; i < groupsSearchResult.getEntryCount(); i++) {
            SearchResultEntry groupEntry = groupsSearchResult.getSearchEntries().get(i);
            String roleName = groupEntry.getAttribute("cn").getValue();

            account.getAuthorizations().addRole(roleName);
        }
    }
}
 
开发者ID:gitblit,项目名称:fathom,代码行数:22,代码来源:LdapRealm.java

示例3: getTeamsFromLdap

import com.unboundid.ldap.sdk.SearchResultEntry; //导入方法依赖的package包/类
private void getTeamsFromLdap(LDAPConnection ldapConnection, String simpleUsername, SearchResultEntry loggingInUser, UserModel user) {
	String loggingInUserDN = loggingInUser.getDN();
	
	user.teams.clear();		// Clear the users team memberships - we're going to get them from LDAP
	String groupBase = settings.getString(Keys.realm.ldap.groupBase, "");
	String groupMemberPattern = settings.getString(Keys.realm.ldap.groupMemberPattern, "(&(objectClass=group)(member=${dn}))");
	
	groupMemberPattern = StringUtils.replace(groupMemberPattern, "${dn}", escapeLDAPSearchFilter(loggingInUserDN));
	groupMemberPattern = StringUtils.replace(groupMemberPattern, "${username}", escapeLDAPSearchFilter(simpleUsername));
	
	// Fill in attributes into groupMemberPattern
	for (Attribute userAttribute : loggingInUser.getAttributes())
		groupMemberPattern = StringUtils.replace(groupMemberPattern, "${" + userAttribute.getName() + "}", escapeLDAPSearchFilter(userAttribute.getValue()));
	
	SearchResult teamMembershipResult = doSearch(ldapConnection, groupBase, groupMemberPattern);
	if (teamMembershipResult != null && teamMembershipResult.getEntryCount() > 0) {
		for (int i = 0; i < teamMembershipResult.getEntryCount(); i++) {
			SearchResultEntry teamEntry = teamMembershipResult.getSearchEntries().get(i);
			String teamName = teamEntry.getAttribute("cn").getValue();
			
			TeamModel teamModel = getTeamModel(teamName);
			if (teamModel == null)
				teamModel = createTeamFromLdap(teamEntry);
				
			user.teams.add(teamModel);
			teamModel.addUser(user.getName());
		}
	}
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:30,代码来源:LdapUserService.java

示例4: authenticate

import com.unboundid.ldap.sdk.SearchResultEntry; //导入方法依赖的package包/类
@Override
public Account authenticate(final String username, final String password) {
    LDAPConnection ldapConnection = getLdapConnection();
    if (ldapConnection != null) {
        try {
            boolean alreadyAuthenticated = false;

            if (!Strings.isNullOrEmpty(ldapBindPattern)) {
                try {
                    String bindUser = ldapBindPattern.replace("${username}", escapeLDAPSearchFilter(username));
                    ldapConnection.bind(bindUser, password);

                    alreadyAuthenticated = true;
                } catch (LDAPException e) {
                    return null;
                }
            }

            // Find the logging in user's DN
            String searchPattern = accountPattern.replace("${username}", escapeLDAPSearchFilter(username));

            SearchResult result = doSearch(ldapConnection, accountBase, searchPattern);
            if (result != null && result.getEntryCount() == 1) {
                SearchResultEntry accountSearchResult = result.getSearchEntries().get(0);
                String accountDN = accountSearchResult.getDN();

                if (alreadyAuthenticated || isAuthenticated(ldapConnection, accountDN, password)) {
                    log.debug("Authentication succeeded for '{}' against '{}'", username, getRealmName());

                    Account account = null;
                    synchronized (this) {
                        account = new Account(username, new StandardCredentials(username, password));
                        setAccountRoles(ldapConnection, accountSearchResult, account);
                        setAccountAttributes(accountSearchResult, account);

                        cacheAccount(account);
                    }

                    return account;
                } else {
                    log.debug("Authentication failed for '{}' against '{}'", username, getRealmName());
                }
            } else if (result == null || result.getSearchEntries().size() == 0) {
                log.debug("No account found for '{}' in '{}'", username, getRealmName());
            }
        } finally {
            ldapConnection.close();
        }
    }
    return null;
}
 
开发者ID:gitblit,项目名称:fathom,代码行数:52,代码来源:LdapRealm.java


注:本文中的com.unboundid.ldap.sdk.SearchResultEntry.getDN方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。