1 package eu
.etaxonomy
.cdm
.remote
.vaadin
.components
;
3 import java
.io
.Serializable
;
5 import javax
.annotation
.PostConstruct
;
7 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
8 import org
.springframework
.context
.annotation
.Scope
;
9 import org
.springframework
.security
.core
.AuthenticationException
;
10 import org
.springframework
.stereotype
.Component
;
12 import com
.vaadin
.data
.validator
.StringLengthValidator
;
13 import com
.vaadin
.event
.ShortcutAction
.KeyCode
;
14 import com
.vaadin
.server
.Page
;
15 import com
.vaadin
.ui
.Button
;
16 import com
.vaadin
.ui
.Button
.ClickEvent
;
17 import com
.vaadin
.ui
.FormLayout
;
18 import com
.vaadin
.ui
.Label
;
19 import com
.vaadin
.ui
.Notification
;
20 import com
.vaadin
.ui
.PasswordField
;
21 import com
.vaadin
.ui
.TextField
;
22 import com
.vaadin
.ui
.UI
;
24 import eu
.etaxonomy
.cdm
.remote
.vaadin
.service
.VaadinAuthenticationService
;
25 import eu
.etaxonomy
.cdm
.remote
.vaadin
.uiset
.redlist
.views
.ClassificationSelectorView
;
30 * Yet another component, which creates a simple login form layout. It makes use of the
31 * AuthenticationController.
40 public class LoginForm
extends FormLayout
implements Serializable
{
43 * Automatically generated serial version ID
45 private static final long serialVersionUID
= 8409330855620204572L;
47 private static final String COMMON_FIELD_WIDTH
= "12em";
50 private transient VaadinAuthenticationService authenticationController
;
55 private TextField userName
;
56 private PasswordField passwordField
;
60 public void PostConstruct(){
62 userName
= new TextField();
63 userName
.setRequired(true);
64 userName
.setRequiredError("Please enter a valid user name!");
65 userName
.setCaption("Username");
66 userName
.setImmediate(false);
67 userName
.addValidator(new StringLengthValidator("It must be 3-25 characters", 3, 25, false));
68 userName
.setWidth(COMMON_FIELD_WIDTH
);
69 userName
.setNullRepresentation("");
73 passwordField
= new PasswordField();
74 passwordField
.setRequired(true);
75 passwordField
.setRequiredError("Please enter a valid password!");
76 passwordField
.addValidator(new StringLengthValidator("It must be 3-25 characters", 3, 25, false));
77 passwordField
.setCaption("Password");
78 passwordField
.setImmediate(false);
79 passwordField
.setWidth(COMMON_FIELD_WIDTH
);
82 Button sendButton
= new Button("Send", new Button
.ClickListener() {
85 * Automatically generated serial version ID
87 private static final long serialVersionUID
= -4423849632134093870L;
90 public void buttonClick(ClickEvent event
) {
92 boolean isAuthenticated
= authenticationController
.authenticate(userName
.getValue(), passwordField
.getValue());
94 UI
.getCurrent().getSession().setAttribute("isAuthenticated", isAuthenticated
);
95 Page
.getCurrent().setUriFragment("!"+ ClassificationSelectorView
.NAME
);//DashBoardView BfnView.NAME
97 }catch(AuthenticationException e
){
98 Notification
.show("Bad credentials",Notification
.Type
.ERROR_MESSAGE
);
102 sendButton
.setClickShortcut(KeyCode
.ENTER
, null);
103 sendButton
.setCaption("Send");
104 sendButton
.setImmediate(true);
106 Label header
= new Label("Vaaditor login...");
107 Label label
= new Label("Bitte melden Sie sich mit Ihrem Benutzernamen und Passwort an.");
109 header
.setStyleName("h1");
115 addComponent(header
);
117 addComponent(userName
);
118 addComponent(passwordField
);
119 addComponent(sendButton
);