Announcement Announcement Module
Collapse
No announcement yet.
Spring LDAP Authentication (automated or not?) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring LDAP Authentication (automated or not?)

    I read through the Spring LDAP reference docs[*] and was unable to figure out whether user authentication against the LDAP server is automated or not.

    By "automated" I mean that it happens automatically on bean instantiation if you provide userDn and password in your ContextSource. That is to say, the programmer never has to call LdapTemplate.authenticate(...) - it happens "behind-the-scenes".

    So I would like to know

    (1) If Spring LDAP authentication is automatic
    (2) If there are fields I can set to change this behavior

    Thanks,
    ktm

    [*] http://static.springsource.org/sprin...ntication.html

  • #2
    I ask this because I have to do an authentication at runtime, since I get the userDn and password at runtime. Will the following code work?

    Code:
    public class RuntimeContext extends LdapContextSource {
    	
    	public RuntimeContext() {
    		super();
    		if (!resolveAuthInfo()) {
    			System.out.println("Failed to resolve auth info. Exiting...");
    			System.exit(1);
    		}
    	}
    	
    	public boolean resolveAuthInfo()
    	{
    		String myUserDn, myPassword;
    		try {
    			BufferedReader br = new BufferedReader(
    					new InputStreamReader(System.in));
    			System.out.print("userDn: ");
    			myUserDn = br.readLine();
    			System.out.print("password: ");
    			myPassword = br.readLine();
    		} catch (IOException e) {
    			return false;
    		}
    		super.setUserDn(myUserDn);
    		super.setPassword(myPassword);
    		return true;
    	}
    
    }
    My RuntimeContext is instantiated through a bean... but I figure, before it actually authenticates (does the BIND call to the LDAP server), it has to run my code, and my code will set the proper userDn/password for authentication.

    EDIT: I believe it does work. I tested it by removing the url property from the beans file, and configuring it instead with a setUrl call in the above code (specifically, in resolveAuthInfo, so that it is executed in the constructor). The app still works and does the lookup successfully.
    Last edited by ktm5124; Jan 25th, 2011, 01:39 PM.

    Comment

    Working...
    X