List of usage examples for javax.naming.directory Attributes getIDs
NamingEnumeration<String> getIDs();
From source file:com.aes.touresbalon.touresbalonoms.utilities.ContactAttributeMapperJSON.java
@Override public Object mapFromAttributes(Attributes atrbts) throws NamingException { NamingEnumeration<String> ids = atrbts.getIDs(); JSONObject jo = new JSONObject(); while (ids.hasMore()) { String id = ids.next();//from ww w . j a va2 s . c o m jo.put(id, atrbts.get(id).get()); } return jo.toString(); }
From source file:com.expedia.seiso.security.SeisoUserDetailsContextMapper.java
@SuppressWarnings("unused") private void printAttributeIds(DirContextOperations ctx) { Attributes attrs = ctx.getAttributes(); NamingEnumeration<? extends String> allAttrs = attrs.getIDs(); while (allAttrs.hasMoreElements()) { String attrId = allAttrs.nextElement(); log.trace("attrId={}", attrId); }/* w ww . j a v a2 s .co m*/ }
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();//from ww w.j a v a 2 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.hyperic.hq.plugin.openldap.OpenLDAPMeasurementPlugin.java
/** * @return true = monitoring is enabled * @return false = monitoring is not enabled * @exception NamingException no conection *//*from ww w . j a va2s . c o m*/ private boolean hasMonitoringEnabled(Metric metric) throws NamingException { NamingEnumeration enumer = null, enumerx = null, enumery = null; boolean res = false; try { String[] a = { "monitorContext" }; SearchControls cons = new SearchControls(); cons.setSearchScope(SearchControls.OBJECT_SCOPE); cons.setReturningAttributes(a); enumer = getDirContext(metric.getProperties()).search("", "(&(objectClass=*))", cons); while (enumer.hasMore() && !res) { SearchResult searchresult = (SearchResult) enumer.next(); Attributes attrs = searchresult.getAttributes(); enumerx = attrs.getIDs(); while (enumerx.hasMore()) { String id = (String) enumerx.next(); Attribute attr = attrs.get(id); res = true; } } } finally { if (enumer != null) { enumer.close(); } if (enumerx != null) { enumerx.close(); } if (enumery != null) { enumery.close(); } } log.debug("[hasMonitoringEnabled] res=" + res + " metric:" + metric); return res; }
From source file:org.jasig.schedassist.impl.ldap.DefaultAttributesMapperImpl.java
/** * /*from www . j a va2 s . c om*/ * @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:org.jasig.schedassist.impl.oraclecalendar.OracleCalendarResourceAccountAttributesMapper.java
@Override public Object mapFromAttributes(Attributes attributes) throws NamingException { OracleCalendarResourceAccount user = new OracleCalendarResourceAccount(owner); 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 ww . j ava 2 s . c o m*/ } final String lcAttributeName = attributeName.toLowerCase(); attributesMap.put(lcAttributeName, value); if (RESOURCE_OWNER_USERNAME.equals(lcAttributeName)) { user.setAccountOwnerUsername(value); } else if (AbstractOracleCalendarAccount.CTCALXITEMID.equals(lcAttributeName)) { user.setCtcalxitemid(value); } else if (OracleLdapCalendarResourceAccountDaoImpl.CN.equals(lcAttributeName)) { user.setResourceName(value); } else if (OracleLdapCalendarResourceAccountDaoImpl.POSTALADDRESS.equals(lcAttributeName)) { user.setLocation(value); } else if (AbstractOracleCalendarAccount.WISCEDUCALEMAIL.equals(lcAttributeName)) { user.setEmailAddress(value); } } user.setAttributes(attributesMap); String contactInfo = buildContactInformation( getAttributeValue(attributes, OracleLdapCalendarResourceAccountDaoImpl.GIVENNAME), getAttributeValue(attributes, OracleLdapCalendarResourceAccountDaoImpl.SN), getAttributeValue(attributes, OracleLdapCalendarResourceAccountDaoImpl.TELEPHONENUMBER)); user.setContactInformation(contactInfo); String oracleGuid = this.oracleGUIDSource.getOracleGUID(user); user.setOracleGuid(oracleGuid); user.getAttributes().put(AbstractOracleCalendarAccount.ORACLE_GUID_ATTRIBUTE, oracleGuid); return user; }
From source file:hsa.awp.common.naming.DirectoryTest.java
/** * Checks if the content of the Attributes and Properties is equal. In * properties it assumes the mapping from ldap names to our names. * * @param attributes Ldap Attribtues// w w w .ja v a2 s . c o m * @param properties Properties returned from Directory * @return True if they are equal, otherwise false * @throws Exception If someone went wron. */ private boolean isEqual(Attributes attributes, Properties properties) throws Exception { if (attributes.size() != properties.size()) { return false; } NamingEnumeration<String> attribIds = attributes.getIDs(); while (attribIds.hasMoreElements()) { String curAttribId = attribIds.nextElement(); String currentAttribValue = (String) attributes.get(curAttribId).get(); String currentPropertyId = (String) directory.getClass().getField(mapping.getProperty(curAttribId)) .get(""); String currentPropertyValue = properties.getProperty(currentPropertyId); if (!currentAttribValue.equals(currentPropertyValue)) { return false; } } return true; }
From source file:edu.vt.middleware.ldap.ssl.DefaultHostnameVerifier.java
/** * Returns the CNs from the supplied certificate. * * @param cert to get CNs from//from w w w . j ava2s . com * * @return CNs */ private String[] getCNs(final X509Certificate cert) { final List<String> names = new ArrayList<String>(); final String subjectPrincipal = cert.getSubjectX500Principal().toString(); if (subjectPrincipal != null) { try { final LdapName subjectDn = new LdapName(subjectPrincipal); for (Rdn rdn : subjectDn.getRdns()) { final Attributes attrs = rdn.toAttributes(); final NamingEnumeration<String> ids = attrs.getIDs(); while (ids.hasMore()) { final String id = ids.next(); if (id.toLowerCase().equals("cn") || id.toLowerCase().equals("commonname") || id.toLowerCase().equals("2.5.4.3")) { final Object value = attrs.get(id).get(); if (value != null) { if (value instanceof String) { names.add((String) value); } else if (value instanceof Attribute) { // for multi value RDNs the first value is used final Object multiValue = ((Attribute) value).get(); if (multiValue != null && multiValue instanceof String) { names.add((String) multiValue); } } } } } } } catch (NamingException e) { if (this.logger.isWarnEnabled()) { this.logger.warn("Could not get distinguished name from subject " + subjectPrincipal, e); } } } return names.toArray(new String[names.size()]); }
From source file:com.evolveum.midpoint.model.common.expression.functions.BasicExpressionFunctions.java
public String determineLdapSingleAttributeValue(String dn, String attributeName, Collection<?> values) throws NamingException { if (values == null || values.isEmpty()) { return null; }//from ww w. j a v a2s .c o m Collection<String> stringValues = null; // Determine item type, try to convert to strings Object firstElement = values.iterator().next(); if (firstElement instanceof String) { stringValues = (Collection) values; } else if (firstElement instanceof Element) { stringValues = new ArrayList<String>(values.size()); for (Object value : values) { Element element = (Element) value; stringValues.add(element.getTextContent()); } } else { throw new IllegalArgumentException("Unexpected value type " + firstElement.getClass()); } if (stringValues.size() == 1) { return stringValues.iterator().next(); } if (StringUtils.isBlank(dn)) { throw new IllegalArgumentException( "No dn argument specified, cannot determine which of " + values.size() + " values to use"); } LdapName parsedDn = new LdapName(dn); for (int i = 0; i < parsedDn.size(); i++) { Rdn rdn = parsedDn.getRdn(i); Attributes rdnAttributes = rdn.toAttributes(); NamingEnumeration<String> rdnIDs = rdnAttributes.getIDs(); while (rdnIDs.hasMore()) { String rdnID = rdnIDs.next(); Attribute attribute = rdnAttributes.get(rdnID); if (attributeName.equals(attribute.getID())) { for (int j = 0; j < attribute.size(); j++) { Object value = attribute.get(j); if (stringValues.contains(value)) { return (String) value; } } } } } // Fallback. No values in DN. Just return the first alphabetically-wise value. return Collections.min(stringValues); }
From source file:org.nuxeo.wizard.RouterServlet.java
public void handleUserPOST(Page currentPage, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Context ctx = Context.instance(req); ParamCollector collector = ctx.getCollector(); String refreshParam = req.getParameter("refresh"); String directoryType = collector.getConfigurationParam("nuxeo.directory.type"); if ("true".equals(refreshParam)) { currentPage.dispatchToJSP(req, resp); return;//from w ww. java 2s .c o m } if ("checkNetwork".equals(refreshParam) || "checkAuth".equals(refreshParam) || "checkUserLdapParam".equals(refreshParam) || "checkGroupLdapParam".equals(refreshParam)) { try { if ("checkNetwork".equals(refreshParam)) { bindLdapConnection(collector, false); ctx.trackInfo("nuxeo.ldap.url", "info.host.found"); } else if ("checkAuth".equals(refreshParam)) { bindLdapConnection(collector, true); ctx.trackInfo("nuxeo.ldap.auth", "info.auth.success"); } else { DirContext dirContext = new InitialDirContext(getContextEnv(collector, true)); String searchScope; String searchBaseDn; String searchClass; String searchFilter; if ("checkUserLdapParam".equals(refreshParam)) { searchBaseDn = collector.getConfigurationParam("nuxeo.ldap.user.searchBaseDn"); searchScope = collector.getConfigurationParam("nuxeo.ldap.user.searchScope"); searchClass = collector.getConfigurationParam("nuxeo.ldap.user.searchClass"); searchFilter = collector.getConfigurationParam("nuxeo.ldap.user.searchFilter"); } else { searchBaseDn = collector.getConfigurationParam("nuxeo.ldap.group.searchBaseDn"); searchScope = collector.getConfigurationParam("nuxeo.ldap.group.searchScope"); searchFilter = collector.getConfigurationParam("nuxeo.ldap.group.searchFilter"); searchClass = ""; } SearchControls scts = new SearchControls(); if ("onelevel".equals(searchScope)) { scts.setSearchScope(SearchControls.ONELEVEL_SCOPE); } else { scts.setSearchScope(SearchControls.SUBTREE_SCOPE); } String filter = String.format("(&(%s)(objectClass=%s))", searchFilter.isEmpty() ? "objectClass=*" : searchFilter, searchClass.isEmpty() ? "*" : searchClass); NamingEnumeration<SearchResult> results; try { results = dirContext.search(searchBaseDn, filter, scts); if (!results.hasMore()) { ctx.trackError("nuxeo.ldap.search", "error.ldap.noresult"); } else { SearchResult result = results.next(); if (searchBaseDn.equalsIgnoreCase(result.getNameInNamespace()) && results.hasMore()) { // try not to display the root of the search // base DN result = results.next(); } ctx.trackInfo("dn", result.getNameInNamespace()); Attributes attributes = result.getAttributes(); NamingEnumeration<String> ids = attributes.getIDs(); String id; StringBuilder sb; while (ids.hasMore()) { id = ids.next(); NamingEnumeration<?> values = attributes.get(id).getAll(); sb = new StringBuilder(); while (values.hasMore()) { sb.append(values.next()).append(" , "); } ctx.trackInfo(id, sb.substring(0, sb.length() - 3)); } } } catch (NameNotFoundException e) { ctx.trackError("nuxeo.ldap.search", "error.ldap.searchBaseDn"); log.warn(e); } dirContext.close(); } } catch (AuthenticationException e) { ctx.trackError("nuxeo.ldap.auth", "error.auth.failed"); log.warn(e); } catch (NamingException e) { ctx.trackError("nuxeo.ldap.url", "error.host.not.found"); log.warn(e); } } // Form submit if (!"default".equals(directoryType) && refreshParam.isEmpty()) { // first check bind to LDAP server try { bindLdapConnection(collector, true); } catch (NamingException e) { ctx.trackError("nuxeo.ldap.auth", "error.ldap.bind.failed"); log.warn(e); } // then check mandatory fields if (collector.getConfigurationParam("nuxeo.ldap.user.searchBaseDn").isEmpty()) { ctx.trackError("nuxeo.ldap.user.searchBaseDn", "error.user.searchBaseDn.required"); } if (collector.getConfigurationParam("nuxeo.ldap.user.mapping.rdn").isEmpty()) { ctx.trackError("nuxeo.ldap.user.mapping.rdn", "error.user.rdn.required"); } if (collector.getConfigurationParam("nuxeo.ldap.user.mapping.username").isEmpty()) { ctx.trackError("nuxeo.ldap.user.mapping.username", "error.user.username.required"); } if (collector.getConfigurationParam("nuxeo.ldap.user.mapping.password").isEmpty()) { ctx.trackError("nuxeo.ldap.user.mapping.password", "error.user.password.required"); } if (collector.getConfigurationParam("nuxeo.ldap.user.mapping.firstname").isEmpty()) { ctx.trackError("nuxeo.ldap.user.mapping.firstname", "error.user.firstname.required"); } if (collector.getConfigurationParam("nuxeo.ldap.user.mapping.lastname").isEmpty()) { ctx.trackError("nuxeo.ldap.user.mapping.lastname", "error.user.lastname.required"); } String userGroupStorage = collector.getConfigurationParam("nuxeo.user.group.storage"); if (!"userLdapOnly".equals(userGroupStorage) && !"multiUserSqlGroup".equals(userGroupStorage)) { if (collector.getConfigurationParam("nuxeo.ldap.group.searchBaseDn").isEmpty()) { ctx.trackError("nuxeo.ldap.group.searchBaseDn", "error.group.searchBaseDn.required"); } if (collector.getConfigurationParam("nuxeo.ldap.group.mapping.rdn").isEmpty()) { ctx.trackError("nuxeo.ldap.group.mapping.rdn", "error.group.rdn.required"); } if (collector.getConfigurationParam("nuxeo.ldap.group.mapping.name").isEmpty()) { ctx.trackError("nuxeo.ldap.group.mapping.name", "error.group.name.required"); } } if ("true".equals(collector.getConfigurationParam("nuxeo.user.emergency.enable"))) { if (collector.getConfigurationParam("nuxeo.user.emergency.username").isEmpty()) { ctx.trackError("nuxeo.user.emergency.username", "error.emergency.username.required"); } if (collector.getConfigurationParam("nuxeo.user.emergency.password").isEmpty()) { ctx.trackError("nuxeo.user.emergency.password", "error.emergency.password.required"); } } } if (ctx.hasErrors() || ctx.hasInfos()) { currentPage.dispatchToJSP(req, resp); } else { currentPage.next().dispatchToJSP(req, resp, true); } }