本文整理匯總了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);
}
}
}