Revision dfe03eb9
Added by Cherian Mathew almost 9 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/AuthenticationPresenter.java | ||
---|---|---|
5 | 5 |
import org.springframework.security.authentication.AuthenticationManager; |
6 | 6 |
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
7 | 7 |
import org.springframework.security.core.Authentication; |
8 |
import org.springframework.security.core.context.SecurityContextHolder; |
|
8 | 9 |
|
9 | 10 |
import com.vaadin.server.VaadinSession; |
10 | 11 |
|
... | ... | |
23 | 24 |
AuthenticationManager authenticationManager = (AuthenticationManager) CdmSpringContextHelper.getCurrent().getBean("authenticationManager"); |
24 | 25 |
Authentication authentication = authenticationManager.authenticate(token); |
25 | 26 |
if(authentication != null && authentication.isAuthenticated()) { |
27 |
SecurityContextHolder.getContext().setAuthentication(authentication); |
|
26 | 28 |
CdmVaadinAuthentication cvAuthentication = (CdmVaadinAuthentication) VaadinSession.getCurrent().getAttribute(CdmVaadinAuthentication.KEY); |
27 | 29 |
if(cvAuthentication == null) { |
28 | 30 |
cvAuthentication = new CdmVaadinAuthentication(); |
src/main/java/eu/etaxonomy/cdm/vaadin/ui/AbstractAuthenticatedUI.java | ||
---|---|---|
48 | 48 |
URI uri = Page.getCurrent().getLocation(); |
49 | 49 |
String context = VaadinServlet.getCurrent().getServletContext().getContextPath(); |
50 | 50 |
if(ignoreAuthentication || (cvAuthentication != null && cvAuthentication.isAuthenticated(uri, context))) { |
51 |
if(cvAuthentication != null) { |
|
52 |
cvAuthentication.setSecurityContextAuthentication(uri, context); |
|
53 |
} |
|
51 | 54 |
UI.getCurrent().getNavigator().navigateTo(getFirstViewName()); |
52 | 55 |
} else { |
53 | 56 |
UI.getCurrent().getNavigator().navigateTo(AUTHENTICATION_VIEW); |
src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmVaadinAuthentication.java | ||
---|---|---|
15 | 15 |
|
16 | 16 |
import org.apache.log4j.Logger; |
17 | 17 |
import org.springframework.security.core.Authentication; |
18 |
import org.springframework.security.core.context.SecurityContextHolder; |
|
18 | 19 |
|
19 | 20 |
/** |
20 | 21 |
* @author cmathew |
... | ... | |
53 | 54 |
return false; |
54 | 55 |
} |
55 | 56 |
|
57 |
public boolean setSecurityContextAuthentication(URI uri, String context) { |
|
58 |
if(uri != null && context != null && !context.isEmpty()) { |
|
59 |
Authentication authentication = hostAuthenticationMap.get(getRequestSource(uri, context)); |
|
60 |
if(authentication != null && authentication.isAuthenticated()) { |
|
61 |
SecurityContextHolder.getContext().setAuthentication(authentication); |
|
62 |
return true; |
|
63 |
} |
|
64 |
} |
|
65 |
return false; |
|
66 |
} |
|
67 |
|
|
56 | 68 |
public static String getRequestSource(URI uri, String context) { |
57 | 69 |
String source = uri.getHost() + ":" + String.valueOf(uri.getPort()) + context; |
58 | 70 |
logger.warn(" request source : " + source); |
59 | 71 |
return source; |
60 | 72 |
} |
61 | 73 |
|
74 |
|
|
75 |
|
|
62 | 76 |
} |
Also available in: Unified diff
setting authentication in security context of UI thread