List of usage examples for javax.naming.directory Attributes get
Attribute get(String attrID);
From source file:org.apache.roller.weblogger.ui.core.security.CustomUserRegistry.java
private static String getLdapAttribute(Attributes attributes, String name) { if (attributes == null) { return null; }/* w w w. j a va 2s . c om*/ Attribute attribute = attributes.get(name); if (attribute == null) { return null; } Object oValue = null; try { oValue = attribute.get(); } catch (NamingException e) { return null; } if (oValue == null) { return null; } return oValue.toString(); }
From source file:org.projectforge.business.ldap.LdapUtils.java
public static Attribute putAttribute(final Attributes attributes, final String attrId, final String attrValue) { final Attribute attr = attributes.get(attrId); if (attrValue == null) { return attr; }/*from w w w . j av a 2 s.c om*/ if (attr == null) { return attributes.put(attrId, attrValue); } attr.add(attrValue); return attr; }
From source file:org.projectforge.business.ldap.LdapUtils.java
public static Object getAttributeValue(final Attributes attributes, final String attrId) throws NamingException { final Attribute attr = attributes.get(attrId); if (attr == null) { return null; }/*from ww w . j ava 2s. co m*/ return attr.get(); }
From source file:org.projectforge.business.ldap.LdapUtils.java
public static String getAttributeStringValue(final Attributes attributes, final String attrId) throws NamingException { final Attribute attr = attributes.get(attrId); if (attr == null) { return null; }//from w w w . ja v a2 s . c om return (String) attr.get(); }
From source file:org.projectforge.business.ldap.LdapUtils.java
public static Integer getAttributeIntegerValue(final Attributes attributes, final String attrId) throws NamingException { final Attribute attr = attributes.get(attrId); if (attr == null) { return null; }//from www . j ava 2 s . c o m return (Integer) attr.get(); }
From source file:com.newrelic.agent.deps.org.apache.http.conn.ssl.DefaultHostnameVerifier.java
static String extractCN(final String subjectPrincipal) throws SSLException { if (subjectPrincipal == null) { return null; }//from w w w. ja v a 2 s .c om try { final LdapName subjectDN = new LdapName(subjectPrincipal); final List<Rdn> rdns = subjectDN.getRdns(); for (int i = rdns.size() - 1; i >= 0; i--) { final Rdn rds = rdns.get(i); final Attributes attributes = rds.toAttributes(); final Attribute cn = attributes.get("cn"); if (cn != null) { try { final Object value = cn.get(); if (value != null) { return value.toString(); } } catch (NoSuchElementException ignore) { } catch (NamingException ignore) { } } } return null; } catch (InvalidNameException e) { throw new SSLException(subjectPrincipal + " is not a valid X500 distinguished name"); } }
From source file:org.projectforge.business.ldap.LdapUtils.java
public static String[] getAttributeStringValues(final Attributes attributes, final String attrId) throws NamingException { final Attribute attr = attributes.get(attrId); if (attr == null) { return null; }/*from w w w. ja v a2 s .co m*/ final NamingEnumeration<?> enumeration = attr.getAll(); final List<String> list = new ArrayList<String>(); while (enumeration.hasMore() == true) { final Object attrValue = enumeration.next(); if (attrValue == null) { list.add(null); } list.add(String.valueOf(attrValue)); } return list.toArray(new String[list.size()]); }
From source file:org.jkcsoft.java.util.JndiHelper.java
private static void loadMap(Map info, Attributes userLdapAttrs, String key) throws NamingException { Attribute attribute = userLdapAttrs.get(key); Object value = null;// w ww . j ava 2s .c o m if (attribute != null) { value = attribute.get().toString(); } else { log.warn("Null value of AD param [" + key + "]"); } info.put(key, value); }
From source file:eu.europa.ec.markt.dss.validation.crl.OnlineCRLSource.java
/** * Downloads a CRL from given LDAP url, e.g. ldap://ldap.infonotary.com/dc=identity-ca,dc=infonotary,dc=com * * @throws CertificateException//from w ww . j av a 2 s . c o m * @throws CRLException */ private static X509CRL downloadCRLFromLDAP_(final String ldapURL) throws DSSException { final Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapURL); try { final DirContext ctx = new InitialDirContext(env); final Attributes attributes = ctx.getAttributes(""); final javax.naming.directory.Attribute attribute = attributes.get("certificateRevocationList;binary"); final byte[] val = (byte[]) attribute.get(); if (val == null || val.length == 0) { throw new DSSException("Can not download CRL from: " + ldapURL); } final InputStream inStream = new ByteArrayInputStream(val); return DSSUtils.loadCRL(inStream); } catch (Exception e) { LOG.warning(e.getMessage()); e.printStackTrace(); } return null; }
From source file:org.pentaho.di.trans.steps.mailvalidator.MailValidation.java
/** * verify if there is a mail server registered to the domain name. and return the email servers count *///ww w .j a v a2s . co m public static int mailServersCount(String hostName) throws NamingException { Hashtable<String, String> env = new Hashtable<String, String>(); env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); DirContext ictx = new InitialDirContext(env); Attributes attrs = ictx.getAttributes(hostName, new String[] { "MX" }); Attribute attr = attrs.get("MX"); if (attr == null) { return (0); } return (attr.size()); }