List of usage examples for javax.naming NamingEnumeration next
public T next() throws NamingException;
From source file:be.fedict.eid.dss.sp.StartupServletContextListener.java
public static void bindComponent(String jndiName, Object component) throws NamingException { LOG.debug("bind component: " + jndiName); InitialContext initialContext = new InitialContext(); String[] names = jndiName.split("/"); Context context = initialContext; for (int idx = 0; idx < names.length - 1; idx++) { String name = names[idx]; LOG.debug("name: " + name); NamingEnumeration<NameClassPair> listContent = context.list(""); boolean subContextPresent = false; while (listContent.hasMore()) { NameClassPair nameClassPair = listContent.next(); if (!name.equals(nameClassPair.getName())) { continue; }/*from w w w.j av a2s.c o m*/ subContextPresent = true; } if (!subContextPresent) { context = context.createSubcontext(name); } else { context = (Context) context.lookup(name); } } String name = names[names.length - 1]; context.rebind(name, component); }
From source file:de.micromata.genome.util.runtime.jndi.JndiDumper.java
public static void dumpJndiBinding(InitialContext initialContext, String parentKey, Binding binding, StringBuilder sb, String indent) throws NamingException { try {/* w w w . j a v a 2s. c o m*/ Object obj = binding.getObject(); ClassLoader bindClassLoader = obj.getClass().getClassLoader(); sb.append(indent).append(parentKey + "/" + binding.getName()).append("(") .append(System.identityHashCode(binding)).append(", cl: ").append(bindClassLoader).append("): ") .append(binding.toString()); if (obj instanceof Context) { sb.append("\n"); Context ctx = (Context) obj; indent += " "; NamingEnumeration<Binding> bindings = ctx.listBindings(""); while (bindings.hasMore()) { Binding cbinding = bindings.next(); dumpJndiBinding(initialContext, parentKey + "/" + binding.getName(), cbinding, sb, indent); } } else if (obj instanceof Reference) { Reference ref = (Reference) obj; // binding.get // ref. sb.append("\n"); } else if (obj instanceof Session) { Session sess = (Session) obj; sb.append("\n"); } else if (obj instanceof DataSource) { DataSource ds = (DataSource) obj; if (ds instanceof BasicDataSource) { BasicDataSource dbds = (BasicDataSource) ds; sb.append(" '" + dbds.getUrl() + "'"); } sb.append("\n"); } else if (obj != null) { Class<? extends Object> clazz = obj.getClass(); sb.append(" unkown type: " + clazz); sb.append("\n"); } } catch (NamingException ex) { sb.append("Error access binding: " + binding.getName() + ": " + ex.getMessage()); } }
From source file:org.apache.cxf.sts.claims.LdapUtils.java
public static List<String> getAttributeOfEntries(LdapTemplate ldapTemplate, String baseDN, String objectClass, String filterAttributeName, String filterAttributeValue, String searchAttribute) { List<String> ldapAttributes = null; AttributesMapper mapper = new AttributesMapper() { public Object mapFromAttributes(Attributes attrs) throws NamingException { NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll(); while (attrEnum.hasMore()) { return (String) attrEnum.next().get(); }//from www . j a va2s. com return null; } }; String[] searchAttributes = new String[] { searchAttribute }; List<?> result = null; AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", objectClass)) .and(new EqualsFilter(filterAttributeName, filterAttributeValue)); result = ldapTemplate.search((baseDN == null) ? "" : baseDN, filter.toString(), SearchControls.SUBTREE_SCOPE, searchAttributes, mapper); if (result != null && result.size() > 0) { ldapAttributes = CastUtils.cast((List<?>) result); } return ldapAttributes; }
From source file:org.apache.cxf.sts.claims.LdapUtils.java
public static Map<String, Attribute> getAttributesOfEntry(LdapTemplate ldapTemplate, String baseDN, String objectClass, String filterAttributeName, String filterAttributeValue, String[] searchAttributes) { Map<String, Attribute> ldapAttributes = null; AttributesMapper mapper = new AttributesMapper() { public Object mapFromAttributes(Attributes attrs) throws NamingException { Map<String, Attribute> map = new HashMap<String, Attribute>(); NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll(); while (attrEnum.hasMore()) { Attribute att = attrEnum.next(); map.put(att.getID(), att); }/*w ww. j a v a 2 s .c o m*/ return map; } }; List<?> result = null; AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", objectClass)) .and(new EqualsFilter(filterAttributeName, filterAttributeValue)); result = ldapTemplate.search((baseDN == null) ? "" : baseDN, filter.toString(), SearchControls.SUBTREE_SCOPE, searchAttributes, mapper); if (result != null && result.size() > 0) { ldapAttributes = CastUtils.cast((Map<?, ?>) result.get(0)); } return ldapAttributes; }
From source file:org.pepstock.jem.annotations.SetFields.java
private static void checkIfIsRightObject(String name, boolean isDD) throws NamingException { InitialContext ic = ContextUtils.getContext(); NamingEnumeration<NameClassPair> list = ic.list(name); boolean isDataDescription = false; while (list.hasMore()) { NameClassPair pair = list.next(); // checks if is datastream // only datastreams are changed if (pair instanceof DataStreamNameClassPair) { isDataDescription = true;/*from w w w . j a v a2 s . co m*/ } } if (isDD && !isDataDescription) { throw new NamingException(name + " is not a data description"); } if (!isDD && isDataDescription) { throw new NamingException(name + " is not a data source"); } }
From source file:com.jaeksoft.searchlib.util.ActiveDirectory.java
public static void collectMemberOf(Attributes attrs, Collection<ADGroup> groups) throws NamingException { Attribute tga = attrs.get("memberOf"); if (tga == null) return;/*from ww w. j a v a2 s.c om*/ NamingEnumeration<?> membersOf = tga.getAll(); while (membersOf.hasMore()) { Object memberObject = membersOf.next(); groups.add(new ADGroup(memberObject.toString())); } membersOf.close(); }
From source file:de.griffel.confluence.plugins.plantuml.DatasourceHelper.java
/** * Determines data sources configured in Tomcat. * * @return List of data source names//from w w w.j a v a2s . co m */ public static List<String> listAvailableDataSources() { final List<String> results = new LinkedList<String>(); // Workaround for classloader problems, see https://answers.atlassian.com/questions/6374/how-do-i-access-jndi-from-a-version-2-osgi-plugin final ClassLoader origCL = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(ComponentManager.class.getClassLoader()); final InitialContext jndiContext = new InitialContext(); final NamingEnumeration<Binding> bindings = jndiContext.listBindings(JDBC_CONTEXT); while (bindings != null && bindings.hasMore()) { results.add(bindings.next().getName()); } } catch (NamingException e) { log.debug("NamingException listBindings", e); results.add(e.toString()); } finally { Thread.currentThread().setContextClassLoader(origCL); } return results; }
From source file:org.codehaus.groovy.grails.plugins.springsecurity.ldap.LdapUtils.java
/** * Retrieves the LDAP attribute values for the specified name. * @param attributeName the LDAP attribute name * @return the values or <code>null</code> if not available *///from w ww. j ava2 s .c om public static List<String> getAttributes(String attributeName) { Object currentUser = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (!(currentUser instanceof GrailsLdapUser)) { LOG.warn("Must be using an implementation of " + GrailsLdapUser.class.getName() + " to retrieve Attributes"); return null; } List<String> values = new ArrayList<String>(); NamingEnumeration<?> attributes = null; try { attributes = ((GrailsLdapUser) currentUser).getAttributes().get(attributeName).getAll(); if (attributes != null) { while (attributes.hasMore()) { values.add(attributes.next().toString()); } } } catch (NamingException e) { LOG.warn("Unable to retrieve attribute " + attributeName + " from the currently logged in user", e); } catch (RuntimeException e) { LOG.warn("Unable to retrieve attribute " + attributeName + " from the currently logged in user", e); } return values; }
From source file:com.funambol.server.db.DataSourceContextHelperTest.java
/** * Usefull method for troubleshooting/*w ww. j av a2 s. c o m*/ * @throws java.lang.Exception */ private static void printContext(String contextName) throws Exception { System.out.println("---------- Listing '" + contextName + "' ------------"); InitialContext initialContext = new InitialContext(); NamingEnumeration<NameClassPair> nameEnum = initialContext.list(contextName); if (nameEnum != null) { while (nameEnum.hasMore()) { NameClassPair name = nameEnum.next(); String nameInSpace = name.getName(); String className = name.getClassName(); System.out.println("NameInSpace: " + nameInSpace + ", class: " + className); } } System.out.println("--------------------------------------------"); }
From source file:org.wso2.carbon.uuf.core.API.java
/** * Returns a map of service implementation class names and instances of all OSGi services for the given service * class name.//ww w . j a va 2 s . c o m * * @param serviceClassName service class name * @return a map of implementation class and instances */ public static Map<String, Object> getOSGiServices(String serviceClassName) { try { Context context = new InitialContext(); NamingEnumeration<Binding> enumeration = context.listBindings("osgi:service/" + serviceClassName); Map<String, Object> services = new HashMap<>(); while (enumeration.hasMore()) { Binding binding = enumeration.next(); services.put(binding.getClassName(), binding.getObject()); } return services; } catch (NamingException e) { throw new UUFException( "Cannot create the initial context when calling OSGi service '" + serviceClassName + "'."); } }