List of usage examples for javax.naming NamingEnumeration hasMore
public boolean hasMore() throws NamingException;
From source file:ldap.UserAccountImpl.java
public UserAccountImpl(Attributes atts) throws NamingException { NamingEnumeration attList = atts.getAll(); while (attList.hasMore()) { Attribute att = (Attribute) attList.next(); put(att);//w w w . j a v a2s .com } }
From source file:ldap.UserAccountImpl.java
public String toString() { StringBuffer buffer = new StringBuffer(); String name = null;//from www .j ava 2 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:de.interseroh.report.test.security.LdapServerTest.java
@Test public void testJndiSun() throws NamingException { Hashtable<String, String> contextParams = new Hashtable<String, String>(); contextParams.put(Context.PROVIDER_URL, "ldap://ldap.xxx:389"); contextParams.put(Context.SECURITY_PRINCIPAL, USER_LDAP); contextParams.put(Context.SECURITY_CREDENTIALS, PASSWORD_LDAP); contextParams.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); DirContext dirContext = new InitialDirContext(contextParams); Attributes attributes = dirContext.getAttributes("", new String[] { "namingContexts" }); Attribute attribute = attributes.get("namingContexts"); NamingEnumeration<?> all = attribute.getAll(); while (all.hasMore()) { String next = (String) all.next(); logger.info(next);/*from w w w .j ava2 s . c o m*/ } }
From source file:org.apache.activemq.jndi.JNDITestSupport.java
/** * Stops all existing ActiveMQConnectionFactory in Context. * * @throws javax.naming.NamingException/*from ww w . ja va 2 s . 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:it.infn.ct.security.utilities.LDAPUtils.java
public static boolean isCNregistered(String cn) { boolean registered = false; NamingEnumeration results = null; DirContext ctx = null;//from ww w . j a va2s .c o m try { ctx = getContext(); SearchControls controls = new SearchControls(); controls.setSearchScope(SearchControls.SUBTREE_SCOPE); ResourceBundle rb = ResourceBundle.getBundle("ldap"); results = ctx.search(rb.getString("peopleRoot"), "(cn=" + cn + ")", controls); if (results.hasMore()) { registered = true; } } catch (NameNotFoundException ex) { _log.error(ex); } catch (NamingException e) { registered = true; } finally { if (results != null) { try { results.close(); } catch (Exception e) { // Never mind this. } } if (ctx != null) { try { ctx.close(); } catch (Exception e) { // Never mind this. } } } return registered; }
From source file:it.infn.ct.security.utilities.LDAPUtils.java
public static boolean isMailUsed(String mail) { boolean registered = false; NamingEnumeration results = null; DirContext ctx = null;// w ww . j a v a 2 s .c o m try { ctx = getContext(); SearchControls controls = new SearchControls(); controls.setSearchScope(SearchControls.SUBTREE_SCOPE); ResourceBundle rb = ResourceBundle.getBundle("ldap"); results = ctx.search(rb.getString("peopleRoot"), "(mail=" + mail + ")", controls); if (results.hasMore()) { registered = true; } } catch (NameNotFoundException ex) { _log.error(ex); } catch (NamingException e) { registered = true; } finally { if (results != null) { try { results.close(); } catch (Exception e) { // Never mind this. } } if (ctx != null) { try { ctx.close(); } catch (Exception e) { // Never mind this. } } } return registered; }
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); }/*w ww. ja v a 2 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 va2 s .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.jasig.schedassist.impl.ldap.DefaultAttributesMapperImpl.java
/** * //from w w w .j ava2 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:com.swdouglass.joid.server.DirectoryUserManagerImpl.java
@Override public User getUser(String username) { User user = null;/*w ww .j a v a 2 s.c o m*/ 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; }