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) {
}
}
}
}
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);
}
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));
}
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;
}
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;
}
Aggregations