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


Java LdapContext.getAttributes方法代碼示例

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


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

示例1: getGroup

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public Group getGroup(String groupName) throws GroupNotFoundException {
    LdapContext ctx = null;
    try {
        String groupDN = manager.findGroupDN(groupName);
        // Load record.
        ctx = manager.getContext(manager.getGroupsBaseDN(groupName));
        Attributes attrs = ctx.getAttributes(groupDN, standardAttributes);

        return processGroup(ctx, attrs);
    }
    catch (Exception e) {
        Log.error(e.getMessage(), e);
        throw new GroupNotFoundException("Group with name " + groupName + " not found.", e);
    }
    finally {
        try {
            if (ctx != null) {
                ctx.setRequestControls(null);
                ctx.close();
            }
        }
        catch (Exception ignored) {
            // Ignore.
        }
    }
}
 
開發者ID:coodeer,項目名稱:g3server,代碼行數:27,代碼來源:LdapGroupProvider.java

示例2: defineTriggerExecutionSpecificPoint

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
/**
 * Defines the Administration point and administrative role for the TriggerExecution specific point
 * @param apCtx The administrative point context
 * @throws NamingException If the operation failed
 */
public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException
{
    Attributes ap = apCtx.getAttributes( "", new String[] { SchemaConstants.ADMINISTRATIVE_ROLE_AT } );
    Attribute administrativeRole = ap.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT );
    
    if ( administrativeRole == null
        || !AttributeUtils.containsValueCaseIgnore( administrativeRole, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA ) )
    {
        Attributes changes = new BasicAttributes( SchemaConstants.ADMINISTRATIVE_ROLE_AT,
            SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA, true );
        apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes );
    }
}
 
開發者ID:apache,項目名稱:directory-ldap-api,代碼行數:19,代碼來源:TriggerUtils.java

示例3: getObject

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
protected Identity getObject(String distinguishedName, String scope) {
    LdapContext context = null;
    try {
        LdapName object = new LdapName(distinguishedName);
        context = getServiceContext();
        Attributes search;
        search = context.getAttributes(object);
        if (!isType(search, scope) && !hasPermission(search)){
            return null;
        }
        return attributesToIdentity(object);
    }
    catch (NamingException e) {
        getLogger().error("Failed to get object: {} : {}", distinguishedName, e.getExplanation());
        if(!LDAPUtils.isRecoverable(e)) {
            invalidateServiceContext(context);
            context = null;
        }
        return null;
    }
    finally {
        if (context != null) {
            returnServiceContext(context);
        }
    }
}
 
開發者ID:rancher,項目名稱:cattle,代碼行數:27,代碼來源:LDAPIdentityProvider.java

示例4: loadRoleByRoleNameAttributeID

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
protected void loadRoleByRoleNameAttributeID(LdapContext searchContext, String roleDN)
{
   String[] returnAttribute = {roleNameAttributeID};
   if (trace) {
      log.trace("Using roleDN: " + roleDN);
   }
   try
   {
      Attributes result2 = searchContext.getAttributes(roleDN, returnAttribute);
      Attribute roles2 = result2.get(roleNameAttributeID);
      if (roles2 != null)
      {
         for (int m = 0; m < roles2.size(); m++)
         {
            String roleName = (String) roles2.get(m);
            addRole(roleName);
         }
      }
   }
   catch (NamingException e)
   {
      if (trace) {
         log.trace("Failed to query roleNameAttrName", e);
      }
   }
}
 
開發者ID:wildfly-security,項目名稱:jboss-negotiation,代碼行數:27,代碼來源:AdvancedLdapLoginModule.java

示例5: getByDn

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public Attributes getByDn(final String dn) throws NamingException {
    LdapContext ctx = new InitialLdapContext(env, null);
    Attributes result = ctx.getAttributes(dn);
    ctx.close();

    return result;
}
 
開發者ID:klenkes74,項目名稱:openshift-ldapsync,代碼行數:8,代碼來源:LdapServer.java

示例6: getGroup

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
@Override
public Group getGroup(String groupName) throws GroupNotFoundException {
    LdapContext ctx = null;
    try {
        String groupDN = manager.findGroupDN(groupName);
        // Load record.
        ctx = manager.getContext(manager.getGroupsBaseDN(groupName));
        Attributes attrs = ctx.getAttributes(groupDN, standardAttributes);

        return processGroup(ctx, attrs);
    }
    catch (Exception e) {
        Log.error(e.getMessage(), e);
        throw new GroupNotFoundException("Group with name " + groupName + " not found.", e);
    }
    finally {
        try {
            if (ctx != null) {
                ctx.setRequestControls(null);
                ctx.close();
            }
        }
        catch (Exception ignored) {
            // Ignore.
        }
    }
}
 
開發者ID:igniterealtime,項目名稱:Openfire,代碼行數:28,代碼來源:LdapGroupProvider.java

示例7: getGroupMembershipLists

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
/**
 * Returns the distinguished-names (DNs) of all the members of the groups
 * specified in the restriction list. The information is organised as a list
 * of <code>&quot;&lt;groupDN&gt;=&lt;
 * [userDN1,userDN2,...,userDNn]&gt;&quot;</code>. Put differently, each
 * <code>groupDN</code> is associated to a list of <code>userDNs</code>.
 * 
 * @param connection
 *            The connection to the LDAP directory server.
 * @return Returns a map of groupDNs to userDN lists.
 * @throws NamingException
 *             Propagated from underlying LDAP communication layer.
 */
