1 |
ead0a1ab
|
Cherian Mathew
|
package eu.etaxonomy.cdm.vaadin.presenter;
|
2 |
|
|
|
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
|
import eu.etaxonomy.cdm.vaadin.view.IAuthenticationComponent;
|
16 |
|
|
|
17 |
|
|
public class AuthenticationPresenter implements IAuthenticationComponent.AuthenticationComponentListener{
|
18 |
|
|
|
19 |
93fcde18
|
Cherian Mathew
|
@Override
|
20 |
|
|
public boolean login(URI uri, String context, String userName, String password) {
|
21 |
|
|
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userName, password);
|
22 |
|
|
AuthenticationManager authenticationManager = (AuthenticationManager) CdmSpringContextHelper.getCurrent().getBean("authenticationManager");
|
23 |
|
|
Authentication authentication = authenticationManager.authenticate(token);
|
24 |
|
|
if(authentication != null && authentication.isAuthenticated()) {
|
25 |
dfe03eb9
|
Cherian Mathew
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
26 |
93fcde18
|
Cherian Mathew
|
CdmVaadinAuthentication cvAuthentication = (CdmVaadinAuthentication) VaadinSession.getCurrent().getAttribute(CdmVaadinAuthentication.KEY);
|
27 |
|
|
if(cvAuthentication == null) {
|
28 |
|
|
cvAuthentication = new CdmVaadinAuthentication();
|
29 |
|
|
}
|
30 |
|
|
cvAuthentication.addAuthentication(uri, context, authentication);
|
31 |
|
|
CdmVaadinSessionUtilities.setCurrentAttribute(CdmVaadinAuthentication.KEY, cvAuthentication);
|
32 |
|
|
return true;
|
33 |
|
|
}
|
34 |
|
|
return false;
|
35 |
|
|
}
|
36 |
ead0a1ab
|
Cherian Mathew
|
|
37 |
|
|
}
|