本文整理汇总了Java中javax.naming.ldap.LdapName.getRdn方法的典型用法代码示例。如果您正苦于以下问题:Java LdapName.getRdn方法的具体用法?Java LdapName.getRdn怎么用?Java LdapName.getRdn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.ldap.LdapName
的用法示例。
在下文中一共展示了LdapName.getRdn方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getACLs
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
protected Set<GroupPrincipal> getACLs(String destinationBase, SearchControls constraints, String roleBase, String roleAttribute) {
try {
Set<GroupPrincipal> roles = new HashSet<GroupPrincipal>();
Set<String> acls = new HashSet<String>();
NamingEnumeration<?> results = context.search(destinationBase, roleBase, constraints);
while (results.hasMore()) {
SearchResult result = (SearchResult)results.next();
Attributes attrs = result.getAttributes();
if (attrs == null) {
continue;
}
acls = addAttributeValues(roleAttribute, attrs, acls);
}
for (Iterator<String> iter = acls.iterator(); iter.hasNext();) {
String roleName = iter.next();
LdapName ldapname = new LdapName(roleName);
Rdn rdn = ldapname.getRdn(ldapname.size() - 1);
LOG.debug("Found role: [" + rdn.getValue().toString() + "]");
roles.add(new GroupPrincipal(rdn.getValue().toString()));
}
return roles;
} catch (NamingException e) {
LOG.error(e.toString());
return new HashSet<GroupPrincipal>();
}
}
示例2: rename
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
public void rename(Name nOld, Name nNew) throws NamingException {
checkName(nOld);
checkName(nNew);
if (!isInSameNamespace(nOld, nNew)) {
throw new InvalidNameException(Messages.getString("ldap.2A")); //$NON-NLS-1$
}
if (hasMultiNamingSpace(nOld) && hasMultiNamingSpace(nNew)) {
Context context = findNnsContext(nOld);
context.rename(nOld.getSuffix(1), nNew.getSuffix(1));
return;
}
// get absolute dn name
String oldTargetDN = getTargetDN(nOld, contextDn);
String newTargetDN = getTargetDN(nNew, contextDn);
LdapName name = new LdapName(newTargetDN);
Rdn rdn = name.getRdn(name.size() - 1);
String value = (String) env.get(LDAP_DELETE_RDN);
// true is default value
boolean isDeleteRdn = true;
if (value != null) {
isDeleteRdn = Boolean.getBoolean(value);
}
ModifyDNOp op = new ModifyDNOp(oldTargetDN, rdn.toString(),
isDeleteRdn, name.getPrefix(name.size() - 1).toString());
try {
doBasicOperation(op);
} catch (ReferralException e) {
if (isFollowReferral(e)) {
DirContext referralContext = getReferralContext(e);
referralContext.rename(nOld, nNew);
return;
}
throw e;
}
}
示例3: testGetRdn002
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* <p>
* Test method for 'javax.naming.ldap.LdapName.getRdn(int)'
* </p>
* <p>
* Here we are testing if this method correctly returns the RDN contained in
* the LdapName that is at the specified index.
* </p>
* <p>
* The expected result is an exception like IndexOutOfBounds.
* </p>
*/
public void testGetRdn002() throws Exception {
try {
LinkedList<Rdn> test = new LinkedList<Rdn>();
test.add(new Rdn("t=test"));
LdapName ln = new LdapName(test);
ln.getRdn(-1);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException e) {}
}
示例4: testGetRdn003
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* <p>
* Test method for 'javax.naming.ldap.LdapName.getRdn(int)'
* </p>
* <p>
* Here we are testing if this method correctly returns the RDN contained in
* the LdapName that is at the specified index.
* </p>
* <p>
* The expected result is an exception like IndexOutOfBounds.
* </p>
*/
public void testGetRdn003() throws Exception {
try {
LinkedList<Rdn> test = new LinkedList<Rdn>();
test.add(new Rdn("t=test"));
LdapName ln = new LdapName(test);
ln.getRdn(1);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException e) {}
}
示例5: testGetRdn004
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* <p>
* Test method for 'javax.naming.ldap.LdapName.getRdn(int)'
* </p>
* <p>
* Here we are testing if this method correctly returns the RDN contained in
* the LdapName that is at the specified index.
* </p>
* <p>
* The expected result is an IndexOutOfBoundsException.
* </p>
*/
public void testGetRdn004() throws Exception {
try {
LdapName ln = new LdapName("");
ln.getRdn(0);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException e) {}
}