Hi all,
I am stuck with an AD authentication issue. the scenario is like this
I have two AD services running on two different servers in two domains viz
server1.domain1.com and
server2.domain2.com
We have a web service on a machine in server1 domain, that can access server1's AD service.
Now , access to server2 AD service is not granted to machines outside the domain. so the web service, cannot access the AD service of server2. we plan to hit server2 AD through server1's AD. How do i replicate this in code in
java. I have already coded the first part of accessing server1's AD and can successfully authenticate a user in server1 domain. how do i connect to server2 AD from server1. What configurations do i need to do in code as well as on the server to support this?
String getUsername="abcd";
String searchBase = "dc=domain1,dc=domain2";
Hashtable environment = new Hashtable();
environment.put(LdapContext.CONTROL_FACTORIES, "com.sun.jndi.ldap.ControlFactory ");
System.out.println("one");
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
System.out.println("two");
environment.put(Context.PROVIDER_URL, "ldap://server1.domain1.com:xxx" );
System.out.println("three");
environment.put(Context.SECURITY_AUTHENTICATION, "simple");
System.out.println("four");
environment.put(Context.SECURITY_PRINCIPAL, "domain1" );
System.out.println("five");
environment.put(Context.SECURITY_CREDENTIALS, "password");
System.out.println("six");
environment.put(Context.STATE_FACTORIES, "PersonStateFactory");
System.out.println("seven");
environment.put(Context.OBJECT_FACTORIES, "PersonObjectFactory");
System.out.println("eight");
try
{
System.out.println("nine");
DirContext ctx = new InitialDirContext(environment);
System.out.println("ten");
String FILTER = "(&(objectClass=Person) ((sAMAccountName=" + getUsername + ")))";
System.out.println("eleven");
SearchControls ctls = new SearchControls();
System.out.println("twelve");
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
System.out.println("thirteen");
NamingEnumeration answer = ctx.search(searchBase, FILTER, ctls);
System.out.println("fourteen");
//SearchResult sr = (SearchResult) answer.next();
How do i extend this to access server2's AD from server1 internally