Java Code Examples for javax.naming.Name#toString()
The following examples show how to use
javax.naming.Name#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalContext.java From unitime with Apache License 2.0 | 5 votes |
protected Name getMyComponents(Name name) throws NamingException { if (name instanceof CompositeName) { if (name.size() > 1) throw new InvalidNameException(name.toString() + " has more components than namespace can handle"); return parse(name.get(0)); } else { return name; } }
Example 2
Source File: ContinuationDirContext.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
protected DirContextStringPair getTargetContext(String name) throws NamingException { if (cpe.getResolvedObj() == null) throw (NamingException)cpe.fillInStackTrace(); Context ctx = NamingManager.getContext(cpe.getResolvedObj(), cpe.getAltName(), cpe.getAltNameCtx(), env); if (ctx instanceof DirContext) return new DirContextStringPair((DirContext)ctx, name); if (ctx instanceof Resolver) { Resolver res = (Resolver)ctx; ResolveResult rr = res.resolveToClass(name, DirContext.class); // Reached a DirContext; return result. DirContext dctx = (DirContext)rr.getResolvedObj(); Name tmp = rr.getRemainingName(); String remains = (tmp != null) ? tmp.toString() : ""; return (new DirContextStringPair(dctx, remains)); } // Resolve all the way using lookup(). This may allow the operation // to succeed if it doesn't require the penultimate context. Object ultimate = ctx.lookup(name); if (ultimate instanceof DirContext) { return (new DirContextStringPair((DirContext)ultimate, "")); } throw (NamingException)cpe.fillInStackTrace(); }
Example 3
Source File: ContinuationDirContext.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
protected DirContextStringPair getTargetContext(String name) throws NamingException { if (cpe.getResolvedObj() == null) throw (NamingException)cpe.fillInStackTrace(); Context ctx = NamingManager.getContext(cpe.getResolvedObj(), cpe.getAltName(), cpe.getAltNameCtx(), env); if (ctx instanceof DirContext) return new DirContextStringPair((DirContext)ctx, name); if (ctx instanceof Resolver) { Resolver res = (Resolver)ctx; ResolveResult rr = res.resolveToClass(name, DirContext.class); // Reached a DirContext; return result. DirContext dctx = (DirContext)rr.getResolvedObj(); Name tmp = rr.getRemainingName(); String remains = (tmp != null) ? tmp.toString() : ""; return (new DirContextStringPair(dctx, remains)); } // Resolve all the way using lookup(). This may allow the operation // to succeed if it doesn't require the penultimate context. Object ultimate = ctx.lookup(name); if (ultimate instanceof DirContext) { return (new DirContextStringPair((DirContext)ultimate, "")); } throw (NamingException)cpe.fillInStackTrace(); }
Example 4
Source File: LdapUserRolesProvider.java From fiat with Apache License 2.0 | 5 votes |
private String getUserFullDn(String userId) { String rootDn = LdapUtils.parseRootDnFromUrl(configProps.getUrl()); DistinguishedName root = new DistinguishedName(rootDn); log.debug("Root DN: " + root.toString()); String[] formatArgs = new String[] {LdapEncoder.nameEncode(userId)}; String partialUserDn; if (!StringUtils.isEmpty(configProps.getUserSearchFilter())) { try { DirContextOperations res = ldapTemplate.searchForSingleEntry( configProps.getUserSearchBase(), configProps.getUserSearchFilter(), formatArgs); partialUserDn = res.getDn().toString(); } catch (IncorrectResultSizeDataAccessException e) { log.error("Unable to find a single user entry", e); return null; } } else { partialUserDn = configProps.getUserDnPattern().format(formatArgs); } DistinguishedName user = new DistinguishedName(partialUserDn); log.debug("User portion: " + user.toString()); try { Name fullUser = root.addAll(user); log.debug("Full user DN: " + fullUser.toString()); return fullUser.toString(); } catch (InvalidNameException ine) { log.error("Could not assemble full userDn", ine); } return null; }
Example 5
Source File: right_LmiInitialContext_1.6.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
public String composeName(String name, String prefix) throws NamingException { if (TraceCarol.isDebugJndiCarol()) { TraceCarol.debugJndiCarol("LmiInitialContext.composeName(" + name + "," + prefix + ")"); } Name result = composeName(new CompositeName(name), new CompositeName(prefix)); return result.toString(); }
Example 6
Source File: left_LmiInitialContext_1.5.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
public String composeName(String name, String prefix) throws NamingException { if (TraceCarol.isDebugJndiCarol()) { TraceCarol.debugJndiCarol("LmiInitialContext.composeName(" + name + "," + prefix + ")"); } Name result = composeName(new CompositeName(name), new CompositeName(prefix)); return result.toString(); }
Example 7
Source File: ContinuationDirContext.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
protected DirContextStringPair getTargetContext(String name) throws NamingException { if (cpe.getResolvedObj() == null) throw (NamingException)cpe.fillInStackTrace(); Context ctx = NamingManager.getContext(cpe.getResolvedObj(), cpe.getAltName(), cpe.getAltNameCtx(), env); if (ctx instanceof DirContext) return new DirContextStringPair((DirContext)ctx, name); if (ctx instanceof Resolver) { Resolver res = (Resolver)ctx; ResolveResult rr = res.resolveToClass(name, DirContext.class); // Reached a DirContext; return result. DirContext dctx = (DirContext)rr.getResolvedObj(); Name tmp = rr.getRemainingName(); String remains = (tmp != null) ? tmp.toString() : ""; return (new DirContextStringPair(dctx, remains)); } // Resolve all the way using lookup(). This may allow the operation // to succeed if it doesn't require the penultimate context. Object ultimate = ctx.lookup(name); if (ultimate instanceof DirContext) { return (new DirContextStringPair((DirContext)ultimate, "")); } throw (NamingException)cpe.fillInStackTrace(); }
Example 8
Source File: ContinuationDirContext.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
protected DirContextStringPair getTargetContext(String name) throws NamingException { if (cpe.getResolvedObj() == null) throw (NamingException)cpe.fillInStackTrace(); Context ctx = NamingManager.getContext(cpe.getResolvedObj(), cpe.getAltName(), cpe.getAltNameCtx(), env); if (ctx instanceof DirContext) return new DirContextStringPair((DirContext)ctx, name); if (ctx instanceof Resolver) { Resolver res = (Resolver)ctx; ResolveResult rr = res.resolveToClass(name, DirContext.class); // Reached a DirContext; return result. DirContext dctx = (DirContext)rr.getResolvedObj(); Name tmp = rr.getRemainingName(); String remains = (tmp != null) ? tmp.toString() : ""; return (new DirContextStringPair(dctx, remains)); } // Resolve all the way using lookup(). This may allow the operation // to succeed if it doesn't require the penultimate context. Object ultimate = ctx.lookup(name); if (ultimate instanceof DirContext) { return (new DirContextStringPair((DirContext)ultimate, "")); } throw (NamingException)cpe.fillInStackTrace(); }
Example 9
Source File: ContinuationDirContext.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
protected DirContextStringPair getTargetContext(String name) throws NamingException { if (cpe.getResolvedObj() == null) throw (NamingException)cpe.fillInStackTrace(); Context ctx = NamingManager.getContext(cpe.getResolvedObj(), cpe.getAltName(), cpe.getAltNameCtx(), env); if (ctx instanceof DirContext) return new DirContextStringPair((DirContext)ctx, name); if (ctx instanceof Resolver) { Resolver res = (Resolver)ctx; ResolveResult rr = res.resolveToClass(name, DirContext.class); // Reached a DirContext; return result. DirContext dctx = (DirContext)rr.getResolvedObj(); Name tmp = rr.getRemainingName(); String remains = (tmp != null) ? tmp.toString() : ""; return (new DirContextStringPair(dctx, remains)); } // Resolve all the way using lookup(). This may allow the operation // to succeed if it doesn't require the penultimate context. Object ultimate = ctx.lookup(name); if (ultimate instanceof DirContext) { return (new DirContextStringPair((DirContext)ultimate, "")); } throw (NamingException)cpe.fillInStackTrace(); }
Example 10
Source File: JndiUtils.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Convert a {@link javax.naming.Name} to a Dn * * @param name The Name to convert * @return A Dn */ public static Dn fromName( Name name ) { try { return new Dn( name.toString() ); } catch ( LdapInvalidDnException lide ) { // TODO : check if we must throw an exception. // Logically, the Name must be valid. return null; } }
Example 11
Source File: ContinuationDirContext.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
protected DirContextStringPair getTargetContext(String name) throws NamingException { if (cpe.getResolvedObj() == null) throw (NamingException)cpe.fillInStackTrace(); Context ctx = NamingManager.getContext(cpe.getResolvedObj(), cpe.getAltName(), cpe.getAltNameCtx(), env); if (ctx instanceof DirContext) return new DirContextStringPair((DirContext)ctx, name); if (ctx instanceof Resolver) { Resolver res = (Resolver)ctx; ResolveResult rr = res.resolveToClass(name, DirContext.class); // Reached a DirContext; return result. DirContext dctx = (DirContext)rr.getResolvedObj(); Name tmp = rr.getRemainingName(); String remains = (tmp != null) ? tmp.toString() : ""; return (new DirContextStringPair(dctx, remains)); } // Resolve all the way using lookup(). This may allow the operation // to succeed if it doesn't require the penultimate context. Object ultimate = ctx.lookup(name); if (ultimate instanceof DirContext) { return (new DirContextStringPair((DirContext)ultimate, "")); } throw (NamingException)cpe.fillInStackTrace(); }
Example 12
Source File: ContinuationDirContext.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
protected DirContextStringPair getTargetContext(String name) throws NamingException { if (cpe.getResolvedObj() == null) throw (NamingException)cpe.fillInStackTrace(); Context ctx = NamingManager.getContext(cpe.getResolvedObj(), cpe.getAltName(), cpe.getAltNameCtx(), env); if (ctx instanceof DirContext) return new DirContextStringPair((DirContext)ctx, name); if (ctx instanceof Resolver) { Resolver res = (Resolver)ctx; ResolveResult rr = res.resolveToClass(name, DirContext.class); // Reached a DirContext; return result. DirContext dctx = (DirContext)rr.getResolvedObj(); Name tmp = rr.getRemainingName(); String remains = (tmp != null) ? tmp.toString() : ""; return (new DirContextStringPair(dctx, remains)); } // Resolve all the way using lookup(). This may allow the operation // to succeed if it doesn't require the penultimate context. Object ultimate = ctx.lookup(name); if (ultimate instanceof DirContext) { return (new DirContextStringPair((DirContext)ultimate, "")); } throw (NamingException)cpe.fillInStackTrace(); }
Example 13
Source File: ContinuationDirContext.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
protected DirContextStringPair getTargetContext(String name) throws NamingException { if (cpe.getResolvedObj() == null) throw (NamingException)cpe.fillInStackTrace(); Context ctx = NamingManager.getContext(cpe.getResolvedObj(), cpe.getAltName(), cpe.getAltNameCtx(), env); if (ctx instanceof DirContext) return new DirContextStringPair((DirContext)ctx, name); if (ctx instanceof Resolver) { Resolver res = (Resolver)ctx; ResolveResult rr = res.resolveToClass(name, DirContext.class); // Reached a DirContext; return result. DirContext dctx = (DirContext)rr.getResolvedObj(); Name tmp = rr.getRemainingName(); String remains = (tmp != null) ? tmp.toString() : ""; return (new DirContextStringPair(dctx, remains)); } // Resolve all the way using lookup(). This may allow the operation // to succeed if it doesn't require the penultimate context. Object ultimate = ctx.lookup(name); if (ultimate instanceof DirContext) { return (new DirContextStringPair((DirContext)ultimate, "")); } throw (NamingException)cpe.fillInStackTrace(); }
Example 14
Source File: ContinuationDirContext.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
protected DirContextStringPair getTargetContext(String name) throws NamingException { if (cpe.getResolvedObj() == null) throw (NamingException)cpe.fillInStackTrace(); Context ctx = NamingManager.getContext(cpe.getResolvedObj(), cpe.getAltName(), cpe.getAltNameCtx(), env); if (ctx instanceof DirContext) return new DirContextStringPair((DirContext)ctx, name); if (ctx instanceof Resolver) { Resolver res = (Resolver)ctx; ResolveResult rr = res.resolveToClass(name, DirContext.class); // Reached a DirContext; return result. DirContext dctx = (DirContext)rr.getResolvedObj(); Name tmp = rr.getRemainingName(); String remains = (tmp != null) ? tmp.toString() : ""; return (new DirContextStringPair(dctx, remains)); } // Resolve all the way using lookup(). This may allow the operation // to succeed if it doesn't require the penultimate context. Object ultimate = ctx.lookup(name); if (ultimate instanceof DirContext) { return (new DirContextStringPair((DirContext)ultimate, "")); } throw (NamingException)cpe.fillInStackTrace(); }
Example 15
Source File: ConversionServiceConverterManager.java From spring-ldap with Apache License 2.0 | 5 votes |
@Override public String convert(Name source) { if(source == null) { return null; } return source.toString(); }
Example 16
Source File: InstanceKeyDataSourceFactory.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Implements ObjectFactory to create an instance of SharedPoolDataSource or PerUserPoolDataSource */ @Override public Object getObjectInstance(final Object refObj, final Name name, final Context context, final Hashtable<?, ?> env) throws IOException, ClassNotFoundException { // The spec says to return null if we can't create an instance // of the reference Object obj = null; if (refObj instanceof Reference) { final Reference ref = (Reference) refObj; if (isCorrectClass(ref.getClassName())) { final RefAddr refAddr = ref.get("instanceKey"); if (refAddr != null && refAddr.getContent() != null) { // object was bound to JNDI via Referenceable API. obj = instanceMap.get(refAddr.getContent()); } else { // Tomcat JNDI creates a Reference out of server.xml // <ResourceParam> configuration and passes it to an // instance of the factory given in server.xml. String key = null; if (name != null) { key = name.toString(); obj = instanceMap.get(key); } if (obj == null) { final InstanceKeyDataSource ds = getNewInstance(ref); setCommonProperties(ref, ds); obj = ds; if (key != null) { instanceMap.put(key, ds); } } } } } return obj; }
Example 17
Source File: MemoryUserDatabaseFactory.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * <p>Create and return a new <code>MemoryUserDatabase</code> instance * that has been configured according to the properties of the * specified <code>Reference</code>. If you instance can be created, * return <code>null</code> instead.</p> * * @param obj The possibly null object containing location or * reference information that can be used in creating an object * @param name The name of this object relative to <code>nameCtx</code> * @param nameCtx The context relative to which the <code>name</code> * parameter is specified, or <code>null</code> if <code>name</code> * is relative to the default initial context * @param environment The possibly null environment that is used in * creating this object */ @Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment) throws Exception { // We only know how to deal with <code>javax.naming.Reference</code>s // that specify a class name of "org.apache.catalina.UserDatabase" if ((obj == null) || !(obj instanceof Reference)) { return null; } Reference ref = (Reference) obj; if (!"org.apache.catalina.UserDatabase".equals(ref.getClassName())) { return null; } // Create and configure a MemoryUserDatabase instance based on the // RefAddr values associated with this Reference MemoryUserDatabase database = new MemoryUserDatabase(name.toString()); RefAddr ra = null; ra = ref.get("pathname"); if (ra != null) { database.setPathname(ra.getContent().toString()); } ra = ref.get("readonly"); if (ra != null) { database.setReadonly(Boolean.parseBoolean(ra.getContent().toString())); } ra = ref.get("watchSource"); if (ra != null) { database.setWatchSource(Boolean.parseBoolean(ra.getContent().toString())); } // Return the configured database instance database.open(); // Don't try something we know won't work if (!database.getReadonly()) database.save(); return database; }
Example 18
Source File: LocalContext.java From unitime with Apache License 2.0 | 4 votes |
@Override public String composeName(String name, String prefix) throws NamingException { Name result = composeName(new CompositeName(name), new CompositeName(prefix)); return result.toString(); }
Example 19
Source File: DefaultDirObjectFactory.java From spring-ldap with Apache License 2.0 | 4 votes |
/** * Construct a DirContextAdapter given the supplied paramters. The * <code>name</code> is normally a JNDI <code>CompositeName</code>, which * needs to be handled with particuclar care. Specifically the escaping of a * <code>CompositeName</code> destroys proper escaping of Distinguished * Names. Also, the name might contain referral information, in which case * we need to separate the server information from the actual Distinguished * Name so that we can create a representing DirContextAdapter. * * @param attrs the attributes * @param name the Name, typically a <code>CompositeName</code>, possibly * including referral information. * @param nameInNamespace the Name in namespace. * @return a {@link DirContextAdapter} representing the specified * information. */ DirContextAdapter constructAdapterFromName(Attributes attrs, Name name, String nameInNamespace) { String nameString; String referralUrl = ""; if (name instanceof CompositeName) { // Which it most certainly will be, and therein lies the // problem. CompositeName.toString() completely screws up the // formatting // in some cases, particularly when backslashes are involved. nameString = LdapUtils .convertCompositeNameToString((CompositeName) name); } else { LOG .warn("Expecting a CompositeName as input to getObjectInstance but received a '" + name.getClass().toString() + "' - using toString and proceeding with undefined results"); nameString = name.toString(); } if (nameString.startsWith(LDAP_PROTOCOL_PREFIX) || nameString.startsWith(LDAPS_PROTOCOL_PREFIX)) { if (LOG.isDebugEnabled()) { LOG.debug("Received name '" + nameString + "' contains protocol delimiter; indicating a referral." + "Stripping protocol and address info to enable construction of a proper LdapName"); } try { URI url = new URI(nameString); String pathString = url.getPath(); referralUrl = nameString.substring(0, nameString.length() - pathString.length()); if (StringUtils.hasLength(pathString) && pathString.startsWith("/")) { // We don't want any slash in the beginning of the // Distinguished Name. pathString = pathString.substring(1); } nameString = pathString; } catch (URISyntaxException e) { throw new IllegalArgumentException( "Supplied name starts with protocol prefix indicating a referral," + " but is not possible to parse to an URI", e); } if (LOG.isDebugEnabled()) { LOG.debug("Resulting name after removal of referral information: '" + nameString + "'"); } } DirContextAdapter dirContextAdapter = new DirContextAdapter(attrs, LdapUtils.newLdapName(nameString), LdapUtils.newLdapName(nameInNamespace), referralUrl); dirContextAdapter.setUpdateMode(true); return dirContextAdapter; }
Example 20
Source File: RMIContext.java From oodt with Apache License 2.0 | 4 votes |
public String composeName(String name, String prefix) throws NamingException { Name result = composeName(new CompositeName(name), new CompositeName(prefix)); return result.toString(); }