List of usage examples for javax.naming.directory Attribute get
Object get(int ix) throws NamingException;
From source file:org.springframework.ldap.support.LdapUtils.java
/** * Iterate through all the values of the specified Attribute calling back to * the specified callbackHandler.//from w w w .ja v a2 s . c o m * @param attribute the Attribute to work with; not <code>null</code>. * @param callbackHandler the callbackHandler; not <code>null</code>. * @since 1.3 */ public static void iterateAttributeValues(Attribute attribute, AttributeValueCallbackHandler callbackHandler) { Assert.notNull(attribute, "Attribute must not be null"); Assert.notNull(callbackHandler, "callbackHandler must not be null"); for (int i = 0; i < attribute.size(); i++) { try { callbackHandler.handleAttributeValue(attribute.getID(), attribute.get(i), i); } catch (javax.naming.NamingException e) { throw LdapUtils.convertLdapException(e); } } }
From source file:it.infn.ct.security.utilities.LDAPUtils.java
public static List<LDAPUser> getIdPUserList() { List<LDAPUser> users = new ArrayList<LDAPUser>(); NamingEnumeration results = null; DirContext ctx;// w w w. j a v a 2 s .c o m ResourceBundle rb = ResourceBundle.getBundle("ldap"); try { ctx = getMainAuthContext(); String attrs[] = { "uniqueMember" }; Attribute userGAttr = ctx.getAttributes(rb.getString("usersGroup"), attrs).get("uniqueMember"); for (int i = 0; i < userGAttr.size(); i++) { String userDN = (String) userGAttr.get(i); users.add(getUser(userDN.substring(userDN.indexOf("=") + 1, userDN.indexOf(",")))); } } catch (NamingException ex) { _log.error(ex); } return users; }
From source file:net.spfbl.core.Reverse.java
public static ArrayList<String> getMXSet(String host) throws NamingException { TreeMap<Integer, TreeSet<String>> mxMap = new TreeMap<Integer, TreeSet<String>>(); Attributes atributes = Server.getAttributesDNS(host, new String[] { "MX" }); if (atributes == null || atributes.size() == 0) { atributes = Server.getAttributesDNS(host, new String[] { "CNAME" }); Attribute attribute = atributes.get("CNAME"); if (attribute != null) { String cname = (String) attribute.get(0); return getMXSet(cname); }/*from w ww . j a va 2 s. c om*/ } else { Attribute attribute = atributes.get("MX"); if (attribute != null) { for (int index = 0; index < attribute.size(); index++) { try { String mx = (String) attribute.get(index); int space = mx.indexOf(' '); String value = mx.substring(0, space); int priority = Integer.parseInt(value); mx = mx.substring(space + 1); int last = mx.length() - 1; TreeSet<String> mxSet = mxMap.get(priority); if (mxSet == null) { mxSet = new TreeSet<String>(); mxMap.put(priority, mxSet); } if (Subnet.isValidIP(mx.substring(0, last))) { mxSet.add(Subnet.normalizeIP(mx.substring(0, last))); } else if (Domain.isHostname(mx)) { mxSet.add(Domain.normalizeHostname(mx, true)); } } catch (NumberFormatException ex) { } } } } ArrayList<String> mxList = new ArrayList<String>(); if (mxMap.isEmpty()) { // https://tools.ietf.org/html/rfc5321#section-5 mxList.add(Domain.normalizeHostname(host, true)); } else { for (int priority : mxMap.keySet()) { TreeSet<String> mxSet = mxMap.get(priority); for (String mx : mxSet) { if (!mxList.contains(mx)) { mxList.add(mx); } } } } return mxList; }
From source file:net.spfbl.core.Reverse.java
private static TreeSet<String> getIPv4Set(String host) throws NamingException { TreeSet<String> ipSet = new TreeSet<String>(); Attributes atributes = Server.getAttributesDNS(host, new String[] { "A" }); if (atributes != null) { Attribute attribute = atributes.get("A"); if (attribute != null) { for (int index = 0; index < attribute.size(); index++) { String ip = (String) attribute.get(index); if (SubnetIPv4.isValidIPv4(ip)) { ip = SubnetIPv4.normalizeIPv4(ip); ipSet.add(ip);//from w w w . j av a2 s .c om } } } } return ipSet; }
From source file:net.spfbl.core.Reverse.java
private static TreeSet<String> getIPv6Set(String host) throws NamingException { TreeSet<String> ipSet = new TreeSet<String>(); Attributes atributes = Server.getAttributesDNS(host, new String[] { "AAAA" }); if (atributes != null) { Attribute attribute = atributes.get("AAAA"); if (attribute != null) { for (int index = 0; index < attribute.size(); index++) { String ip = (String) attribute.get(index); if (SubnetIPv6.isValidIPv6(ip)) { ip = SubnetIPv6.normalizeIPv6(ip); ipSet.add(ip);/*from www . ja va 2 s.c om*/ } } } } return ipSet; }
From source file:net.spfbl.core.Reverse.java
public static TreeSet<String> getPointerSet(String host) throws NamingException { if (host == null) { return null; } else {//from w ww . ja v a 2s .c o m TreeSet<String> reverseSet = new TreeSet<String>(); if (Subnet.isValidIP(host)) { if (SubnetIPv4.isValidIPv4(host)) { host = getHostReverse(host, "in-addr.arpa"); } else if (SubnetIPv6.isValidIPv6(host)) { host = getHostReverse(host, "ip6.arpa"); } } Attributes atributes = Server.getAttributesDNS(host, new String[] { "PTR" }); if (atributes != null) { Attribute attribute = atributes.get("PTR"); if (attribute != null) { for (int index = 0; index < attribute.size(); index++) { host = (String) attribute.get(index); if (host != null) { host = host.trim(); if (host.endsWith(".")) { int endIndex = host.length() - 1; host = host.substring(0, endIndex); } if (Domain.isHostname(host)) { host = Domain.normalizeHostname(host, true); reverseSet.add(host); } } } } } return reverseSet; } }
From source file:fedora.server.security.servletfilters.ldap.FilterLdap.java
private static Boolean comparePassword(Attributes attributes, String password, String passwordAttribute) throws PasswordComparisonException { String m = "- comparePassword() "; log.debug(m + ">"); Boolean rc = null;/*from w ww. j av a 2 s .c om*/ try { log.debug(m + "looking for return attribute==" + passwordAttribute); Attribute attribute = attributes.get(passwordAttribute); if (attribute == null) { log.error(m + "null object"); } else { int size = attribute.size(); log.debug(m + "object with n==" + size); for (int j = 0; j < size; j++) { Object o = attribute.get(j); if (password.equals(o.toString())) { log.debug(m + "compares true"); if (rc == null) { log.debug(m + "1st comp: authenticate"); rc = Boolean.TRUE; } else { log.error(m + "dup comp: keep previous rc==" + rc); } } else { log.debug(m + "compares false, -un-authenticate"); if (rc == null) { log.debug(m + "1st comp (fyi)"); } else { log.error(m + "dup comp (fyi)"); } rc = Boolean.FALSE; } } } } catch (Throwable th) { log.error(m + "resetting to null rc==" + rc + th.getMessage()); throw new PasswordComparisonException("in ldap servlet filter", th); } finally { log.debug(m + "< " + rc); } return rc; }
From source file:no.smint.anthropos.ldap.PersonAttributesMapper.java
public Person mapFromAttributes(Attributes attributes) throws NamingException { Person person = new Person(); person.setUidNumber(Long.valueOf((String) attributes.get("uidNumber").get())); person.setGivenName(attributes.get("givenName") != null ? (String) attributes.get("givenName").get() : ""); person.setSn(attributes.get("sn") != null ? (String) attributes.get("sn").get() : ""); person.setCn(attributes.get("cn") != null ? (String) attributes.get("cn").get() : ""); person.setUid(attributes.get("uid") != null ? (String) attributes.get("uid").get() : ""); person.setMail(attributes.get("mail") != null ? (String) attributes.get("mail").get() : ""); person.setTelephoneNumber(// ww w .j a v a2s .c om attributes.get("telephoneNumber") != null ? (String) attributes.get("telephoneNumber").get() : ""); Attribute memberOfAtt = attributes.get("memberOf"); if (memberOfAtt != null) { ArrayList<String> memberOf = new ArrayList<String>(); for (int i = 0; i < memberOfAtt.size(); i++) { memberOf.add((String) memberOfAtt.get(i)); } person.setMemberOf(memberOf); } return person; }
From source file:org.jasig.schedassist.impl.ldap.DefaultAttributesMapperImpl.java
/** * /* w w w . ja v a2 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:ldap.Entry.java
/** * Utility method to get as a String all the attribute values * of a particular attribute.//from www . j a va 2 s . c om * @param attributeName * @return null if attribute does not exist, an array of string values otherwise. * @throws NamingException */ public String[] getValues(String attributeName) throws NamingException { Attribute att = get(attributeName); if (att == null) return null; String[] returnVals = new String[att.size()]; for (int i = 0; i < att.size(); i++) returnVals[i] = att.get(i).toString(); return returnVals; }