Project

General

Profile

Download (1.77 KB) Statistics
| Branch: | Tag: | Revision:
1 29078af6 Andreas Kohlbecker
package eu.etaxonomy.cdm.vaadin.view;
2 ead0a1ab Cherian Mathew
3 93fcde18 Cherian Mathew
import java.net.URI;
4
5 ead0a1ab Cherian Mathew
import org.springframework.security.authentication.AuthenticationManager;
6
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
7
import org.springframework.security.core.Authentication;
8 dfe03eb9 Cherian Mathew
import org.springframework.security.core.context.SecurityContextHolder;
9 ead0a1ab Cherian Mathew
10 93fcde18 Cherian Mathew
import com.vaadin.server.VaadinSession;
11
12 ead0a1ab Cherian Mathew
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
13 93fcde18 Cherian Mathew
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinAuthentication;
14
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
15 ead0a1ab Cherian Mathew
16
public class AuthenticationPresenter implements IAuthenticationComponent.AuthenticationComponentListener{
17
18 93fcde18 Cherian Mathew
    @Override
19
    public boolean login(URI uri, String context, String userName, String password) {
20 92a4f98e Andreas Kohlbecker
21 93fcde18 Cherian Mathew
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userName, password);
22
        AuthenticationManager authenticationManager = (AuthenticationManager) CdmSpringContextHelper.getCurrent().getBean("authenticationManager");
23
        Authentication authentication = authenticationManager.authenticate(token);
24 92a4f98e Andreas Kohlbecker
25 93fcde18 Cherian Mathew
        if(authentication != null && authentication.isAuthenticated()) {
26 dfe03eb9 Cherian Mathew
            SecurityContextHolder.getContext().setAuthentication(authentication);
27 93fcde18 Cherian Mathew
            CdmVaadinAuthentication cvAuthentication = (CdmVaadinAuthentication) VaadinSession.getCurrent().getAttribute(CdmVaadinAuthentication.KEY);
28
            if(cvAuthentication == null) {
29
                cvAuthentication = new CdmVaadinAuthentication();
30
            }
31
            cvAuthentication.addAuthentication(uri, context, authentication);
32
            CdmVaadinSessionUtilities.setCurrentAttribute(CdmVaadinAuthentication.KEY, cvAuthentication);
33
            return true;
34
        }
35 92a4f98e Andreas Kohlbecker
36 93fcde18 Cherian Mathew
        return false;
37
    }
38 ead0a1ab Cherian Mathew
39
}