<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="net.sourceforge.eclipsejetty.launcher.JettyLaunchClassPathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="net.sourceforge.eclipsejetty.starter.jetty9.Jetty9LauncherMain"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="cdm-vaadin"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dlog4j.configDebug=false -Dlog4j.configuration=file:///${system_property:user.home}/.cdmLibrary/log4j.properties -Dcdm.forceSchemaUpdate=true"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dlog4j.configDebug=false -Dlog4j.configuration=file:///${system_property:user.home}/.cdmLibrary/log4j.properties -Dcdm.forceSchemaUpdate=true -Dcdm-vaadin.login.usr=admin -Dcdm-vaadin.login.pwd=00000"/>
</launchConfiguration>
*/
package eu.etaxonomy.cdm.vaadin.view;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.EventListener;
* The {@link LoginView is used as replacement view in the scope of other views.
* Therefore the LoginPresenter must be in <b>UIScope</b> so that the LoginPresenter
* is available to all Views.
+ * <p>
+ * The LoginPresenter offers a <b>auto login feature for developers</b>. Tio activate the auto login
+ * you need to provide the <code>user name</code> and <code>password</code> using the environment variables
+ * <code>cdm-vaadin.login.usr</code> and <code>cdm-vaadin.login.pwd</code>, e.g.:
+ * <pre>
+ * -Dcdm-vaadin.login.usr=admin -Dcdm-vaadin.login.pwd=00000
+ * </pre>
*
* @author a.kohlbecker
* @since Apr 25, 2017
private static final long serialVersionUID = 4020699735656994791L;
+ private static final Logger log = Logger.getLogger(LoginPresenter.class);
+
+ private final static String PROPNAME_USER = "cdm-vaadin.login.usr";
+
+ private final static String PROPNAME_PASSWORD = "cdm-vaadin.login.pwd";
+
@Autowired
protected ApplicationEventPublisher eventBus;
Authentication authentication = authenticationManager.authenticate(token);
if(authentication != null && authentication.isAuthenticated()) {
+ log.debug("user '" + userName + "' autheticated");
currentSecurityContext().setAuthentication(authentication);
if(NavigationManager.class.isAssignableFrom(getNavigationManager().getClass())){
+ log.debug("reloading current view");
getNavigationManager().reloadCurrentView();
eventBus.publishEvent(new AuthenticationSuccessEvent(userName));
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onViewEnter() {
+ super.onViewEnter();
+ // attempt to auto login
+ if(StringUtils.isNotEmpty(System.getProperty(PROPNAME_USER)) && StringUtils.isNotEmpty(System.getProperty(PROPNAME_PASSWORD))){
+ log.warn("Performing autologin with user " + System.getProperty(PROPNAME_USER));
+ authenticate(System.getProperty(PROPNAME_USER), System.getProperty(PROPNAME_PASSWORD));
+ }
+ }
+
@EventListener
protected void onLoginEvent(AuthenticationAttemptEvent e){
authenticate(e.getUserName(), getView().getLoginDialog().getPassword().getValue());