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


Java LdapName.size方法代碼示例

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


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

示例1: formatDestination

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
/**
 * Parses a DN into the equivalent {@link ActiveMQDestination}. The default implementation expects a format of
 * cn=<PERMISSION_NAME>,ou=<DESTINATION_PATTERN>,.... or ou=<DESTINATION_PATTERN>,.... for permission and
 * destination entries, respectively. For example {@code cn=admin,ou=$,ou=...} or {@code ou=$,ou=...}.
 *
 * @param dn
 *            the DN to parse
 * @param destinationType
 *            the type of the destination that we are parsing
 *
 * @return the destination that the DN represents
 *
 * @throws IllegalArgumentException
 *             if {@code destinationType} is {@link DestinationType#TEMP} or if the format of {@code dn} is
 *             incorrect for for a topic or queue
 *
 * @see #formatDestination(Rdn, DestinationType)
 */
protected ActiveMQDestination formatDestination(LdapName dn, DestinationType destinationType) {
    ActiveMQDestination destination = null;

    switch (destinationType) {
        case QUEUE:
        case TOPIC:
            // There exists a need to deal with both names representing a permission or simply a
            // destination. As such, we need to determine the proper RDN to work with based
            // on the destination type and the DN size.
            if (dn.size() == (getPrefixLengthForDestinationType(destinationType) + 2)) {
                destination = formatDestination(dn.getRdn(dn.size() - 2), destinationType);
            } else if (dn.size() == (getPrefixLengthForDestinationType(destinationType) + 1)) {
                destination = formatDestination(dn.getRdn(dn.size() - 1), destinationType);
            } else {
                throw new IllegalArgumentException("Malformed DN for representing a permission or destination entry.");
            }
            break;
        default:
            throw new IllegalArgumentException("Cannot format destination for destination type " + destinationType);
    }

    return destination;
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:42,代碼來源:SimpleCachedLDAPAuthorizationMap.java

示例2: convertToRelativeName

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
public static LdapName convertToRelativeName(LdapName dn, LdapName base)
        throws NamingException {
    if (base.size() == 0) {
        return dn;
    }

    if (dn.size() < base.size()) {
        // TODO add error message
        throw new NamingException("");
    }

    Name prefix = dn.getPrefix(base.size());
    if (!prefix.equals(base)) {
        // TODO add error message
        throw new NamingException("");
    }

    return (LdapName) dn.getSuffix(base.size());

}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:21,代碼來源:LdapUtils.java

示例3: convertObjectAndAddGrantedAuthorityToList

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
private void convertObjectAndAddGrantedAuthorityToList(final Object o, final List<GrantedAuthority> grantedAuthorities) {
    if (o instanceof String) {
        final String memberOfString = (String) o;
        try {
            LdapName name = new LdapName(memberOfString);
            if (name.size() > 0) {
                String value = name.getRdn(name.size() - 1).getValue().toString();
                if (this.convertToUpperCase) {
                    value = value.toUpperCase();
                }
                if (this.convertSpacesToUnderscores) {
                    value = value.replace(' ', '_');
                }
                grantedAuthorities.add(new SimpleGrantedAuthority(rolePrefix + value));
            }
        } catch (InvalidNameException e) {
            logger.warn("Couldn't convert \"" + memberOfString + "\" to an LdapName", e);
        }
    }
}
 
開發者ID:acu-dev,項目名稱:spring-security-cas-memberOf-roles,代碼行數:21,代碼來源:GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService.java

示例4: parseRole

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
private LdapEntry parseRole(String dn, String groupNameAttribute, URI groupReferralAddress) {

            try {
                LdapName ldapName = new LdapName(Rdn.unescapeValue(dn).toString());
                for (int i = ldapName.size() - 1; i >= 0; i--) {
                    String rdnString = ldapName.get(i);
                    Rdn rdn = new Rdn(rdnString);
                    Attribute attr = rdn.toAttributes().get(groupNameAttribute);
                    if (attr != null) {
                        Object value = attr.get();
                        if (value != null) {
                            return new LdapEntry( (value instanceof byte[]) ? new String((byte[]) value, StandardCharsets.UTF_8) : value.toString(), dn, groupReferralAddress);
                        }
                    }
                }
            } catch (NamingException e) {
                SECURITY_LOGGER.tracef("Unable to parse role from DN (%s): %s", dn, e.getMessage());
            }
            return null;
        }
 
開發者ID:wildfly,項目名稱:wildfly-core,代碼行數:21,代碼來源:LdapGroupSearcherFactory.java

示例5: getDnAttribute

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
private List<String> getDnAttribute(LdapName rfc2253dn, String attribute) {        
    final List<String> attrValues = new ArrayList<>(rfc2253dn.size());
    final List<Rdn> reverseRdn = new ArrayList<>(rfc2253dn.getRdns());
    Collections.reverse(reverseRdn);

    for (Rdn rdn : reverseRdn) {
        if (rdn.getType().equalsIgnoreCase(attribute)) {
            attrValues.add(rdn.getValue().toString());
        }
    }
    
    return Collections.unmodifiableList(attrValues);
}
 
開發者ID:floragunncom,項目名稱:search-guard,代碼行數:14,代碼來源:HTTPClientCertAuthenticator.java

示例6: setQueueSearchBase

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
public void setQueueSearchBase(String queueSearchBase) {
    try {
        LdapName baseName = new LdapName(queueSearchBase);
        queuePrefixLength = baseName.size();
        this.queueSearchBase = queueSearchBase;
    } catch (InvalidNameException e) {
        throw new IllegalArgumentException("Invalid base DN value " + queueSearchBase, e);
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:10,代碼來源:SimpleCachedLDAPAuthorizationMap.java

示例7: setTopicSearchBase

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
public void setTopicSearchBase(String topicSearchBase) {
    try {
        LdapName baseName = new LdapName(topicSearchBase);
        topicPrefixLength = baseName.size();
        this.topicSearchBase = topicSearchBase;
    } catch (InvalidNameException e) {
        throw new IllegalArgumentException("Invalid base DN value " + topicSearchBase, e);
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:10,代碼來源:SimpleCachedLDAPAuthorizationMap.java

示例8: setTempSearchBase

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
public void setTempSearchBase(String tempSearchBase) {
    try {
        LdapName baseName = new LdapName(tempSearchBase);
        tempPrefixLength = baseName.size();
        this.tempSearchBase = tempSearchBase;
    } catch (InvalidNameException e) {
        throw new IllegalArgumentException("Invalid base DN value " + tempSearchBase, e);
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:10,代碼來源:SimpleCachedLDAPAuthorizationMap.java

示例9: getDomainComponents

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
/**
 * Extracts the DC attributes in a DN string as an {@code LdapName}.
 *
 * @param userDn the Documentum user LDAP DN
 * @return LDAP name for the given user DN
 * @throws InvalidNameException if a syntax violation is detected.
 */
public static LdapName getDomainComponents(String userDn)
    throws InvalidNameException{
  LdapName userName = new LdapName(userDn);
  ArrayList<Rdn> userDnDomain = new ArrayList<Rdn>(userName.size());
  for (Rdn rdn : userName.getRdns()) {
    if (rdn.getType().equalsIgnoreCase("dc")) {
      userDnDomain.add(rdn);
    }
  }
  return new LdapName(userDnDomain);
}
 
開發者ID:googlegsa,項目名稱:documentum,代碼行數:19,代碼來源:Principals.java

示例10: isUserMemberOfDynamicGroup

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
boolean isUserMemberOfDynamicGroup(LdapName userLdapDn, String memberUrl,
      final LdapContextFactory ldapContextFactory) throws NamingException {

  // ldap://host:port/dn?attributes?scope?filter?extensions

  if (memberUrl == null) {
    return false;
  }
  String[] tokens = memberUrl.split("\\?");
  if (tokens.length < 4) {
    return false;
  }

  String searchBaseString = tokens[0].substring(tokens[0].lastIndexOf("/") + 1);
  String searchScope = tokens[2];
  String searchFilter = tokens[3];

  LdapName searchBaseDn = new LdapName(searchBaseString);

  // do scope test
  if (searchScope.equalsIgnoreCase("base")) {
    log.debug("DynamicGroup SearchScope base");
    return false;
  }
  if (!userLdapDn.toString().endsWith(searchBaseDn.toString())) {
    return false;
  }
  if (searchScope.equalsIgnoreCase("one") && (userLdapDn.size() != searchBaseDn.size() - 1)) {
    log.debug("DynamicGroup SearchScope one");
    return false;
  }
  // search for the filter, substituting base with userDn
  // search for base_dn=userDn, scope=base, filter=filter
  LdapContext systemLdapCtx = null;
  systemLdapCtx = ldapContextFactory.getSystemLdapContext();
  boolean member = false;
  NamingEnumeration<SearchResult> searchResultEnum = null;
  try {
    searchResultEnum = systemLdapCtx.search(userLdapDn, searchFilter,
          searchScope.equalsIgnoreCase("sub") ? SUBTREE_SCOPE : ONELEVEL_SCOPE);
    if (searchResultEnum.hasMore()) {
      return true;
    }
  } finally {
    try {
      if (searchResultEnum != null) {
        searchResultEnum.close();
      }
    } finally {
      LdapUtils.closeContext(systemLdapCtx);
    }
  }
  return member;
}
 
開發者ID:apache,項目名稱:zeppelin,代碼行數:55,代碼來源:LdapRealm.java

示例11: getEntry

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
/**
 * Retrieves or creates the {@link AuthorizationEntry} that corresponds to the DN in {@code dn}. This implementation
 * should not be invoked concurrently.
 *
 * @param map
 *            the DefaultAuthorizationMap to operate on.
 * @param dn
 *            the DN representing the policy entry in the directory
 * @param destinationType
 *            the type of the destination to get/create the entry for
 *
 * @return the corresponding authorization entry for the DN
 *
 * @throws IllegalArgumentException
 *             if destination type is not one of {@link DestinationType#QUEUE}, {@link DestinationType#TOPIC},
 *             {@link DestinationType#TEMP} or if the policy entry DN is malformed
 */
protected AuthorizationEntry getEntry(DefaultAuthorizationMap map, LdapName dn, DestinationType destinationType) {
    AuthorizationEntry entry = null;
    switch (destinationType) {
        case TEMP:
            // handle temp entry
            if (dn.size() != getPrefixLengthForDestinationType(destinationType) + 1) {
                // handle unknown entry
                throw new IllegalArgumentException("Malformed policy structure for a temporary destination "
                    + "policy entry.  The permission group entries should be immediately below the " + "temporary policy base DN.");
            }
            entry = map.getTempDestinationAuthorizationEntry();
            if (entry == null) {
                entry = new TempDestinationAuthorizationEntry();
                map.setTempDestinationAuthorizationEntry((TempDestinationAuthorizationEntry) entry);
            }

            break;

        case QUEUE:
        case TOPIC:
            // handle regular destinations
            if (dn.size() != getPrefixLengthForDestinationType(destinationType) + 2) {
                throw new IllegalArgumentException("Malformed policy structure for a queue or topic destination "
                    + "policy entry.  The destination pattern and permission group entries should be " + "nested below the queue or topic policy base DN.");
            }

            ActiveMQDestination dest = formatDestination(dn, destinationType);

            if (dest != null) {
                entry = entries.get(dest);
                if (entry == null) {
                    entry = new AuthorizationEntry();
                    entry.setDestination(dest);
                    entries.put(dest, entry);
                }
            }

            break;
        default:
            // handle unknown entry
            throw new IllegalArgumentException("Unknown destination type " + destinationType);
    }

    return entry;
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:63,代碼來源:SimpleCachedLDAPAuthorizationMap.java

示例12: testIntegrationConstructorAndMethods002

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
/**
 * <p>Method to test all the add methods in addition to the test of the remaining methods.</p>
 *
 */
public void testIntegrationConstructorAndMethods002(){
	
	try {
		
		//Testing Constructor
		LdapName temp=new LdapName("t=test");
		LdapName temp2=new LdapName(list);
		list.add(aux);
		LdapName temp3=new LdapName(list);
		assertNotNull(temp);
		assertNotNull(temp2);
		assertNotNull(temp3);
		
		//Testing Add Methods
		temp.add(0,aux);
		temp.add(0,"f=flag");
		temp.add(aux);
		temp.add("f=flag");
		temp.addAll(0,list);
		temp.addAll(0,temp2);
		temp.addAll(list);
		temp.addAll(temp2);

		
		//Testing methods 
		assertTrue(temp.hashCode()!=0);
		assertFalse(temp.isEmpty());
		assertNotNull(temp.remove(0));
		assertTrue(temp.size()!=0);
		while(temp.size()>0){
			assertNotNull(temp.remove(temp.size()-1));
		}
		assertTrue(temp.isEmpty());
		
		//Testing String
		String x="t=test,T=TEST";
		LdapName temp4=new LdapName(x);
		assertEquals(x.getBytes().length,temp4.toString().getBytes().length);
		
	} catch (InvalidNameException e) {
		fail("Failed with:"+e);
	}
		
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:49,代碼來源:TestLdapNameIntegration.java

示例13: testCompleteIntegration

import javax.naming.ldap.LdapName; //導入方法依賴的package包/類
/**
 * <p>Test method to test the complete integration of the class.</p>
 *
 */
public void testCompleteIntegration(){
	try {
		
		//Testing Constructor
		LdapName temp=new LdapName("t=test");
		LdapName temp2=new LdapName(list);
		list.add(aux);
		LdapName temp3=new LdapName(list);
		assertNotNull(temp);
		assertNotNull(temp2);
		assertNotNull(temp3);
		
		//Testing Add Methods
		temp.add(0,aux);
		temp.add(0,"f=flag");
		temp.add(aux);
		temp.add("f=flag");
		temp.addAll(0,list);
		temp.addAll(0,temp2);
		temp.addAll(list);
		temp.addAll(temp2);

		//Testing String
		String x="t=test,T=TEST";
		LdapName temp4=new LdapName(x);
		assertEquals(x.getBytes().length,temp4.toString().getBytes().length);
		
		//Testing get methods 
		LdapName en=(LdapName) temp.clone();
		assertEquals("t=test",temp.get(0));
		assertNotNull(temp.getAll());
		Enumeration<String> enume=temp.getAll();
		Enumeration<String> enume2=en.getAll();
		while(enume.hasMoreElements()&&enume2.hasMoreElements()){
			if(enume.nextElement().compareTo(enume2.nextElement())!=0)fail("Fail.");
			
		}
		if(!temp.getClass().equals(temp2.getClass()))fail("Fail.");
		assertTrue(temp.startsWith(temp.getPrefix(0)));
		assertTrue(temp.endsWith(temp.getSuffix(0)));
		assertTrue(temp.endsWith(temp.getRdns()));
		assertTrue(temp.getRdn(0).equals(aux));
		
		//Testing Clone, Equlas and CompareTo 
		if(!temp.clone().getClass().equals(temp.getClass()))fail("Fail.");
		assertEquals(0,temp.compareTo(temp));
		assertTrue(temp.compareTo(temp2)>0);
		assertTrue(temp.compareTo(temp3)>0);
		assertFalse(temp.equals(null));
		assertTrue(temp.equals(temp));
		assertFalse(temp.equals(temp2));
		
		//Testing SartWith and EndWith methods
		assertTrue(temp.endsWith(list));
		assertTrue(temp.endsWith(temp2));
		assertTrue(temp.startsWith(list));
		assertTrue(temp.startsWith(temp2));
		
		//Testing methods 
		assertTrue(temp.hashCode()!=0);
		assertFalse(temp.isEmpty());
		assertNotNull(temp.remove(0));
		assertTrue(temp.size()!=0);
		while(temp.size()>0){
			assertNotNull(temp.remove(temp.size()-1));
		}
		assertTrue(temp.isEmpty());
	} catch (InvalidNameException e) {
		fail("Failed with:"+e);
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:76,代碼來源:TestLdapNameIntegration.java


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