1
|
/**
|
2
|
* Copyright (C) 2018 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.view;
|
10
|
|
11
|
import org.springframework.security.authentication.AuthenticationManager;
|
12
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
13
|
import org.springframework.security.core.Authentication;
|
14
|
import org.springframework.security.core.context.SecurityContextHolder;
|
15
|
|
16
|
import com.vaadin.server.VaadinSession;
|
17
|
|
18
|
import eu.etaxonomy.cdm.common.URI;
|
19
|
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
|
20
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinAuthentication;
|
21
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
|
22
|
|
23
|
public class AuthenticationPresenter implements IAuthenticationComponent.AuthenticationComponentListener{
|
24
|
|
25
|
@Override
|
26
|
public boolean login(URI uri, String context, String userName, String password) {
|
27
|
|
28
|
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userName, password);
|
29
|
AuthenticationManager authenticationManager = (AuthenticationManager) CdmSpringContextHelper.getCurrent().getBean("authenticationManager");
|
30
|
Authentication authentication = authenticationManager.authenticate(token);
|
31
|
|
32
|
if(authentication != null && authentication.isAuthenticated()) {
|
33
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
34
|
CdmVaadinAuthentication cvAuthentication = (CdmVaadinAuthentication) VaadinSession.getCurrent().getAttribute(CdmVaadinAuthentication.KEY);
|
35
|
if(cvAuthentication == null) {
|
36
|
cvAuthentication = new CdmVaadinAuthentication();
|
37
|
}
|
38
|
cvAuthentication.addAuthentication(uri, context, authentication);
|
39
|
CdmVaadinSessionUtilities.setCurrentAttribute(CdmVaadinAuthentication.KEY, cvAuthentication);
|
40
|
return true;
|
41
|
}
|
42
|
|
43
|
return false;
|
44
|
}
|
45
|
}
|