Project

General

Profile

« Previous | Next » 

Revision 3d053187

Added by Andreas Kohlbecker over 6 years ago

showing error message on failed login attempt

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/LoginDialog.java
9 9
package eu.etaxonomy.cdm.vaadin.component;
10 10

  
11 11
import com.vaadin.ui.Button;
12
import com.vaadin.ui.Label;
12 13
import com.vaadin.ui.PasswordField;
13 14
import com.vaadin.ui.TabSheet;
14 15
import com.vaadin.ui.TextField;
......
26 27

  
27 28
    public LoginDialog() {
28 29
        addSelectedTabChangeListener(e -> focusFirstElement(e.getTabSheet()));
30
        getMessageLabel().setVisible(false);
29 31
        getTab(1).setEnabled(false);
30 32
        getTab(2).setEnabled(false);
31 33
    }
......
122 124
        return sendOnetimeLogin;
123 125
    }
124 126

  
127
    public Label getMessageLabel() {
128
        return message;
129
    }
130

  
125 131

  
126 132
}
src/main/java/eu/etaxonomy/cdm/vaadin/design/LoginDialogDesign.java
3 3
import com.vaadin.annotations.AutoGenerated;
4 4
import com.vaadin.annotations.DesignRoot;
5 5
import com.vaadin.ui.Button;
6
import com.vaadin.ui.Label;
6 7
import com.vaadin.ui.PasswordField;
7 8
import com.vaadin.ui.TabSheet;
8 9
import com.vaadin.ui.TextField;
9 10
import com.vaadin.ui.declarative.Design;
10 11

  
11
/**
12
/** 
12 13
 * !! DO NOT EDIT THIS FILE !!
13
 *
14
 * 
14 15
 * This class is generated by Vaadin Designer and will be overwritten.
15
 *
16
 * 
16 17
 * Please make a subclass with logic and additional interfaces as needed,
17 18
 * e.g class LoginView extends LoginDesign implements View { }
18 19
 */
......
22 23
public class LoginDialogDesign extends TabSheet {
23 24
    protected TextField userName;
24 25
    protected PasswordField password;
26
    protected Label message;
25 27
    protected Button loginButton;
26 28
    protected Button cancelLoginButton;
27 29
    protected TextField userNameSuggestion;
src/main/java/eu/etaxonomy/cdm/vaadin/view/LoginPresenter.java
18 18
import org.springframework.security.authentication.AuthenticationManager;
19 19
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
20 20
import org.springframework.security.core.Authentication;
21
import org.springframework.security.core.AuthenticationException;
21 22

  
22 23
import com.vaadin.spring.annotation.SpringComponent;
23 24
import com.vaadin.spring.annotation.UIScope;
......
61 62

  
62 63
    private String redirectToState;
63 64

  
64
    public boolean authenticate(String userName, String password){
65
    public boolean authenticate(String userName, String password) {
66

  
67
        getView().clearMessage();
65 68

  
66 69
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userName, password);
67 70
        AuthenticationManager authenticationManager = getRepo().getAuthenticationManager();
68
        Authentication authentication = authenticationManager.authenticate(token);
69

  
70
        if(authentication != null && authentication.isAuthenticated()) {
71
            log.debug("user '" + userName + "' authenticated");
72
            currentSecurityContext().setAuthentication(authentication);
73
            if(NavigationManager.class.isAssignableFrom(getNavigationManager().getClass())){
74
                eventBus.publishEvent(new AuthenticationSuccessEvent(userName));
75
                log.debug("redirecting to " + redirectToState);
76
                eventBus.publishEvent(new NavigationEvent(redirectToState));
71
        try {
72
            Authentication authentication = authenticationManager.authenticate(token);
73
            if(authentication != null && authentication.isAuthenticated()) {
74
                log.debug("user '" + userName + "' authenticated");
75
                currentSecurityContext().setAuthentication(authentication);
76
                if(NavigationManager.class.isAssignableFrom(getNavigationManager().getClass())){
77
                    eventBus.publishEvent(new AuthenticationSuccessEvent(userName));
78
                    log.debug("redirecting to " + redirectToState);
79
                    eventBus.publishEvent(new NavigationEvent(redirectToState));
80
                }
77 81
            }
82
        } catch (AuthenticationException e){
83
            getView().showErrorMessage("Login failed! Please check your username and password.");
78 84
        }
79 85
        return false;
80 86
    }
src/main/java/eu/etaxonomy/cdm/vaadin/view/LoginView.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.view;
10 10

  
11
import com.vaadin.ui.themes.ValoTheme;
12

  
11 13
import eu.etaxonomy.cdm.vaadin.component.LoginDialog;
12 14
import eu.etaxonomy.vaadin.mvp.ApplicationView;
13 15

  
......
20 22

  
21 23
    LoginDialog getLoginDialog();
22 24

  
25
    void clearMessage();
26

  
27
    void showErrorMessage(String text);
28

  
23 29
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/LoginViewBean.java
14 14
import com.vaadin.ui.Alignment;
15 15
import com.vaadin.ui.Button.ClickEvent;
16 16
import com.vaadin.ui.VerticalLayout;
17
import com.vaadin.ui.themes.ValoTheme;
17 18

  
18 19
import eu.etaxonomy.cdm.vaadin.component.LoginDialog;
19 20
import eu.etaxonomy.cdm.vaadin.event.AuthenticationAttemptEvent;
......
78 79
        getPresenter().onViewEnter();
79 80
    }
80 81

  
82
    @Override
83
    public void showErrorMessage(String text){
84
        loginDialog.getMessageLabel().setVisible(true);
85
        loginDialog.getMessageLabel().setStyleName(ValoTheme.BUTTON_TINY + " " +  ValoTheme.LABEL_FAILURE);
86
        loginDialog.getMessageLabel().setValue(text);
87
    }
88

  
89

  
90
    @Override
91
    public void clearMessage(){
92
        loginDialog.getMessageLabel().setVisible(false);
93
        loginDialog.getMessageLabel().setStyleName("");
94
        loginDialog.getMessageLabel().setValue("");
95
    }
81 96
}
src/main/resources/eu/etaxonomy/cdm/vaadin/design/LoginDialogDesign.html
14 14
     </vaadin-label>
15 15
     <vaadin-text-field caption="Username" _id="userName"></vaadin-text-field>
16 16
     <vaadin-password-field caption="Password" _id="password"></vaadin-password-field>
17
     <vaadin-label style-name="tiny" width="190px" _id="message">
18
     </vaadin-label>
17 19
     <vaadin-label style-name="tiny" width="190px">
18 20
       Lost your password? Please use the 
19 21
      <b>Password Recovery</b> tab. 

Also available in: Unified diff