List of usage examples for javax.naming NamingEnumeration next
public T next() throws NamingException;
From source file:org.jamwiki.ldap.LdapUserHandler.java
/** * */// w w w . j a va2s.co m private WikiUserInfo initWikiUserInfo(NamingEnumeration answer) throws Exception { WikiUserInfo userInfo = new WikiUserInfo(); SearchResult sr = (SearchResult) answer.next(); Attributes attributes = sr.getAttributes(); userInfo.setEmail((String) attributes.get(Environment.getValue(Environment.PROP_LDAP_FIELD_EMAIL)).get()); userInfo.setFirstName( (String) attributes.get(Environment.getValue(Environment.PROP_LDAP_FIELD_FIRST_NAME)).get()); userInfo.setLastName( (String) attributes.get(Environment.getValue(Environment.PROP_LDAP_FIELD_LAST_NAME)).get()); return userInfo; }
From source file:org.nuxeo.ecm.directory.ldap.ExternalLDAPDirectoryFeature.java
protected void destroyRecursively(String dn, DirContext ctx, int limit) throws NamingException { if (limit == 0) { log.warn("Reach recursion limit, stopping deletion at" + dn); return;/*from w ww .j av a 2s.co m*/ } SearchControls scts = new SearchControls(); scts.setSearchScope(SearchControls.ONELEVEL_SCOPE); NamingEnumeration<SearchResult> children = ctx.search(dn, "(objectClass=*)", scts); try { while (children.hasMore()) { SearchResult child = children.next(); String subDn = child.getName(); subDn = subDn + ',' + dn; destroyRecursively(subDn, ctx, limit); } } catch (SizeLimitExceededException e) { log.warn("SizeLimitExceededException: trying again on partial results " + dn); if (limit == -1) { limit = 100; } destroyRecursively(dn, ctx, limit - 1); } ctx.destroySubcontext(dn); }
From source file:binky.reportrunner.ui.actions.datasource.SaveDataSource.java
private List<String> listJNDINames(Context ctx, String ident) throws NamingException { List<String> names = new LinkedList<String>(); NamingEnumeration<Binding> list = ctx.listBindings(""); while (list.hasMore()) { Binding item = (Binding) list.next(); String name = item.getName(); Object o = item.getObject(); if (o instanceof javax.naming.Context) { names.addAll(listJNDINames((Context) o, name)); } else {// w ww. j a va 2 s. c o m names.add(ident + "/" + name); } } return names; }
From source file:no.dusken.momus.ldap.LdapSyncer.java
private List<Person> getAllPersonsFromLdap() { final int[] activeCount = { 0 }; List<Person> persons = ldapTemplate.search("ou=Users", "(objectClass=person)", new AttributesMapper<Person>() { @Override/* w w w . j a v a 2s. c om*/ public Person mapFromAttributes(Attributes attributes) throws NamingException { Long id = Long.valueOf((String) attributes.get("uidNumber").get()); String firstName = attributes.get("givenName") != null ? (String) attributes.get("givenName").get() : ""; String fullName = attributes.get("cn") != null ? (String) attributes.get("cn").get() : ""; String userName = attributes.get("uid") != null ? (String) attributes.get("uid").get() : ""; String email = attributes.get("mail") != null ? (String) attributes.get("mail").get() : ""; String telephoneNumber = attributes.get("telephoneNumber") != null ? (String) attributes.get("telephoneNumber").get() : ""; boolean isActive = false; Attribute memberOf1 = attributes.get("memberOf"); if (memberOf1 != null) { NamingEnumeration<?> memberOf = memberOf1.getAll(); while (memberOf.hasMore()) { String group = (String) memberOf.next(); if (group.equalsIgnoreCase( "cn=Active,ou=Sections,ou=Org,ou=Groups,dc=studentmediene,dc=no")) { isActive = true; activeCount[0]++; break; } } } return new Person(id, userName, firstName, fullName, email, telephoneNumber, isActive); } }); logger.info("Number of users from LDAP: {}", persons.size()); logger.info("Number of active: {}", activeCount[0]); return persons; }
From source file:org.archone.ad.dao.CommonDao.java
public List<ShoadUser> listUsers(String domain) throws NamingException { List<ShoadUser> users = new LinkedList<ShoadUser>(); NamingEnumeration<SearchResult> searchResults = dirContext.search(nameConvertor.getUsersBaseDn(domain), "(uid=*)", defaultSearchControls); while (searchResults.hasMore()) { SearchResult sr = searchResults.next(); ShoadUser shoadUser = (ShoadUser) this.dirContext.lookup(sr.getNameInNamespace()); users.add(shoadUser);//from ww w .ja v a 2s .c o m } return users; }
From source file:py.una.pol.karaku.util.LDAPUtil.java
/** * Recupera los usuarios de LDAP//from www .j av a 2 s. c o m * * @return Una lista con los usuarios de LDAP */ public List<User> getUsers() { List<User> users = new ArrayList<User>(); try { DirContext ctx = createInitialDirContext(); Attributes matchAttrs = new BasicAttributes(true); matchAttrs.put(new BasicAttribute("uid")); NamingEnumeration<SearchResult> answer = ctx.search("ou=users", matchAttrs); while (answer.hasMore()) { SearchResult sr = answer.next(); String uid = sr.getName().substring(4); // No se retornan los usuarios especiales if (!uid.startsWith(LDAP_SPECIAL_USER_PREFIX) && !ListHelper.contains(EXCLUDED_USERS, uid)) { User user = new User(); user.setUid(uid); Attributes atributos = sr.getAttributes(); String cn = atributos.get("cn").toString().substring(4); user.setCn(cn); users.add(user); } } } catch (NamingException e) { throw new KarakuRuntimeException(e.getMessage(), e); } return users; }
From source file:org.jasig.schedassist.impl.oraclecalendar.OracleCalendarUserAccountAttributesMapper.java
public Object mapFromAttributes(Attributes attributes) throws NamingException { OracleCalendarUserAccount user = new OracleCalendarUserAccount(); NamingEnumeration<String> attributeNames = attributes.getIDs(); Map<String, String> attributesMap = new HashMap<String, String>(); while (attributeNames.hasMore()) { String attributeName = attributeNames.next(); Attribute attribute = attributes.get(attributeName); String value = (String) attribute.get(); if (null != value) { value = value.trim();/*w w w.j a va2 s . co m*/ } final String lcAttributeName = attributeName.toLowerCase(); attributesMap.put(lcAttributeName, value); if (USERNAME_ATTRIBUTE.equals(lcAttributeName)) { user.setUsername(value); } else if (CALENDAR_UNIQUEID_ATTRIBUTE.equals(lcAttributeName)) { user.setCtcalxitemid(value); } else if (EMAIL_ATTRIBUTE.equals(lcAttributeName)) { user.setEmailAddress(value); } else if (DISPLAYNAME_ATTRIBUTE.equals(lcAttributeName)) { user.setDisplayName(value); } else if (GIVENNAME_ATTRIBUTE.equals(lcAttributeName)) { user.setGivenName(value); } else if (SURNAME_ATTRIBUTE.equals(lcAttributeName)) { user.setSurname(value); } } user.setAttributes(attributesMap); if (user.getCalendarUniqueId() != null) { String oracleGuid = this.oracleGUIDSource.getOracleGUID(user); user.setOracleGuid(oracleGuid); user.getAttributes().put(AbstractOracleCalendarAccount.ORACLE_GUID_ATTRIBUTE, oracleGuid); } return user; }
From source file:org.archone.ad.authentication.ShoadRealm.java
private String getUserDn(String username) throws javax.naming.NamingException { SearchControls controls = new SearchControls(); controls.setSearchScope(SearchControls.SUBTREE_SCOPE); DirContext dirContext = contextSource.getReadOnlyContext(); NamingEnumeration<SearchResult> searchResults = dirContext.search("", adConfiguration.getUserDnSearchFilter(), new String[] { username }, controls); SearchResult sr = searchResults.next(); if (sr == null || searchResults.hasMore()) { throw new AuthenticationException(); }/*from w w w .j ava 2 s . c o m*/ return sr.getNameInNamespace(); }
From source file:org.wso2.carbon.connector.ldap.SearchEntry.java
private OMElement prepareNode(SearchResult entityResult, OMFactory factory, OMNamespace ns, String returnAttributes[]) throws NamingException { Attributes attributes = entityResult.getAttributes(); Attribute attribute;//w w w . ja v a2 s. c om OMElement entry = factory.createOMElement(LDAPConstants.ENTRY, ns); OMElement dnattr = factory.createOMElement(LDAPConstants.DN, ns); dnattr.setText(entityResult.getNameInNamespace()); entry.addChild(dnattr); for (int i = 0; i < returnAttributes.length; i++) { attribute = attributes.get(returnAttributes[i]); if (attribute != null) { NamingEnumeration ne = null; ne = attribute.getAll(); while (ne.hasMoreElements()) { String value = (String) ne.next(); OMElement attr = factory.createOMElement(returnAttributes[i], ns); attr.setText(value); entry.addChild(attr); } } } return entry; }
From source file:org.saiku.reporting.backend.server.SaikuJndiDatasourceConnectionProvider.java
public void showJndiContext(Context ctx, String name, String space) { if (null == name) name = ""; if (null == space) space = ""; try {//from ww w .j av a 2 s .com NamingEnumeration<NameClassPair> en = ctx.list(name); while (en != null && en.hasMoreElements()) { String delim = (name.length() > 0) ? "/" : ""; NameClassPair ncp = en.next(); log.debug(space + name + delim + ncp); if (space.length() < 40) showJndiContext(ctx, ncp.getName(), " " + space); } } catch (javax.naming.NamingException ex) { // Normalerweise zu ignorieren } }