@Override public Attributes getAttributes(String name) throws NamingException { return delegating.getAttributes(name); }
@Override public Attributes getAttributes(String name, String[] attrIds) throws NamingException { return delegating.getAttributes(name, attrIds); }
@Override public Attributes getAttributes(Name name) throws NamingException { return delegating.getAttributes(name); }
@Override public Attributes getAttributes(Name name, String[] attrIds) throws NamingException { return delegating.getAttributes(name, attrIds); }
protected boolean isContextAlive() { boolean alive = false; if (context != null) { try { context.getAttributes(""); alive = true; } catch (Exception e) { } } return alive; }
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(domainName, new String[] {"MX"}); Attribute attr = attrs.get("MX"); if (attr == null) // No MX record else // If attr.size() > 0, there is an MX record
/** * verify if there is a mail server registered to the domain name. and return the email servers count */ 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() ); }
public Object executeWithContext(DirContext ctx) throws NamingException { try { Attributes attrs = ctx.getAttributes(dn, attributesToRetrieve); return new DirContextAdapter(attrs, LdapUtils.getFullDn(dn, ctx)); } catch (NameNotFoundException notFound) { throw new UsernameNotFoundException( "User " + username + " not found", notFound); } } });
private Attribute lookup(String query, DirContext ictx, String recordType) { try { Attributes dnsResult = ictx.getAttributes(query, new String[] { recordType }); return dnsResult.get(recordType); } catch (NamingException e) { if (e instanceof NameNotFoundException) { throw new DnsEntryNotFoundException("DNS entry not found for:" + query, e); } throw new DnsLookupException("DNS lookup failed for: " + query, e); } }
@Override public Attributes getAttributes(Name name) throws NamingException { Assert.checkNotNullParam("name", name); final ReparsedName reparsedName = reparse(name); ContextResult result = getProviderContext(reparsedName.getUrlScheme()); if(result.oldStyle) { return ((DirContext)result.context).getAttributes(name); } else { return ((DirContext)result.context).getAttributes(reparsedName.getName()); } }
@Override public Attributes getAttributes(Name name, String[] attrIds) throws NamingException { Assert.checkNotNullParam("name", name); final ReparsedName reparsedName = reparse(name); ContextResult result = getProviderContext(reparsedName.getUrlScheme()); if(result.oldStyle) { return ((DirContext)result.context).getAttributes(name, attrIds); } else { return ((DirContext)result.context).getAttributes(reparsedName.getName(), attrIds); } }
@Test(expected = DnsLookupException.class) public void testUnknowError() throws Exception { when(context.getAttributes(any(String.class), any(String[].class))).thenThrow( new NamingException("error")); dnsResolver.resolveIpAddress(""); }
@Override public Attributes getAttributes(String name) throws NamingException { Assert.checkNotNullParam("name", name); final ReparsedName reparsedName = reparse(getNameParser().parse(name)); ContextResult result = getProviderContext(reparsedName.getUrlScheme()); if(result.oldStyle) { return ((DirContext)result.context).getAttributes(name); } else { return ((DirContext)result.context).getAttributes(reparsedName.getName()); } }
@Override public Attributes getAttributes(String name, String[] attrIds) throws NamingException { Assert.checkNotNullParam("name", name); final ReparsedName reparsedName = reparse(getNameParser().parse(name)); ContextResult result = getProviderContext(reparsedName.getUrlScheme()); if(result.oldStyle) { return ((DirContext)result.context).getAttributes(name, attrIds); } else { return ((DirContext)result.context).getAttributes(reparsedName.getName(), attrIds); } }
@Test public void testResolveServiceIpAddress() throws Exception { BasicAttributes srvRecords = createSrvRecords(); BasicAttributes aRecords = new BasicAttributes("A", "63.246.7.80"); when(context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })) .thenReturn(srvRecords); when(context.getAttributes("kdc.springsource.com", new String[] { "A" })) .thenReturn(aRecords); String ipAddress = dnsResolver .resolveServiceIpAddress("ldap", "springsource.com"); assertThat(ipAddress).isEqualTo("63.246.7.80"); }
@Test public void testResolveServiceEntry() throws Exception { BasicAttributes records = createSrvRecords(); when(context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })) .thenReturn(records); String hostname = dnsResolver.resolveServiceEntry("ldap", "springsource.com"); assertThat(hostname).isEqualTo("kdc.springsource.com"); }
@Test public void testResolveIpAddress() throws Exception { Attributes records = new BasicAttributes("A", "63.246.7.80"); when(context.getAttributes("www.springsource.com", new String[] { "A" })) .thenReturn(records); String ipAddress = dnsResolver.resolveIpAddress("www.springsource.com"); assertThat(ipAddress).isEqualTo("63.246.7.80"); }
@Test(expected = DnsEntryNotFoundException.class) public void testResolveServiceEntryNotExisting() throws Exception { when(context.getAttributes(any(String.class), any(String[].class))).thenThrow( new NameNotFoundException("not found")); dnsResolver.resolveServiceEntry("wrong", "secpod.de"); }
@Test(expected = DnsEntryNotFoundException.class) public void testResolveIpAddressNotExisting() throws Exception { when(context.getAttributes(any(String.class), any(String[].class))).thenThrow( new NameNotFoundException("not found")); dnsResolver.resolveIpAddress("notexisting.ansdansdugiuzgguzgioansdiandwq.foo"); }
public Object executeWithContext(DirContext ctx) throws NamingException { Attributes attrs = ctx.getAttributes(dn, attributesToRetrieve); // Object object = ctx.lookup(LdapUtils.getRelativeName(dn, ctx)); return new DirContextAdapter(attrs, new DistinguishedName(dn), new DistinguishedName(ctx.getNameInNamespace())); } });