Skip to content
Snippets Groups Projects
Commit 6a8c99a7 authored by brinn's avatar brinn
Browse files

LMS-327

change: make IAuthenticationService throw an IllegalArgumentException rather than an EnvironmentFailureException if retrieving information about a user fails

SVN: 5511
parent bf23c512
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ public interface IAuthenticationService extends ISelfTestable ...@@ -28,7 +28,7 @@ public interface IAuthenticationService extends ISelfTestable
/** /**
* Attempts authentication of the application with credentials passed in the constructor and * Attempts authentication of the application with credentials passed in the constructor and
* retuns the application token. Implementations should log what is going on, whether the * returns the application token. Implementations should log what is going on, whether the
* application could register itself successfully or not. * application could register itself successfully or not.
* <p> * <p>
* The returned application token can then be used to authenticate an user (via * The returned application token can then be used to authenticate an user (via
...@@ -60,8 +60,10 @@ public interface IAuthenticationService extends ISelfTestable ...@@ -60,8 +60,10 @@ public interface IAuthenticationService extends ISelfTestable
* not <code>null</code>) to perform this lookup. * not <code>null</code>) to perform this lookup.
* </p> * </p>
* *
* @return a <code>Principal</code> object if given <var>user</var> could be found, * @return The <code>Principal</code> object for the given <var>user</var>.
* <code>null</code> otherwise. * @throws IllegalArgumentException If either the <var>applicationToken</var> is invalid or the
* <var>user</var> cannot be found.
*/ */
public Principal getPrincipal(String applicationToken, String user); public Principal getPrincipal(String applicationToken, String user)
throws IllegalArgumentException;
} }
\ No newline at end of file
...@@ -273,11 +273,10 @@ public class CrowdAuthenticationService implements IAuthenticationService ...@@ -273,11 +273,10 @@ public class CrowdAuthenticationService implements IAuthenticationService
} }
if (principal == null) if (principal == null)
{ {
throw new EnvironmentFailureException("CROWD: Principal information for user '" throw new IllegalArgumentException("Cannot find user '" + user + "'.");
+ user + "' could not be obtained.");
} }
return principal; return principal;
} catch (EnvironmentFailureException ex) } catch (IllegalArgumentException ex)
{ {
throw ex; throw ex;
} catch (Exception ex) // SAXException, IOException } catch (Exception ex) // SAXException, IOException
......
...@@ -28,7 +28,6 @@ import org.testng.annotations.Test; ...@@ -28,7 +28,6 @@ import org.testng.annotations.Test;
import ch.systemsx.cisd.authentication.IAuthenticationService; import ch.systemsx.cisd.authentication.IAuthenticationService;
import ch.systemsx.cisd.authentication.Principal; import ch.systemsx.cisd.authentication.Principal;
import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
import ch.systemsx.cisd.common.logging.BufferedAppender; import ch.systemsx.cisd.common.logging.BufferedAppender;
import ch.systemsx.cisd.common.utilities.OSUtilities; import ch.systemsx.cisd.common.utilities.OSUtilities;
...@@ -250,10 +249,9 @@ public class CrowdAuthenticationServiceTest ...@@ -250,10 +249,9 @@ public class CrowdAuthenticationServiceTest
{ {
authenticationService.getPrincipal(APPLICATION_TOKEN, USER); authenticationService.getPrincipal(APPLICATION_TOKEN, USER);
fail("EnvironmentFailureException expected"); fail("EnvironmentFailureException expected");
} catch (EnvironmentFailureException e) } catch (IllegalArgumentException e)
{ {
assertEquals("CROWD: Principal information for user '" + USER assertEquals("Cannot find user '" + USER + "'.", e.getMessage());
+ "' could not be obtained.", e.getMessage());
} }
assertEquals( assertEquals(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment