From dddd967f01c829928530289dde324496bd26131f Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Sat, 19 Jan 2013 17:03:40 +0000 Subject: [PATCH] User method tryGetAndAuthenticateUserByEmail() rather than listPrincipalsByEmail() in DefaultSessionManager to authenticate a user by its email address. SVN: 28133 --- .../cisd/authentication/DefaultSessionManager.java | 11 ++--------- .../authentication/DefaultSessionManagerTest.java | 12 ++++-------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/authentication/source/java/ch/systemsx/cisd/authentication/DefaultSessionManager.java b/authentication/source/java/ch/systemsx/cisd/authentication/DefaultSessionManager.java index fab5a16bfaf..d8913fa6042 100644 --- a/authentication/source/java/ch/systemsx/cisd/authentication/DefaultSessionManager.java +++ b/authentication/source/java/ch/systemsx/cisd/authentication/DefaultSessionManager.java @@ -593,16 +593,9 @@ public class DefaultSessionManager<T extends BasicSession> implements ISessionMa { final Principal p = authenticationService.tryGetAndAuthenticateUser(user, password); if (p == null && tryEmailAsUserName && user.contains("@") - && authenticationService.supportsListingByEmail()) + && authenticationService.supportsAuthenticatingByEmail()) { - for (Principal p2 : authenticationService.listPrincipalsByEmail(user)) - { - if (authenticationService.authenticateUser(p2.getUserId(), password)) - { - p2.setAuthenticated(true); - return p2; - } - } + return authenticationService.tryGetAndAuthenticateUserByEmail(user, password); } return p; } diff --git a/authentication/sourceTest/java/ch/systemsx/cisd/authentication/DefaultSessionManagerTest.java b/authentication/sourceTest/java/ch/systemsx/cisd/authentication/DefaultSessionManagerTest.java index 3881425cbff..60b6d39bf18 100644 --- a/authentication/sourceTest/java/ch/systemsx/cisd/authentication/DefaultSessionManagerTest.java +++ b/authentication/sourceTest/java/ch/systemsx/cisd/authentication/DefaultSessionManagerTest.java @@ -20,8 +20,6 @@ import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertTrue; import static org.testng.AssertJUnit.fail; -import java.util.Arrays; - import org.apache.commons.lang.StringUtils; import org.apache.log4j.Level; import org.jmock.Expectations; @@ -169,19 +167,17 @@ public class DefaultSessionManagerTest final String user = "bla"; final String userEmail = "bla@blub.com"; final Principal sessionPrincipal = - new Principal(user, StringUtils.EMPTY, StringUtils.EMPTY, userEmail, false); + new Principal(user, StringUtils.EMPTY, StringUtils.EMPTY, userEmail, true); prepareRemoteHostSessionFactoryAndPrefixGenerator(user, sessionPrincipal); context.checking(new Expectations() { { one(authenticationService).tryGetAndAuthenticateUser(userEmail, "blub"); will(returnValue(null)); - one(authenticationService).supportsListingByEmail(); - will(returnValue(true)); - one(authenticationService).listPrincipalsByEmail(userEmail); - will(returnValue(Arrays.asList(sessionPrincipal))); - one(authenticationService).authenticateUser(user, "blub"); + one(authenticationService).supportsAuthenticatingByEmail(); will(returnValue(true)); + one(authenticationService).tryGetAndAuthenticateUserByEmail(userEmail, "blub"); + will(returnValue(sessionPrincipal)); } }); -- GitLab