Search code examples
javaspringactive-directoryldapvaadin7

Vaadin and Spring, authentication against Active Directory via LDAP


I am trying to authenticate against AD in my application created with Vaadin, which is using also Spring (SpringVaadinIntegration).

I can't find any information about how to achieve this and a lot of confusing, different and partial ways to connect to Active Directory with Spring security. Since Vaadin form fields don't have a name, I don't know if I can even use a normal form or I have to write my own JSP. My impression is that to map the username and the password entered in the form to the xml it's necessary that the fields have a name.

Has anybody achieved this or anybody has a clue on how to do it?

If somebody can provide a link where this is explained step by step, for dummies, would be great too. I just can find partial solutions, where you don't get an overall of the system and how should be configured.


Solution

  • We have a TextField (username), a PasswordField (password) and a Button on a UI:

    public class MyUI extends UI {
        @Override
        protected void init( VaadinRequest request ) {
            setContent( VaadinSession.getCurrent().getAttribute("userId") == null ? getNewLoginLayout() : getNewMainLayout() );
        }
        private VerticalLayout getNewLoginLayout() {
            TextField username = ...
            TextField password = ...
            Button login = ...
            return new VerticalLayout(username, password, login);
        }
    }
    

    When the button pushed we do a simple LDAP search like this on the server side (for example pass these parameters to a Spring bean). If it is successful we set a VaadinSession attribute (userId) and change the UI content to the main layout. Spring security need not necessarily.