1
|
package eu.etaxonomy.cdm.remote.vaadin.components;
|
2
|
|
3
|
import java.io.Serializable;
|
4
|
|
5
|
import javax.annotation.PostConstruct;
|
6
|
|
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;
|
11
|
|
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;
|
23
|
|
24
|
import eu.etaxonomy.cdm.remote.vaadin.service.VaadinAuthenticationService;
|
25
|
import eu.etaxonomy.cdm.remote.vaadin.uiset.redlist.views.ClassificationSelectorView;
|
26
|
|
27
|
/**
|
28
|
*
|
29
|
*
|
30
|
* Yet another component, which creates a simple login form layout. It makes use of the
|
31
|
* AuthenticationController.
|
32
|
*
|
33
|
*
|
34
|
* @author a.oppermann
|
35
|
*
|
36
|
*/
|
37
|
|
38
|
@Component
|
39
|
@Scope("prototype")
|
40
|
public class LoginForm extends FormLayout implements Serializable{
|
41
|
|
42
|
/**
|
43
|
* Automatically generated serial version ID
|
44
|
*/
|
45
|
private static final long serialVersionUID = 8409330855620204572L;
|
46
|
|
47
|
private static final String COMMON_FIELD_WIDTH = "12em";
|
48
|
|
49
|
@Autowired
|
50
|
private transient VaadinAuthenticationService authenticationController;
|
51
|
|
52
|
|
53
|
|
54
|
|
55
|
private TextField userName;
|
56
|
private PasswordField passwordField;
|
57
|
|
58
|
|
59
|
@PostConstruct
|
60
|
public void PostConstruct(){
|
61
|
// userName
|
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("");
|
70
|
userName.focus();
|
71
|
|
72
|
// passwordField
|
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);
|
80
|
|
81
|
// sendButton
|
82
|
Button sendButton = new Button("Send", new Button.ClickListener() {
|
83
|
|
84
|
/**
|
85
|
* Automatically generated serial version ID
|
86
|
*/
|
87
|
private static final long serialVersionUID = -4423849632134093870L;
|
88
|
|
89
|
@Override
|
90
|
public void buttonClick(ClickEvent event) {
|
91
|
try{
|
92
|
boolean isAuthenticated = authenticationController.authenticate(userName.getValue(), passwordField.getValue());
|
93
|
if(isAuthenticated){
|
94
|
UI.getCurrent().getSession().setAttribute("isAuthenticated", isAuthenticated);
|
95
|
Page.getCurrent().setUriFragment("!"+ ClassificationSelectorView.NAME);//DashBoardView BfnView.NAME
|
96
|
}
|
97
|
}catch(AuthenticationException e){
|
98
|
Notification.show("Bad credentials",Notification.Type.ERROR_MESSAGE);
|
99
|
}
|
100
|
}
|
101
|
});
|
102
|
sendButton.setClickShortcut(KeyCode.ENTER, null);
|
103
|
sendButton.setCaption("Send");
|
104
|
sendButton.setImmediate(true);
|
105
|
|
106
|
Label header = new Label("Vaaditor login...");
|
107
|
Label label = new Label("Bitte melden Sie sich mit Ihrem Benutzernamen und Passwort an.");
|
108
|
|
109
|
header.setStyleName("h1");
|
110
|
|
111
|
setSpacing(true);
|
112
|
setMargin(true);
|
113
|
setSizeUndefined();
|
114
|
|
115
|
addComponent(header);
|
116
|
addComponent(label);
|
117
|
addComponent(userName);
|
118
|
addComponent(passwordField);
|
119
|
addComponent(sendButton);
|
120
|
}
|
121
|
}
|