本文整理汇总了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;
}
示例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());
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}