Revision 62b8daac
Added by Andreas Kohlbecker almost 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/LoginPresenter.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.vaadin.view; |
10 | 10 |
|
11 |
import org.apache.commons.lang.StringUtils; |
|
12 |
import org.apache.log4j.Logger; |
|
11 | 13 |
import org.springframework.beans.factory.annotation.Autowired; |
12 | 14 |
import org.springframework.context.ApplicationEventPublisher; |
13 | 15 |
import org.springframework.context.event.EventListener; |
... | ... | |
30 | 32 |
* The {@link LoginView is used as replacement view in the scope of other views. |
31 | 33 |
* Therefore the LoginPresenter must be in <b>UIScope</b> so that the LoginPresenter |
32 | 34 |
* is available to all Views. |
35 |
* <p> |
|
36 |
* The LoginPresenter offers a <b>auto login feature for developers</b>. Tio activate the auto login |
|
37 |
* you need to provide the <code>user name</code> and <code>password</code> using the environment variables |
|
38 |
* <code>cdm-vaadin.login.usr</code> and <code>cdm-vaadin.login.pwd</code>, e.g.: |
|
39 |
* <pre> |
|
40 |
* -Dcdm-vaadin.login.usr=admin -Dcdm-vaadin.login.pwd=00000 |
|
41 |
* </pre> |
|
33 | 42 |
* |
34 | 43 |
* @author a.kohlbecker |
35 | 44 |
* @since Apr 25, 2017 |
... | ... | |
41 | 50 |
|
42 | 51 |
private static final long serialVersionUID = 4020699735656994791L; |
43 | 52 |
|
53 |
private static final Logger log = Logger.getLogger(LoginPresenter.class); |
|
54 |
|
|
55 |
private final static String PROPNAME_USER = "cdm-vaadin.login.usr"; |
|
56 |
|
|
57 |
private final static String PROPNAME_PASSWORD = "cdm-vaadin.login.pwd"; |
|
58 |
|
|
44 | 59 |
@Autowired |
45 | 60 |
protected ApplicationEventPublisher eventBus; |
46 | 61 |
|
... | ... | |
60 | 75 |
Authentication authentication = authenticationManager.authenticate(token); |
61 | 76 |
|
62 | 77 |
if(authentication != null && authentication.isAuthenticated()) { |
78 |
log.debug("user '" + userName + "' autheticated"); |
|
63 | 79 |
currentSecurityContext().setAuthentication(authentication); |
64 | 80 |
if(NavigationManager.class.isAssignableFrom(getNavigationManager().getClass())){ |
81 |
log.debug("reloading current view"); |
|
65 | 82 |
getNavigationManager().reloadCurrentView(); |
66 | 83 |
eventBus.publishEvent(new AuthenticationSuccessEvent(userName)); |
67 | 84 |
} |
... | ... | |
70 | 87 |
} |
71 | 88 |
|
72 | 89 |
|
90 |
|
|
91 |
/** |
|
92 |
* {@inheritDoc} |
|
93 |
*/ |
|
94 |
@Override |
|
95 |
public void onViewEnter() { |
|
96 |
super.onViewEnter(); |
|
97 |
// attempt to auto login |
|
98 |
if(StringUtils.isNotEmpty(System.getProperty(PROPNAME_USER)) && StringUtils.isNotEmpty(System.getProperty(PROPNAME_PASSWORD))){ |
|
99 |
log.warn("Performing autologin with user " + System.getProperty(PROPNAME_USER)); |
|
100 |
authenticate(System.getProperty(PROPNAME_USER), System.getProperty(PROPNAME_PASSWORD)); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
73 | 104 |
@EventListener |
74 | 105 |
protected void onLoginEvent(AuthenticationAttemptEvent e){ |
75 | 106 |
authenticate(e.getUserName(), getView().getLoginDialog().getPassword().getValue()); |
Also available in: Unified diff
auto login feature for developers