Search in sources :

Example 91 with Attributes

use of javax.naming.directory.Attributes in project BiglyBT by BiglySoftware.

the class DNSUtilsImpl method getTXTRecord.

@Override
public String getTXTRecord(String query) throws UnknownHostException {
    DirContext context = null;
    try {
        context = getInitialDirContext().ctx;
        Attributes attrs = context.getAttributes(query, new String[] { "TXT" });
        NamingEnumeration n_enum = attrs.getAll();
        while (n_enum.hasMoreElements()) {
            Attribute attr = (Attribute) n_enum.next();
            NamingEnumeration n_enum2 = attr.getAll();
            while (n_enum2.hasMoreElements()) {
                String attribute = (String) n_enum2.nextElement();
                if (attribute != null) {
                    attribute = attribute.trim();
                    if (attribute.startsWith("\"")) {
                        attribute = attribute.substring(1);
                    }
                    if (attribute.endsWith("\"")) {
                        attribute = attribute.substring(0, attribute.length() - 1);
                    }
                    if (attribute.length() > 0) {
                        return (attribute);
                    }
                }
            }
        }
        throw (new UnknownHostException("DNS query returned no results"));
    } catch (Throwable e) {
        throw (new UnknownHostException("DNS query failed:" + Debug.getNestedExceptionMessage(e)));
    } finally {
        if (context != null) {
            try {
                context.close();
            } catch (Throwable e) {
            }
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) Attribute(javax.naming.directory.Attribute) Attributes(javax.naming.directory.Attributes) NamingEnumeration(javax.naming.NamingEnumeration) DirContext(javax.naming.directory.DirContext) InitialDirContext(javax.naming.directory.InitialDirContext)

Example 92 with Attributes

use of javax.naming.directory.Attributes in project BiglyBT by BiglySoftware.

the class DNSUtilsImpl method getTXTRecords.

@Override
public List<String> getTXTRecords(String query) {
    // System.out.println( "DNSTXTQuery: " + query );
    List<String> result = new ArrayList<>();
    String test_reply = test_records.get(query);
    if (test_reply != null) {
        result.add(test_reply);
        return (result);
    }
    DirContext context = null;
    try {
        context = getInitialDirContext().ctx;
        Attributes attrs = context.getAttributes(query, new String[] { "TXT" });
        NamingEnumeration n_enum = attrs.getAll();
        while (n_enum.hasMoreElements()) {
            Attribute attr = (Attribute) n_enum.next();
            NamingEnumeration n_enum2 = attr.getAll();
            while (n_enum2.hasMoreElements()) {
                String attribute = (String) n_enum2.nextElement();
                if (attribute != null) {
                    attribute = attribute.trim();
                    if (attribute.startsWith("\"")) {
                        attribute = attribute.substring(1);
                    }
                    if (attribute.endsWith("\"")) {
                        attribute = attribute.substring(0, attribute.length() - 1);
                    }
                    if (attribute.length() > 0) {
                        result.add(attribute);
                    }
                }
            }
        }
    } catch (Throwable e) {
    // e.printStackTrace();
    } finally {
        if (context != null) {
            try {
                context.close();
            } catch (Throwable e) {
            }
        }
    }
    return (result);
}
Also used : Attribute(javax.naming.directory.Attribute) Attributes(javax.naming.directory.Attributes) NamingEnumeration(javax.naming.NamingEnumeration) DirContext(javax.naming.directory.DirContext) InitialDirContext(javax.naming.directory.InitialDirContext)

Example 93 with Attributes

use of javax.naming.directory.Attributes in project BiglyBT by BiglySoftware.

the class DNSUtilsImpl method getAllIPV6ByName.

public List<Inet6Address> getAllIPV6ByName(String host) throws UnknownHostException {
    List<Inet6Address> result = new ArrayList<>();
    try {
        DirContext context = getInitialDirContext().ctx;
        Attributes attrs = context.getAttributes(host, new String[] { "AAAA" });
        if (attrs != null) {
            Attribute attr = attrs.get("aaaa");
            if (attr != null) {
                NamingEnumeration values = attr.getAll();
                while (values.hasMore()) {
                    Object value = values.next();
                    if (value instanceof String) {
                        try {
                            result.add((Inet6Address) InetAddress.getByName((String) value));
                        } catch (Throwable e) {
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
    }
    if (result.size() > 0) {
        return (result);
    }
    throw (new UnknownHostException(host));
}
Also used : UnknownHostException(java.net.UnknownHostException) Attribute(javax.naming.directory.Attribute) Attributes(javax.naming.directory.Attributes) Inet6Address(java.net.Inet6Address) NamingEnumeration(javax.naming.NamingEnumeration) DirContext(javax.naming.directory.DirContext) InitialDirContext(javax.naming.directory.InitialDirContext)

Example 94 with Attributes

use of javax.naming.directory.Attributes in project camunda-bpm-platform by camunda.

the class LdapIdentityProviderSession method transformGroup.

protected GroupEntity transformGroup(SearchResult result) throws NamingException {
    final Attributes attributes = result.getAttributes();
    LdapGroupEntity group = new LdapGroupEntity();
    group.setDn(result.getNameInNamespace());
    group.setId(getStringAttributeValue(ldapConfiguration.getGroupIdAttribute(), attributes));
    group.setName(getStringAttributeValue(ldapConfiguration.getGroupNameAttribute(), attributes));
    group.setType(getStringAttributeValue(ldapConfiguration.getGroupTypeAttribute(), attributes));
    return group;
}
Also used : Attributes(javax.naming.directory.Attributes)

Example 95 with Attributes

use of javax.naming.directory.Attributes in project trainning by fernandotomasio.

the class LDAPNetworkUserDAO method buildAttributes.

private Attributes buildAttributes(final NetworkUserDTO user) {
    Attributes attrs = new BasicAttributes();
    BasicAttribute ocattr = new BasicAttribute("objectclass");
    ocattr.add("inetOrgPerson");
    attrs.put(ocattr);
    attrs.put("sn", user.getNomeGuerra());
    attrs.put("uid", user.getLogin());
    attrs.put("cn", user.getNome());
    if (user.getPassword() != null) {
        if (user.getPassword().contains("{SHA}")) {
            attrs.put("userPassword", user.getPassword());
        } else {
            attrs.put("userPassword", "{SHA}" + encrypt(user.getPassword()));
        }
    }
    attrs.put("mail", user.getEmail());
    attrs.put("title", user.getPosto());
    attrs.put("o", user.getOrganizacao());
    attrs.put("telephoneNumber", user.getTelefone());
    attrs.put("givenName", user.getTarjeta());
    if (user.getPhoto() != null) {
        attrs.put("jpegPhoto", user.getPhoto());
    }
    return attrs;
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes)

Aggregations

Attributes (javax.naming.directory.Attributes)252 Attribute (javax.naming.directory.Attribute)135 SearchResult (javax.naming.directory.SearchResult)87 NamingException (javax.naming.NamingException)84 BasicAttributes (javax.naming.directory.BasicAttributes)72 ArrayList (java.util.ArrayList)61 BasicAttribute (javax.naming.directory.BasicAttribute)56 SearchControls (javax.naming.directory.SearchControls)55 DirContext (javax.naming.directory.DirContext)49 NamingEnumeration (javax.naming.NamingEnumeration)44 Test (org.junit.Test)34 InitialDirContext (javax.naming.directory.InitialDirContext)32 LdapContext (javax.naming.ldap.LdapContext)29 HashMap (java.util.HashMap)25 InitialLdapContext (javax.naming.ldap.InitialLdapContext)24 Hashtable (java.util.Hashtable)20 HashSet (java.util.HashSet)18 Map (java.util.Map)17 IOException (java.io.IOException)16 Identity (org.olat.core.id.Identity)16