Revision 93fcde18
Added by Cherian Mathew almost 9 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/AuthenticationView.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.cdm.vaadin.view; |
2 | 2 |
|
3 | 3 |
import org.springframework.security.authentication.BadCredentialsException; |
4 |
import org.springframework.security.core.Authentication; |
|
5 | 4 |
|
6 | 5 |
import com.vaadin.annotations.AutoGenerated; |
7 | 6 |
import com.vaadin.data.validator.StringLengthValidator; |
8 | 7 |
import com.vaadin.event.ShortcutAction.KeyCode; |
9 | 8 |
import com.vaadin.navigator.View; |
10 | 9 |
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; |
10 |
import com.vaadin.server.Page; |
|
11 |
import com.vaadin.server.VaadinServlet; |
|
11 | 12 |
import com.vaadin.ui.Alignment; |
12 | 13 |
import com.vaadin.ui.Button; |
13 | 14 |
import com.vaadin.ui.Button.ClickEvent; |
... | ... | |
20 | 21 |
import com.vaadin.ui.UI; |
21 | 22 |
import com.vaadin.ui.VerticalLayout; |
22 | 23 |
|
24 |
import eu.etaxonomy.cdm.vaadin.presenter.AuthenticationPresenter; |
|
23 | 25 |
import eu.etaxonomy.cdm.vaadin.ui.AbstractAuthenticatedUI; |
24 |
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities; |
|
25 | 26 |
|
26 | 27 |
|
27 | 28 |
public class AuthenticationView extends CustomComponent implements IAuthenticationComponent, ClickListener , View { |
... | ... | |
62 | 63 |
userNameTF.setNullRepresentation(""); |
63 | 64 |
userNameTF.focus(); |
64 | 65 |
|
66 |
authListener = new AuthenticationPresenter(); |
|
67 |
|
|
65 | 68 |
loginBtn.addClickListener(this); |
66 | 69 |
loginBtn.setClickShortcut(KeyCode.ENTER, null); |
67 | 70 |
} |
... | ... | |
74 | 77 |
|
75 | 78 |
@Override |
76 | 79 |
public void buttonClick(ClickEvent event) { |
77 |
Authentication authentication = null; |
|
78 |
try { |
|
79 |
authentication = authListener.login(userNameTF.getValue(), passwordField.getValue()); |
|
80 |
} catch(BadCredentialsException e){ |
|
81 |
Notification.show("Bad credentials", Notification.Type.ERROR_MESSAGE); |
|
82 |
} |
|
83 |
if(authentication != null && authentication.isAuthenticated()) { |
|
84 |
CdmVaadinSessionUtilities.setCurrentAttribute("authentication", authentication); |
|
85 |
// we are sure that since we are in the authentication view that the |
|
86 |
// current ui should be of type AbstractAuthenticatedUI |
|
87 |
AbstractAuthenticatedUI aaui = (AbstractAuthenticatedUI) UI.getCurrent(); |
|
88 |
UI.getCurrent().getNavigator().navigateTo(aaui.getFirstViewName()); |
|
89 |
} |
|
80 |
boolean isAuthenticated = false; |
|
81 |
try { |
|
82 |
isAuthenticated = authListener.login(Page.getCurrent().getLocation(), |
|
83 |
VaadinServlet.getCurrent().getServletContext().getContextPath(), |
|
84 |
userNameTF.getValue(), |
|
85 |
passwordField.getValue()); |
|
86 |
if(isAuthenticated) { |
|
87 |
// we are sure that since we are in the authentication view that the |
|
88 |
// current ui should be of type AbstractAuthenticatedUI |
|
89 |
AbstractAuthenticatedUI aaui = (AbstractAuthenticatedUI) UI.getCurrent(); |
|
90 |
UI.getCurrent().getNavigator().navigateTo(aaui.getFirstViewName()); |
|
91 |
} |
|
92 |
} catch(BadCredentialsException e){ |
|
93 |
Notification.show("Bad credentials", Notification.Type.ERROR_MESSAGE); |
|
94 |
} |
|
90 | 95 |
} |
91 | 96 |
|
92 | 97 |
@Override |
Also available in: Unified diff
fix for #4844
CdmVaadinAuthentication : new class used for authentication
AuthenticationPresenter, AbstractAuthenticatedUI, CdmVaadinSessionUtilities, AuthenticationView, IAuthenticationComponent : using new authentication object linked to host and context path
CdmVaadinBaseTest, AuthenticationPresenterTest : test classes for new authentication