|
From: <go...@us...> - 2013-03-29 09:10:38
|
Revision: 16186
http://unicore.svn.sourceforge.net/unicore/?rev=16186&view=rev
Author: golbi
Date: 2013-03-29 09:10:29 +0000 (Fri, 29 Mar 2013)
Log Message:
-----------
Added initial support for authentication on the Vaadin endpoints
Modified Paths:
--------------
unity/trunk/core/src/main/java/pl/edu/icm/unity/server/authn/AuthenticationContext.java
unity/trunk/distribution/src/test/resources/unityServer.conf
unity/trunk/web-admin/src/main/java/pl/edu/icm/unity/webadmin/WebAdminUI.java
unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/UnityVaadinServlet.java
unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/AuthenticationUI.java
unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/VaadinAuthentication.java
unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/extensions/PasswordRetrieval.java
Added Paths:
-----------
unity/trunk/core/src/main/java/pl/edu/icm/unity/server/authn/AuthenticationResult.java
unity/trunk/types/src/main/java/pl/edu/icm/unity/exceptions/AuthenticationException.java
unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/AuthenticationProcessor.java
Modified: unity/trunk/core/src/main/java/pl/edu/icm/unity/server/authn/AuthenticationContext.java
===================================================================
--- unity/trunk/core/src/main/java/pl/edu/icm/unity/server/authn/AuthenticationContext.java 2013-03-28 19:41:58 UTC (rev 16185)
+++ unity/trunk/core/src/main/java/pl/edu/icm/unity/server/authn/AuthenticationContext.java 2013-03-29 09:10:29 UTC (rev 16186)
@@ -4,6 +4,8 @@
*/
package pl.edu.icm.unity.server.authn;
+import java.io.Serializable;
+
import pl.edu.icm.unity.exceptions.RuntimeEngineException;
/**
@@ -12,8 +14,10 @@
* The thread-local variable should be set up by the binding authentication code.
* @author K. Benedyczak
*/
-public class AuthenticationContext
+public class AuthenticationContext implements Serializable
{
+ private static final long serialVersionUID = 1L;
+
private static ThreadLocal<AuthenticationContext> threadLocal = new ThreadLocal<AuthenticationContext>();
private AuthenticatedEntity euthenticatedEntity;
Added: unity/trunk/core/src/main/java/pl/edu/icm/unity/server/authn/AuthenticationResult.java
===================================================================
--- unity/trunk/core/src/main/java/pl/edu/icm/unity/server/authn/AuthenticationResult.java (rev 0)
+++ unity/trunk/core/src/main/java/pl/edu/icm/unity/server/authn/AuthenticationResult.java 2013-03-29 09:10:29 UTC (rev 16186)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2013 ICM Uniwersytet Warszawski All rights reserved.
+ * See LICENCE.txt file for licensing information.
+ */
+package pl.edu.icm.unity.server.authn;
+
+/**
+ * This class object is returned by authenticator with information about authentication result.
+ * This cover authentication result of a single authenticator, not the combined result of authentication
+ * with all authenticators in the set.
+ *
+ * @author K. Benedyczak
+ */
+public class AuthenticationResult
+{
+ public enum Status {
+ /**
+ * There was no input for authenticator
+ */
+ notApplicable,
+
+ /**
+ * There was authentication try with the authenticator but it failed
+ */
+ deny,
+
+ /**
+ * Can happen only in the case of remote authenticators, when the
+ * authentication was successful, but the remote principal is not
+ * registered locally.
+ */
+ unknownRemotePrincipal,
+
+ /**
+ * Everything OK
+ */
+ success
+ }
+
+ private Status status;
+ //TODO add data about remote authenticated principal
+ private AuthenticatedEntity authenticatedEntity;
+
+ public AuthenticationResult(Status status, AuthenticatedEntity authenticatedEntity)
+ {
+ this.status = status;
+ this.authenticatedEntity = authenticatedEntity;
+ }
+
+ public Status getStatus()
+ {
+ return status;
+ }
+
+ public AuthenticatedEntity getAuthenticatedEntity()
+ {
+ return authenticatedEntity;
+ }
+
+
+}
Modified: unity/trunk/distribution/src/test/resources/unityServer.conf
===================================================================
--- unity/trunk/distribution/src/test/resources/unityServer.conf 2013-03-28 19:41:58 UTC (rev 16185)
+++ unity/trunk/distribution/src/test/resources/unityServer.conf 2013-03-29 09:10:29 UTC (rev 16186)
@@ -38,7 +38,7 @@
unityServer.core.authenticators.1.authenticatorName=password web authenticator
unityServer.core.authenticators.1.authenticatorType=password with web-password
-unityServer.core.authenticators.1.localCredential=secured password
+unityServer.core.authenticators.1.localCredential=Password credential
#unityServer.core.authenticators.1.verificatorConfigurationFile=src/test/resources/empty.json
unityServer.core.authenticators.1.retrievalConfigurationFile=src/test/resources/empty.json
Added: unity/trunk/types/src/main/java/pl/edu/icm/unity/exceptions/AuthenticationException.java
===================================================================
--- unity/trunk/types/src/main/java/pl/edu/icm/unity/exceptions/AuthenticationException.java (rev 0)
+++ unity/trunk/types/src/main/java/pl/edu/icm/unity/exceptions/AuthenticationException.java 2013-03-29 09:10:29 UTC (rev 16186)
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2013 ICM Uniwersytet Warszawski All rights reserved.
+ * See LICENCE.txt file for licensing information.
+ */
+package pl.edu.icm.unity.exceptions;
+
+/**
+ * Thrown on authentication problem
+ * @author K. Benedyczak
+ */
+public class AuthenticationException extends EngineException
+{
+ private static final long serialVersionUID = 1L;
+
+ public AuthenticationException(String msg, Throwable cause)
+ {
+ super(msg, cause);
+ }
+
+ public AuthenticationException(String msg)
+ {
+ super(msg);
+ }
+
+}
Modified: unity/trunk/web-admin/src/main/java/pl/edu/icm/unity/webadmin/WebAdminUI.java
===================================================================
--- unity/trunk/web-admin/src/main/java/pl/edu/icm/unity/webadmin/WebAdminUI.java 2013-03-28 19:41:58 UTC (rev 16185)
+++ unity/trunk/web-admin/src/main/java/pl/edu/icm/unity/webadmin/WebAdminUI.java 2013-03-29 09:10:29 UTC (rev 16186)
@@ -12,9 +12,11 @@
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
-import pl.edu.icm.unity.server.api.GroupsManagement;
+import pl.edu.icm.unity.exceptions.EngineException;
+import pl.edu.icm.unity.server.api.EndpointManagement;
import pl.edu.icm.unity.server.endpoint.BindingAuthn;
import pl.edu.icm.unity.types.endpoint.EndpointDescription;
+import pl.edu.icm.unity.types.endpoint.EndpointTypeDescription;
import pl.edu.icm.unity.webui.UnityWebUI;
import com.vaadin.server.VaadinRequest;
@@ -32,7 +34,7 @@
private static final long serialVersionUID = 1L;
@Autowired
- private GroupsManagement test;
+ private EndpointManagement test;
@Override
public void configure(EndpointDescription description,
@@ -45,7 +47,14 @@
@Override
protected void init(VaadinRequest request)
{
- setContent(new Label("Web UI. Has injected object: " + test));
+ try
+ {
+ List<EndpointTypeDescription> enpT = test.getEndpointTypes();
+ setContent(new Label("Web UI. Endpoint types: " + enpT.toString()));
+ } catch (EngineException e)
+ {
+ setContent(new Label("Web UI. Got error: " + e));
+ }
}
}
Modified: unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/UnityVaadinServlet.java
===================================================================
--- unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/UnityVaadinServlet.java 2013-03-28 19:41:58 UTC (rev 16185)
+++ unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/UnityVaadinServlet.java 2013-03-29 09:10:29 UTC (rev 16186)
@@ -4,11 +4,18 @@
*/
package pl.edu.icm.unity.webui;
+import java.io.IOException;
import java.util.List;
import java.util.Map;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
import org.springframework.context.ApplicationContext;
+import pl.edu.icm.unity.server.authn.AuthenticationContext;
import pl.edu.icm.unity.server.endpoint.BindingAuthn;
import pl.edu.icm.unity.types.endpoint.EndpointDescription;
@@ -41,8 +48,33 @@
this.description = description;
this.authenticators = authenticators;
}
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException
+ {
+ setAuthenticationcontext(request);
+ try
+ {
+ super.service(request, response);
+ } finally
+ {
+ AuthenticationContext.setCurrent(null);
+ }
+ }
-
+ private void setAuthenticationcontext(HttpServletRequest request)
+ {
+ HttpSession session = request.getSession(false);
+ if (session != null)
+ {
+ AuthenticationContext authnContext = (AuthenticationContext) session.getAttribute(
+ WebSession.USER_SESSION_KEY);
+ if (authnContext != null)
+ AuthenticationContext.setCurrent(authnContext);
+ }
+ }
+
@Override
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration)
{
Added: unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/AuthenticationProcessor.java
===================================================================
--- unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/AuthenticationProcessor.java (rev 0)
+++ unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/AuthenticationProcessor.java 2013-03-29 09:10:29 UTC (rev 16186)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2013 ICM Uniwersytet Warszawski All rights reserved.
+ * See LICENCE.txt file for licensing information.
+ */
+package pl.edu.icm.unity.webui.authn;
+
+import java.util.List;
+
+import pl.edu.icm.unity.exceptions.AuthenticationException;
+import pl.edu.icm.unity.server.authn.AuthenticatedEntity;
+import pl.edu.icm.unity.server.authn.AuthenticationContext;
+import pl.edu.icm.unity.server.authn.AuthenticationResult;
+import pl.edu.icm.unity.server.authn.AuthenticationResult.Status;
+import pl.edu.icm.unity.webui.WebSession;
+
+import com.vaadin.server.VaadinSession;
+import com.vaadin.server.WrappedSession;
+import com.vaadin.ui.UI;
+
+/**
+ * Handles results of authentication and if it is all right, redirects to the source application.
+ *
+ * TODO - this is far from being complete: needs to support remote unresolved entities and
+ * support no original URI and fragments.
+ *
+ * @author K. Benedyczak
+ */
+public class AuthenticationProcessor
+{
+ public static void processResults(List<AuthenticationResult> results) throws AuthenticationException
+ {
+ Long entityId = null;
+ for (AuthenticationResult result: results)
+ {
+ if (result.getStatus() != Status.success)
+ throw new AuthenticationException("Authentication failed");
+ long curId = result.getAuthenticatedEntity().getEntityId();
+ if (entityId == null)
+ entityId = curId;
+ else
+ if (entityId != curId)
+ {
+ throw new AuthenticationException("Two different users were authenticated");
+ }
+ }
+ logged(results.get(0).getAuthenticatedEntity());
+ }
+
+
+ private static void logged(AuthenticatedEntity authenticatedEntity)
+ {
+ VaadinSession vss = VaadinSession.getCurrent();
+ if (vss == null)
+ throw new RuntimeException("BUG Can't get VaadinSession to store authenticated user's data.");
+ WrappedSession session = vss.getSession();
+ AuthenticationContext authnContext = new AuthenticationContext(authenticatedEntity);
+ session.setAttribute(WebSession.USER_SESSION_KEY, authnContext);
+
+ UI ui = UI.getCurrent();
+ if (ui == null)
+ throw new RuntimeException("BUG Can't get UI to redirect the authenticated user.");
+ String origURL = (String) session.getAttribute(AuthenticationFilter.ORIGINAL_ADDRESS);
+ //String origFragment = (String) session.getAttribute(AuthenticationApp.ORIGINAL_FRAGMENT);
+ if (origURL == null)
+ return;
+ //origURL = DEFAULT_PORTAL_PATH;
+ //if (origFragment == null)
+ // origFragment = "";
+ //else
+ // origFragment = "#" + origFragment;
+
+ //origURL = origURL+origFragment;
+ ui.getPage().open(origURL, "");
+ }
+}
Modified: unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/AuthenticationUI.java
===================================================================
--- unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/AuthenticationUI.java 2013-03-28 19:41:58 UTC (rev 16185)
+++ unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/AuthenticationUI.java 2013-03-29 09:10:29 UTC (rev 16186)
@@ -4,24 +4,32 @@
*/
package pl.edu.icm.unity.webui.authn;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
-import org.springframework.stereotype.Component;
+import pl.edu.icm.unity.exceptions.AuthenticationException;
+import pl.edu.icm.unity.server.authn.AuthenticationResult;
import pl.edu.icm.unity.server.endpoint.BindingAuthn;
+import pl.edu.icm.unity.types.authn.AuthenticatorSet;
import pl.edu.icm.unity.types.endpoint.EndpointDescription;
import pl.edu.icm.unity.webui.UnityWebUI;
-import pl.edu.icm.unity.webui.WebSession;
+import pl.edu.icm.unity.webui.authn.VaadinAuthentication.UsernameProvider;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinSession;
-import com.vaadin.server.WrappedSession;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TabSheet;
+import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Button.ClickEvent;
@@ -30,58 +38,147 @@
* coordinates authentication.
* @author K. Benedyczak
*/
-@Component("AuthenticationUI")
+@org.springframework.stereotype.Component("AuthenticationUI")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class AuthenticationUI extends UI implements UnityWebUI
{
private static final long serialVersionUID = 1L;
- @SuppressWarnings("serial")
+ private EndpointDescription description;
+ private List<Map<String, VaadinAuthentication>> authenticators;
+
@Override
+ public void configure(EndpointDescription description,
+ List<Map<String, BindingAuthn>> authenticators)
+ {
+ this.description = description;
+ this.authenticators = new ArrayList<Map<String,VaadinAuthentication>>();
+ for (int i=0; i<authenticators.size(); i++)
+ {
+ Map<String, VaadinAuthentication> map = new HashMap<String, VaadinAuthentication>();
+ Map<String, BindingAuthn> origMap = authenticators.get(i);
+ for (Map.Entry<String, BindingAuthn> el: origMap.entrySet())
+ map.put(el.getKey(), (VaadinAuthentication)el.getValue());
+ this.authenticators.add(map);
+ }
+ }
+
+ @Override
protected void init(final VaadinRequest request)
{
- Button dummyAuthn = new Button("Authenticate");
- dummyAuthn.addClickListener(new ClickListener()
+ Component[] components = new Component[authenticators.size()];
+ for (int i=0; i<components.length; i++)
+ components[i] = buildAuthenticatorSetUI(authenticators.get(i),
+ description.getAuthenticatorSets().get(i));
+ Component all = buildAllSetsUI(components);
+ setContent(all);
+ }
+
+ private Component buildAllSetsUI(Component... setComponents)
+ {
+ if (setComponents.length == 1)
+ return setComponents[0];
+ TabSheet sheet = new TabSheet();
+ for (int i=0; i<setComponents.length; i++)
+ sheet.addTab(setComponents[i], "Authentication option " + (i+1));
+ return sheet;
+ }
+
+ private Component buildAuthenticatorSetUI(Map<String, VaadinAuthentication> authenticators,
+ AuthenticatorSet set)
+ {
+ boolean needCommonUsername = false;
+ VerticalLayout mainContainer = new VerticalLayout();
+
+ Label status = new Label("");
+
+ HorizontalLayout authenticatorsContainer = new HorizontalLayout();
+ authenticatorsContainer.setSpacing(true);
+ for (String authenticator: set.getAuthenticators())
{
- @Override
- public void buttonClick(ClickEvent event)
+ VaadinAuthentication vaadinAuth = authenticators.get(authenticator);
+ if (vaadinAuth.needsCommonUsernameComponent())
+ needCommonUsername = true;
+ authenticatorsContainer.addComponent(vaadinAuth.getComponent());
+ }
+
+ Button authenticateButton = new Button("Authenticate");
+ authenticateButton.addClickListener(new LoginButtonListener(authenticators, set, status));
+
+ mainContainer.addComponent(status);
+
+ if (!needCommonUsername)
+ {
+ mainContainer.addComponent(authenticatorsContainer);
+ mainContainer.addComponent(authenticateButton);
+ return mainContainer;
+ }
+
+ UsernameComponent usernameComponent = new UsernameComponent();
+ mainContainer.addComponent(usernameComponent);
+ mainContainer.addComponent(authenticatorsContainer);
+ for (String authenticator: set.getAuthenticators())
+ {
+ VaadinAuthentication vaadinAuth = authenticators.get(authenticator);
+ if (vaadinAuth.needsCommonUsernameComponent())
+ vaadinAuth.setUsernameCallback(usernameComponent);
+ }
+ mainContainer.addComponent(authenticateButton);
+
+ return mainContainer;
+ }
+
+ private class LoginButtonListener implements ClickListener
+ {
+ private static final long serialVersionUID = 1L;
+ private Map<String, VaadinAuthentication> authenticators;
+ private AuthenticatorSet set;
+ private Label status;
+
+ public LoginButtonListener(Map<String, VaadinAuthentication> authenticators,
+ AuthenticatorSet set, Label status)
+ {
+ this.authenticators = authenticators;
+ this.set = set;
+ this.status = status;
+ }
+
+ @Override
+ public void buttonClick(ClickEvent event)
+ {
+ List<AuthenticationResult> results = new ArrayList<AuthenticationResult>();
+ for (String authenticator: set.getAuthenticators())
{
- VaadinSession.getCurrent().getSession().setAttribute(
- WebSession.USER_SESSION_KEY, "dummy");
- logged();
+ VaadinAuthentication vaadinAuth = authenticators.get(authenticator);
+ results.add(vaadinAuth.getAuthenticationResult());
}
- });
- setContent(dummyAuthn);
+
+ try
+ {
+ AuthenticationProcessor.processResults(results);
+ } catch (AuthenticationException e)
+ {
+ status.setValue(e.getMessage());
+ }
+ }
}
- private void logged()
+ private class UsernameComponent extends HorizontalLayout implements UsernameProvider
{
- VaadinSession vss = VaadinSession.getCurrent();
- if (vss == null)
- throw new RuntimeException("BUG Can't get VaadinSession to store authenticated user's data.");
- WrappedSession session = vss.getSession();
- UI ui = UI.getCurrent();
- if (ui == null)
- throw new RuntimeException("BUG Can't get UI to redirect the authenticated user.");
- String origURL = (String) session.getAttribute(AuthenticationFilter.ORIGINAL_ADDRESS);
- //String origFragment = (String) session.getAttribute(AuthenticationApp.ORIGINAL_FRAGMENT);
- if (origURL == null)
- return;
- //origURL = DEFAULT_PORTAL_PATH;
- //if (origFragment == null)
- // origFragment = "";
- //else
- // origFragment = "#" + origFragment;
+ private static final long serialVersionUID = 1L;
+ private TextField username;
- //origURL = origURL+origFragment;
- ui.getPage().open(origURL, "");
- }
+ public UsernameComponent()
+ {
+ addComponent(new Label("Username:"));
+ username = new TextField();
+ addComponent(username);
+ }
- @Override
- public void configure(EndpointDescription description,
- List<Map<String, BindingAuthn>> authenticators)
- {
- // TODO Auto-generated method stub
-
+ @Override
+ public String getUsername()
+ {
+ return username.getValue();
+ }
}
}
Modified: unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/VaadinAuthentication.java
===================================================================
--- unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/VaadinAuthentication.java 2013-03-28 19:41:58 UTC (rev 16185)
+++ unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/VaadinAuthentication.java 2013-03-29 09:10:29 UTC (rev 16186)
@@ -4,6 +4,9 @@
*/
package pl.edu.icm.unity.webui.authn;
+import com.vaadin.ui.Component;
+
+import pl.edu.icm.unity.server.authn.AuthenticationResult;
import pl.edu.icm.unity.server.authn.CredentialRetrieval;
import pl.edu.icm.unity.server.endpoint.BindingAuthn;
import pl.edu.icm.unity.webui.VaadinEndpoint;
@@ -16,4 +19,39 @@
public interface VaadinAuthentication extends BindingAuthn
{
public static final String NAME = "web-vaadin7";
+
+ /**
+ * @return true if the retrieval requires username to be provided. Username is provided
+ * from a component shared by all authenticators in a set.
+ */
+ public boolean needsCommonUsernameComponent();
+
+ /**
+ * @return UI component associated with this retrieval
+ */
+ public Component getComponent();
+
+ /**
+ * Invoked only when {@link #needsCommonUsernameComponent()} returns true.
+ * @param usernameCallback
+ */
+ public void setUsernameCallback(UsernameProvider usernameCallback);
+
+ /**
+ * Should trigger the actual authentication (if was not triggered manually via the component)
+ * and return the result of the authentication.
+ * @return
+ */
+ public AuthenticationResult getAuthenticationResult();
+
+
+
+ /**
+ * Can be used by retriever to get the username which is actually entered.
+ * @author K. Benedyczak
+ */
+ public interface UsernameProvider
+ {
+ public String getUsername();
+ }
}
Modified: unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/extensions/PasswordRetrieval.java
===================================================================
--- unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/extensions/PasswordRetrieval.java 2013-03-28 19:41:58 UTC (rev 16185)
+++ unity/trunk/web-common/src/main/java/pl/edu/icm/unity/webui/authn/extensions/PasswordRetrieval.java 2013-03-29 09:10:29 UTC (rev 16186)
@@ -4,8 +4,18 @@
*/
package pl.edu.icm.unity.webui.authn.extensions;
+import com.vaadin.server.UserError;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.PasswordField;
+
+import pl.edu.icm.unity.server.authn.AuthenticatedEntity;
+import pl.edu.icm.unity.server.authn.AuthenticationResult;
+import pl.edu.icm.unity.server.authn.AuthenticationResult.Status;
import pl.edu.icm.unity.server.authn.CredentialExchange;
import pl.edu.icm.unity.server.authn.CredentialRetrieval;
+import pl.edu.icm.unity.stdext.credential.PasswordExchange;
import pl.edu.icm.unity.webui.authn.VaadinAuthentication;
/**
@@ -15,6 +25,10 @@
*/
public class PasswordRetrieval implements CredentialRetrieval, VaadinAuthentication
{
+ private UsernameProvider usernameProvider;
+ private PasswordExchange credentialExchange;
+ private PasswordField passwordField;
+
@Override
public String getBindingName()
{
@@ -35,8 +49,59 @@
@Override
public void setCredentialExchange(CredentialExchange e)
{
- // TODO Auto-generated method stub
-
+ this.credentialExchange = (PasswordExchange) e;
}
+ @Override
+ public boolean needsCommonUsernameComponent()
+ {
+ return true;
+ }
+
+ @Override
+ public Component getComponent()
+ {
+ HorizontalLayout container = new HorizontalLayout();
+ container.addComponent(new Label("Password: "));
+ passwordField = new PasswordField();
+ container.addComponent(passwordField);
+ return container;
+ }
+
+ @Override
+ public void setUsernameCallback(UsernameProvider usernameCallback)
+ {
+ this.usernameProvider = usernameCallback;
+ }
+
+ @Override
+ public AuthenticationResult getAuthenticationResult()
+ {
+ String username = usernameProvider.getUsername();
+ String password = passwordField.getValue();
+ if (username.equals("") && password.equals(""))
+ {
+ passwordField.setComponentError(new UserError("No value"));
+ return new AuthenticationResult(Status.notApplicable, null);
+ }
+ try
+ {
+ AuthenticatedEntity authenticatedEntity = credentialExchange.checkPassword(username, password);
+ return new AuthenticationResult(Status.success, authenticatedEntity);
+ } catch (Exception e)
+ {
+ passwordField.setComponentError(new UserError("Wrong username or password"));
+ return new AuthenticationResult(Status.deny, null);
+ }
+ }
}
+
+
+
+
+
+
+
+
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|