protected Map<String, Collection<String>> getGroupMembershipLists(LdapContext ldapContext) throws NamingException {
    Map<String, Collection<String>> result = new HashMap<String, Collection<String>>();

    Iterator<String> groupDNsIterator = groupDNs.iterator();

    Attributes groupAttributes;
    while (groupDNsIterator.hasNext()) {
        String groupDN = (String) groupDNsIterator.next();
        groupAttributes = ldapContext.getAttributes(groupDN);
        result.put(groupDN, extractMembers(groupAttributes));
    }

    return result;
}
 
開發者ID:twachan,項目名稱:James,代碼行數:28,代碼來源:ReadOnlyLDAPGroupRestriction.java

示例8: findRolsAmbCodi

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public List<String> findRolsAmbCodi(String codi) throws PersonesPluginException {
	List<String> roles = new ArrayList<String>();
	
	String userFilter = GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.filter.user");
	String filter = new String(userFilter).replace("###", codi);
	
	String roleAtt = GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.attribute.role");
	String roleName = GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.attribute.role.name");
	
	if (roleAtt != null && roleName != null) {
		LdapContext ctx = null;
		
		try {
			ctx = getContext();
			SearchControls searchCtls = new SearchControls();
			searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
			NamingEnumeration<SearchResult> answer = ctx.search(
					GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.searchbase"),
					filter,
					searchCtls);
			
			if (answer.hasMoreElements()) {
				SearchResult sr = (SearchResult)answer.next();
				Attribute memberOf = sr.getAttributes().get(roleAtt);
				if (memberOf != null) {
					for (int i = 0; i < memberOf.size(); i++) {
						Attributes atts = ctx.getAttributes(memberOf.get(i).toString(), new String[] {roleName});
						Attribute att = atts.get(roleName);
						if (att.get() != null)
							roles.add(att.get().toString());
					}
				}
			}
			ctx.close();
		} catch (Exception ex) {
			throw new PersonesPluginException("No s'ha pogut trobar cap persona", ex);
		}
	}
	
	return roles;
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:42,代碼來源:PersonesPluginLdap.java

示例9: attributesToIdentity

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
protected Identity attributesToIdentity(LdapName dn){
    LdapContext context = getServiceContext();
    try {
        Attributes search = context.getAttributes(dn);
        log.trace("Attributes for dn: " + dn + " to translate: " + search);
        String externalIdType;
        String accountName;
        String externalId = dn.toString();
        String login;
        boolean user = false;
        if (isType(search, getConstantsConfig().getUserObjectClass())){
            externalIdType = getConstantsConfig().getUserScope();
            if (search.get(getConstantsConfig().getUserNameField()) != null) {
                accountName = (String) search.get(getConstantsConfig().getUserNameField()).get();
            } else {
                accountName = externalId;
            }
            login = (String) search.get(getConstantsConfig().getUserLoginField()).get();
            user = true;
        } else if (isType(search, getConstantsConfig().getGroupObjectClass())) {
            externalIdType = getConstantsConfig().getGroupScope();
            if (search.get(getConstantsConfig().getGroupNameField()) != null) {
                accountName = (String) search.get(getConstantsConfig().getGroupNameField()).get();
            } else {
                accountName = externalId;
            }
            if (search.get(getConstantsConfig().getUserLoginField()) != null) {
                login = (String) search.get(getConstantsConfig().getUserLoginField()).get();
            } else {
                login = accountName;
            }
        } else {
            return null;
        }
        return new Identity(externalIdType, externalId, accountName, null, null, login, user);
    } catch (NamingException e) {
        getLogger().error("Failed to get attributes: {} : {}", dn, e.getExplanation());
        if(!LDAPUtils.isRecoverable(e)) {
            invalidateServiceContext(context);
            context = null;
        }
        return null;
    } finally {
        if (context != null) {
            returnServiceContext(context);
        }
    }
}
 
開發者ID:rancher,項目名稱:cattle,代碼行數:49,代碼來源:LDAPIdentityProvider.java

示例10: obtainRole

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
protected void obtainRole(LdapContext searchContext, String dn, SearchResult sr) throws NamingException, LoginException
{
   if (trace) {
      log.trace("rolesSearch resultDN = " + dn);
   }

   String[] attrNames =
   {roleAttributeID};

   Attributes result = null;
   if (sr == null || ( sr.isRelative() && sr.getAttributes().size() == 0 ) ) {
       result = searchContext.getAttributes(dn, attrNames);
   }
   else if (sr != null && sr.isRelative() && sr.getAttributes().size() != 0 ) {
       result = sr.getAttributes();
   }
   else
   {
      result = getAttributesFromReferralEntity(sr);
   }
   if (result != null && result.size() > 0)
   {
      Attribute roles = result.get(roleAttributeID);
      for (int n = 0; n < roles.size(); n++)
      {
         String roleName = (String) roles.get(n);
         if (roleAttributeIsDN)
         {
            // Query the roleDN location for the value of roleNameAttributeID
            String roleDN = "\"" + roleName + "\"";

            loadRoleByRoleNameAttributeID(searchContext, roleDN);
            recurseRolesSearch(searchContext, roleName);
         }
         else
         {
            // The role attribute value is the role name
            addRole(roleName);
         }
      }
   }
}
 
開發者ID:wildfly-security,項目名稱:jboss-negotiation,代碼行數:43,代碼來源:AdvancedLdapLoginModule.java


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