List of usage examples for javax.naming Name toString
public String toString()
From source file:naming.resources.ProxyDirContext.java
/** * Binds a name to an object, overwriting any existing binding. All * intermediate contexts and the target context (that named by all but * terminal atomic component of the name) must already exist. * <p>/* w w w . j a v a2 s .c o m*/ * If the object is a DirContext, any existing attributes associated with * the name are replaced with those of the object. Otherwise, any * existing attributes associated with the name remain unchanged. * * @param name the name to bind; may not be empty * @param obj the object to bind; possibly null * @exception InvalidAttributesException if object did not supply all * mandatory attributes * @exception NamingException if a naming exception is encountered */ public void rebind(Name name, Object obj) throws NamingException { dirContext.rebind(parseName(name), obj); cacheUnload(name.toString()); }
From source file:naming.resources.ProxyDirContext.java
/** * Binds a new name to the object bound to an old name, and unbinds the * old name. Both names are relative to this context. Any attributes * associated with the old name become associated with the new name. * Intermediate contexts of the old name are not changed. * /*from ww w . ja v a2s. c o m*/ * @param oldName the name of the existing binding; may not be empty * @param newName the name of the new binding; may not be empty * @exception NameAlreadyBoundException if newName is already bound * @exception NamingException if a naming exception is encountered */ public void rename(Name oldName, Name newName) throws NamingException { dirContext.rename(parseName(oldName), parseName(newName)); cacheUnload(oldName.toString()); }
From source file:it.infn.ct.futuregateway.apiserver.utils.ThreadPoolFactory.java
@Override public final Object getObjectInstance(final Object obj, final Name name, final Context ctx, final Hashtable<?, ?> env) throws Exception { Reference ref = (Reference) obj; Enumeration<RefAddr> addrs = ref.getAll(); int threadPoolSize = Constants.DEFAULTTHREADPOOLSIZE; int maxThreadPoolSize = Constants.MAXTHREADPOOLSIZETIMES * threadPoolSize; int maxThreadIdleTime = Constants.MAXTHREADPOOLSIZETIMES; while (addrs.hasMoreElements()) { RefAddr addr = (RefAddr) addrs.nextElement(); String addrName = addr.getType(); String addrValue = (String) addr.getContent(); switch (addrName) { case "poolSize": try { threadPoolSize = Integer.parseInt(addrValue); } catch (NumberFormatException nfe) { log.warn("Attribute poolSize format not correct." + " Default value applied."); }//w w w .ja v a 2s. com break; case "maxPoolSize": try { maxThreadPoolSize = Integer.parseInt(addrValue); } catch (NumberFormatException nfe) { log.warn("Attribute maxPoolSize format not correct." + " Default value applied."); } break; case "maxThreadIdleTimeMills": try { maxThreadIdleTime = Integer.parseInt(addrValue); } catch (NumberFormatException nfe) { log.warn("Attribute maxThreadIdleTimeMills format not" + " correct. Default value applied."); } break; default: } } log.info("A new thread pool created with name: " + name.toString()); return (ThreadPoolFactory.getThreadPool(threadPoolSize, maxThreadPoolSize, maxThreadIdleTime)); }
From source file:com.dattack.naming.AbstractContext.java
@Override public Object lookup(final Name name) throws NamingException { ensureContextNotClosed();/*from w w w. ja v a 2s. c o m*/ /* * Extract from Context Javadoc: If name is empty, returns a new instance of this context (which represents the * same naming context as this context, but its environment may be modified independently and it may be accessed * concurrently). */ if (name.isEmpty()) { try { return this.clone(); } catch (final CloneNotSupportedException e) { // this shouldn't happen, since we are Cloneable throw (NamingException) new OperationNotSupportedException(e.getMessage()).initCause(e); } } if (name.size() > 1) { if (subContexts.containsKey(name.getPrefix(1))) { return subContexts.get(name.getPrefix(1)).lookup(name.getSuffix(1)); } throw new NamingException( String.format("Invalid subcontext '%s' in context '%s'", name.getPrefix(1).toString(), StringUtils.isBlank(getNameInNamespace()) ? "/" : getNameInNamespace())); } Object result = null; // not found if (objectTable.containsKey(name)) { result = objectTable.get(name); } else if (subContexts.containsKey(name)) { result = subContexts.get(name); } else if (env.containsKey(name.toString())) { result = env.get(name.toString()); } return result; }
From source file:se.inera.axel.shs.broker.directory.internal.LdapDirectoryAdminService.java
@Override public void saveActor(Organization organization) { Name dn = buildDn(organization); boolean isNew = false; DirContextAdapter context = null;/*from w w w . ja va2s .c o m*/ try { context = (DirContextAdapter) ldapTemplate.lookupContext(dn); } catch (NameNotFoundException e) { isNew = true; context = new DirContextAdapter(dn); } OrganizationMapper.mapToContext(organization, context); if (isNew) { ldapTemplate.bind(context); DistinguishedName dn2 = (DistinguishedName) dn.clone(); dn2.add("ou", ShsLdapAttributes.OU_PRODUCT_TYPES); context = new DirContextAdapter(dn2); context.setAttributeValues("objectClass", new String[] { "top", "organizationalUnit" }); ldapTemplate.bind(context); dn2 = (DistinguishedName) dn.clone(); dn2.add("ou", ShsLdapAttributes.OU_AGREEMENTS); context = new DirContextAdapter(dn2); context.setAttributeValues("objectClass", new String[] { "top", "organizationalUnit" }); ldapTemplate.bind(context); dn2 = (DistinguishedName) dn.clone(); dn2.add("ou", ShsLdapAttributes.OU_ADRESSES); context = new DirContextAdapter(dn2); context.setAttributeValues("objectClass", new String[] { "top", "organizationalUnit" }); ldapTemplate.bind(context); log.debug("organization {} created in directory", dn.toString()); } else { ldapTemplate.modifyAttributes(context); log.debug("organization {} updated in directory", dn.toString()); } }
From source file:se.inera.axel.shs.broker.directory.internal.LdapDirectoryAdminService.java
@Override public void deleteActor(Organization organization) { Name dn = buildDn(organization); try {//from www . j a v a 2 s .c om for (ProductType o : getProductTypes(organization)) { removeProduct(organization, o); } DistinguishedName productTypesDn = (DistinguishedName) dn.clone(); productTypesDn.add("ou", ShsLdapAttributes.OU_PRODUCT_TYPES); ldapTemplate.unbind(productTypesDn); } catch (Exception e) { log.warn("Error removing product types for organization: " + organization); } try { for (Agreement o : getAgreements(organization)) { removeAgreement(organization, o); } DistinguishedName agreementsDn = (DistinguishedName) dn.clone(); agreementsDn.add("ou", ShsLdapAttributes.OU_AGREEMENTS); ldapTemplate.unbind(agreementsDn); } catch (Exception e) { log.warn("Error removing product types for organization: " + organization); } try { for (Address o : getAddresses(organization)) { removeAddress(organization, o); } DistinguishedName addressesDn = (DistinguishedName) dn.clone(); addressesDn.add("ou", ShsLdapAttributes.OU_ADRESSES); ldapTemplate.unbind(addressesDn); } catch (Exception e) { log.warn("Error removing addresses for organization: " + organization); } try { ldapTemplate.unbind(dn); log.debug("organization {} deleted from directory", dn.toString()); } catch (Exception e) { log.warn("Error removing organization: " + organization); } }
From source file:org.apache.geronimo.security.realm.providers.GenericHttpHeaderLdapLoginModule.java
protected boolean authenticate(String username) throws Exception { DirContext context = open();//from w ww. j a v a 2 s.c o m try { String filter = userSearchMatchingFormat.format(new String[] { username }); SearchControls constraints = new SearchControls(); if (userSearchSubtreeBool) { constraints.setSearchScope(SearchControls.SUBTREE_SCOPE); } else { constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE); } // setup attributes String[] attribs; if (userRoleName == null) { attribs = new String[] {}; } else { attribs = new String[] { userRoleName }; } constraints.setReturningAttributes(attribs); NamingEnumeration results = context.search(userBase, filter, constraints); if (results == null || !results.hasMore()) { log.error("No roles associated with user " + username); loginSucceeded = false; throw new FailedLoginException(); } SearchResult result = (SearchResult) results.next(); if (results.hasMore()) { // ignore for now } NameParser parser = context.getNameParser(""); Name contextName = parser.parse(context.getNameInNamespace()); Name baseName = parser.parse(userBase); Name entryName = parser.parse(result.getName()); Name name = contextName.addAll(baseName); name = name.addAll(entryName); String dn = name.toString(); Attributes attrs = result.getAttributes(); if (attrs == null) { return false; } ArrayList<String> roles = null; if (userRoleName != null) { roles = addAttributeValues(userRoleName, attrs, roles); } // check the credentials by binding to server // bindUser(context, dn); // if authenticated add more roles roles = getRoles(context, dn, username, roles); for (String role : roles) { groups.add(role); } if (groups.isEmpty()) { log.error("No roles associated with user " + username); loginSucceeded = false; throw new FailedLoginException(); } else loginSucceeded = true; } catch (CommunicationException e) { close(context); throw (LoginException) new FailedLoginException().initCause(e); } catch (NamingException e) { close(context); throw (LoginException) new FailedLoginException().initCause(e); } return true; }
From source file:org.apache.naming.modules.cache.ProxyDirContext.java
/** * Retrieves the named object. If name is empty, returns a new instance * of this context (which represents the same naming context as this * context, but its environment may be modified independently and it may * be accessed concurrently).//from w ww .j a va2 s . c o m * * @param name the name of the object to look up * @return the object bound to name * @exception NamingException if a naming exception is encountered */ public Object lookup(Name name) throws NamingException { CacheEntry entry = cacheLookupAndLoad(name.toString()); if (entry != null) { if (entry.resource != null) { // Check content caching. return entry.resource; } else { return entry.context; } } log.info("Strange, entry was no loadeded " + name); Object object = dirContext.lookup(parseName(name)); // if (object instanceof InputStream) // return new Resource((InputStream) object); // else return object; }
From source file:org.apache.naming.modules.cache.ProxyDirContext.java
/** * Retrieves all of the attributes associated with a named object. * /*from w ww .j a v a2 s. c o m*/ * @return the set of attributes associated with name. * Returns an empty attribute set if name has no attributes; never null. * @param name the name of the object from which to retrieve attributes * @exception NamingException if a naming exception is encountered */ public Attributes getAttributes(Name name) throws NamingException { CacheEntry entry = cacheLookupAndLoad(name.toString()); if (entry != null) { return entry.attributes; } Attributes attributes = dirContext.getAttributes(parseName(name)); // TODO(costin): Why do we need to wrap it ? It may be better to use decorator // if (!(attributes instanceof ResourceAttributes)) { // attributes = new ResourceAttributes(attributes); // } return attributes; }
From source file:org.apache.naming.modules.fs.FileDirContext.java
/** * Retrieves the named object. The result is a File relative to the docBase * or a FileDirContext for directories./*from ww w .j ava 2 s . co m*/ * * @param name the name of the object to look up * @return the object bound to name * @exception NamingException if a naming exception is encountered */ public Object lookup(Name nameObj, boolean resolveLinkx) throws NamingException { if (log.isDebugEnabled()) log.debug("lookup " + nameObj); System.out.println("XXX " + nameObj.get(0)); if ("fs:".equals(nameObj.get(0).toString())) nameObj = nameObj.getSuffix(1); String name = nameObj.toString(); // we need to convert anyway, for File constructor Object result = null; File file = file(name); if (file == null) throw new NamingException(sm.getString("resources.notFound", name)); if (file.isDirectory()) { FileDirContext tempContext = new FileDirContext(env); tempContext.setDocBase(file.getPath()); result = tempContext; } else { // TODO: based on the name, return various 'styles' of // content // TODO: use lazy streams, cacheable result = file; //new FileResource(file); } return result; }