本文整理汇总了Java中javax.naming.ldap.LdapName.toString方法的典型用法代码示例。如果您正苦于以下问题:Java LdapName.toString方法的具体用法?Java LdapName.toString怎么用?Java LdapName.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.ldap.LdapName
的用法示例。
在下文中一共展示了LdapName.toString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: composeDn
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* Creates a valid LDAP distinguished name from the wide range of components. The method
* can be invoked in many ways, e.g.:
*
* composeDn("cn","foo","o","bar")
* composeDn("cn","foo",new Rdn("o","bar"))
* composeDn(new Rdn("cn","foo"),"ou","baz",new Rdn("o","bar"))
* composeDn(new Rdn("cn","foo"),"ou","baz","o","bar")
* composeDn(new Rdn("cn","foo"),new LdapName("ou=baz,o=bar"))
* composeDn("cn","foo",new LdapName("ou=baz,o=bar"))
*
* Note: the DN is not normalized. The case of the attribute names and white spaces are
* preserved.
*/
public static String composeDn(Object... components) throws InvalidNameException {
if (components == null) {
return null;
}
if (components.length == 0) {
return null;
}
if (components.length == 1 && components[0] == null) {
return null;
}
if (components.length == 1 && (components[0] instanceof String) && StringUtils.isBlank((String)(components[0]))) {
return null;
}
LinkedList<Rdn> rdns = new LinkedList<>();
String attrName = null;
for (Object component: components) {
if (attrName != null && !(component instanceof String || component instanceof PolyString || component instanceof PolyStringType)) {
throw new InvalidNameException("Invalid input to composeDn() function: expected string after '"+attrName+"' argument, but got "+component.getClass());
}
if (component instanceof Rdn) {
rdns.addFirst((Rdn)component);
} else if (component instanceof PolyString) {
component = ((PolyString)component).toString();
} else if (component instanceof PolyStringType) {
component = ((PolyStringType)component).toString();
}
if (component instanceof String) {
if (attrName == null) {
attrName = (String)component;
} else {
rdns.addFirst(new Rdn(attrName, (String)component));
attrName = null;
}
}
if (component instanceof LdapName) {
rdns.addAll(0,((LdapName)component).getRdns());
}
}
LdapName dn = new LdapName(rdns);
return dn.toString();
}
示例2: applyToDN
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
public String applyToDN(String dn) {
String mergedDNInput = dn;
try {
LdapName oldDN = new LdapName(Strings.safeSafeTrim(dn));
List<Rdn> oldRdns = oldDN.getRdns();
List<Rdn> newRdns = new ArrayList<>(oldRdns.size());
for (Rdn oldRdn : oldRdns) {
if (this.aliasInput.length == 2 && DN_ALIAS_KEY.equals(oldRdn.getType())) {
if (isRdnMergeable(this.aliasInput[0], oldRdn)) {
newRdns.add(new Rdn(oldRdn.getType(), safeRdnValue(this.aliasInput[1])));
continue;
}
}
if (this.storeName.length == 2 && DN_STORE_KEY.equals(oldRdn.getType())) {
if (this.storeName[0] == null) {
this.storeName[0] = String.valueOf(oldRdn.getValue());
}
if (isRdnMergeable(this.storeName[0], oldRdn)) {
newRdns.add(new Rdn(oldRdn.getType(), safeRdnValue(this.storeName[1])));
continue;
}
}
if (this.serial.length == 2 && DN_SERIAL_KEY.equals(oldRdn.getType())) {
if (this.serial[0] == null) {
this.serial[0] = String.valueOf(oldRdn.getValue());
}
if (isRdnMergeable(this.serial[0], oldRdn)) {
newRdns.add(new Rdn(oldRdn.getType(), safeRdnValue(this.serial[1])));
continue;
}
}
newRdns.add(oldRdn);
}
LdapName newDN = new LdapName(newRdns);
mergedDNInput = newDN.toString();
} catch (InvalidNameException e) {
Exceptions.ignore(e);
}
return mergedDNInput;
}
示例3: composeDn
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* Creates a valid LDAP distinguished name from the wide range of components. The method
* can be invoked in many ways, e.g.:
*
* composeDn("cn","foo","o","bar")
* composeDn("cn","foo",new Rdn("o","bar"))
* composeDn(new Rdn("cn","foo"),"ou","baz",new Rdn("o","bar"))
* composeDn(new Rdn("cn","foo"),"ou","baz","o","bar")
* composeDn(new Rdn("cn","foo"),new LdapName("ou=baz,o=bar"))
* composeDn("cn","foo",new LdapName("ou=baz,o=bar"))
*
* Note: the DN is not normalized. The case of the attribute names and white spaces are
* preserved.
*/
public static String composeDn(Object... components) throws InvalidNameException {
if (components == null) {
return null;
}
if (components.length == 0) {
return null;
}
if (components.length == 1 && components[0] == null) {
return null;
}
if (components.length == 1 && (components[0] instanceof String) && StringUtils.isBlank((String)(components[0]))) {
return null;
}
LinkedList<Rdn> rdns = new LinkedList<>();
String attrName = null;
for (Object component: components) {
if (attrName != null && !(component instanceof String || component instanceof PolyString || component instanceof PolyStringType)) {
throw new InvalidNameException("Invalid input to composeDn() function: expected string after '"+attrName+"' argument, but got "+component.getClass());
}
if (component instanceof Rdn) {
rdns.addFirst((Rdn)component);
} else if (component instanceof PolyString) {
component = ((PolyString)component).toString();
} else if (component instanceof PolyStringType) {
component = ((PolyStringType)component).toString();
}
if (component instanceof String) {
if (attrName == null) {
attrName = (String)component;
} else {
rdns.addFirst(new Rdn(attrName, (String)component));
attrName = null;
}
}
if (component instanceof LdapName) {
rdns.addAll(0,((LdapName)component).getRdns());
}
}
LdapName dn = new LdapName(rdns);
return dn.toString();
}
示例4: attributesToIdentity
import javax.naming.ldap.LdapName; //导入方法依赖的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);
}
}
}