List of usage examples for javax.naming NamingEnumeration next
public T next() throws NamingException;
From source file:org.apache.activemq.jndi.JNDITestSupport.java
/** * Stops all existing ActiveMQConnectionFactory in Context. * * @throws javax.naming.NamingException//from w w w . ja v a 2s .c o m */ @Override protected void tearDown() throws NamingException, JMSException { NamingEnumeration<Binding> iter = context.listBindings(""); while (iter.hasMore()) { Binding binding = iter.next(); Object connFactory = binding.getObject(); if (connFactory instanceof ActiveMQConnectionFactory) { // ((ActiveMQConnectionFactory) connFactory).stop(); } } }
From source file:ldap.UserAccountImpl.java
public String toString() { StringBuffer buffer = new StringBuffer(); String name = null;/*from w w w. j a v a2 s . c om*/ try { NamingEnumeration attList = getAll(); while (attList.hasMore()) { Attribute att = (Attribute) attList.next(); //if (att.getID().equals(Config.USER_NAMING_ATT)) if (att.getID().equals(LdapConstants.ldapAttrUid)) name = att.get().toString() + "\n"; buffer.append(" ").append(att.getID()).append(": "); if (att.size() == 1) buffer.append(att.get().toString()).append("\n"); else { NamingEnumeration values = att.getAll(); buffer.append("\n"); while (values.hasMore()) buffer.append(" ").append(values.next()).append("\n"); } } if (name != null) buffer.insert(0, name); } catch (NamingException e) { return "Unexpected Internal Error dumping UserAccount to text.\nError was: " + e.getMessage(); } return buffer.toString(); }
From source file:org.apache.activemq.jndi.JNDITestSupport.java
protected void assertBinding(Binding binding) throws NamingException { Object object = binding.getObject(); assertTrue("Should have got a child context but got: " + object, object instanceof Context); Context childContext = (Context) object; NamingEnumeration<Binding> iter = childContext.listBindings(""); while (iter.hasMore()) { Binding destinationBinding = iter.next(); LOG.info("Found destination: " + destinationBinding.getName()); Object destination = destinationBinding.getObject(); assertTrue("Should have a Destination but got: " + destination, destination instanceof Destination); }//from ww w . ja va2 s. co m }
From source file:ca.aedwards.ldap.compnent.LdapClConsumer.java
private void sendMessage(LdapSearchResult result) throws Exception { Exchange exchange = endpoint.createExchange(); // create a message body Date now = new Date(); exchange.getIn().setBody(result.getChanges()); // Set the headers/properties NamingEnumeration<String> names = result.getAttributes().getIDs(); while (names.hasMore()) { String key = names.next(); String value = result.getAttr(key); exchange.getIn().setHeader("LDAPCL_" + key.toUpperCase(), value); }// w w w.j a v a 2s . c o m try { // send message to next processor in the route getProcessor().process(exchange); } finally { // log exception if an exception occurred and was not handled if (exchange.getException() != null) { getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException()); } } }
From source file:org.apache.james.user.ldap.ReadOnlyLDAPGroupRestriction.java
/** * Extracts the DNs for members of the group with the given LDAP context * attributes. This is achieved by extracting all the values of the LDAP * attribute, with name equivalent to the field value * {@link #memberAttribute}, from the attributes collection. * * @param groupAttributes The attributes taken from the group's LDAP context. * @return A collection of distinguished-names for the users belonging to * the group with the specified attributes. * @throws NamingException Propagated from underlying LDAP communication layer. *///from ww w .j a v a 2s .com private Collection<String> extractMembers(Attributes groupAttributes) throws NamingException { Collection<String> result = new ArrayList<String>(); Attribute members = groupAttributes.get(memberAttribute); NamingEnumeration<?> memberDNs = members.getAll(); while (memberDNs.hasMore()) result.add(memberDNs.next().toString()); return result; }
From source file:com.swdouglass.joid.server.DirectoryUserManagerImpl.java
@Override public User getUser(String username) { User user = null;//from w w w. j a va2 s.c om try { Attributes attrs = findAttributes(username, initialCtx); if (attrs != null) { if (log.isDebugEnabled()) { NamingEnumeration ne = attrs.getAll(); while (ne.hasMore()) { log.debug(ne.next()); } } // create the user, password very likely to be in binary form... user = new User(username, DirectoryUtil.getAttributeValue(attrs, PASSWORD_ATTRIBUTE_PROP, PASSWORD_ATTRIBUTE_PROP_DEFAULT)); // set the list of OpenIDs Attribute openIDattr = attrs .get(DirectoryUtil.getProperty(OPENID_OBJECTCLASS_PROP, OPENID_OBJECTCLASS_PROP_DEFAULT)); Enumeration e = openIDattr.getAll(); Set<String> openIDs = new HashSet<String>(); while (e.hasMoreElements()) { openIDs.add((String) e.nextElement()); } user.setOpenIDs(openIDs); } } catch (NamingException ex) { log.warn("Error in finding the userame=" + username, ex); } return user; }
From source file:org.jasig.schedassist.impl.ldap.DefaultAttributesMapperImpl.java
/** * /*from w w w. j av a 2 s . c o m*/ * @param attributes * @return * @throws NamingException */ protected final Map<String, List<String>> convertToStringAttributesMap(Attributes attributes) throws NamingException { Map<String, List<String>> attributesMap = new HashMap<String, List<String>>(); NamingEnumeration<String> attributeNames = attributes.getIDs(); while (attributeNames.hasMore()) { String attributeName = attributeNames.next(); if (ldapAttributesKey.getPasswordAttributeName().equalsIgnoreCase(attributeName)) { // skip continue; } Attribute attribute = attributes.get(attributeName); int numberOfValues = attribute.size(); for (int i = 0; i < numberOfValues; i++) { String value = (String) attribute.get(i); if (null != value) { value = value.trim(); } List<String> list = safeGetAttributeList(attributesMap, attributeName.toLowerCase()); list.add(value); } } return attributesMap; }
From source file:io.kamax.mxisd.backend.ldap.LdapBackend.java
public List<String> getAttributes(Entry entry, String attName) { List<String> values = new ArrayList<>(); javax.naming.directory.Attribute att = AttributeUtils.toAttributes(entry).get(attName); if (att == null) { return values; }// w w w .j ava2s . c o m try { NamingEnumeration<?> list = att.getAll(); while (list.hasMore()) { values.add(list.next().toString()); } } catch (NamingException e) { log.warn("Error while processing LDAP attribute {}, result could be incomplete!", attName, e); } return values; }
From source file:com.seyren.core.security.ldap.LdapUserManagement.java
@Override public String[] autoCompleteUsers(String name) { List<String> users = new ArrayList<String>(); try {/*w w w.j av a 2 s. c om*/ DirContext readOnlyContext = contextSource.getReadOnlyContext(); SearchControls ctls = new SearchControls(); ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); String[] attrIDs = { USERNAME }; ctls.setReturningAttributes(attrIDs); NamingEnumeration<SearchResult> results = readOnlyContext.search("", "(sAMAccountName=" + name + "*)", ctls); while (results.hasMore()) { SearchResult rslt = results.next(); Attributes attrs = rslt.getAttributes(); if (attrs.get(USERNAME) != null) { users.add((String) attrs.get(USERNAME).get()); } } } catch (NamingException e) { } return users.toArray(new String[users.size()]); }
From source file:binky.reportrunner.ui.actions.datasource.SetupEditJNDIDataSource.java
private List<String> listJNDINames(Context ctx, String ident) throws NamingException { List<String> names = new LinkedList<String>(); String indent = ""; NamingEnumeration<Binding> list = ctx.listBindings(""); while (list.hasMore()) { Binding item = (Binding) list.next(); String className = item.getClassName(); String name = item.getName(); logger.debug(indent + className + " " + name); Object o = item.getObject(); if (o instanceof javax.naming.Context) { names.addAll(listJNDINames((Context) o, name)); } else {//from ww w . j a va 2 s. c o m names.add(ident + "/" + name); } } return names; }