From 6a8c99a7cc0ff3ef13acf79e47a7807014fa265a Mon Sep 17 00:00:00 2001
From: brinn <brinn>
Date: Mon, 14 Apr 2008 19:57:02 +0000
Subject: [PATCH] LMS-327 change: make IAuthenticationService throw an
 IllegalArgumentException rather than an EnvironmentFailureException if
 retrieving information about a user fails

SVN: 5511
---
 .../cisd/authentication/IAuthenticationService.java    | 10 ++++++----
 .../crowd/CrowdAuthenticationService.java              |  5 ++---
 .../crowd/CrowdAuthenticationServiceTest.java          |  6 ++----
 3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/authentication/source/java/ch/systemsx/cisd/authentication/IAuthenticationService.java b/authentication/source/java/ch/systemsx/cisd/authentication/IAuthenticationService.java
index 85b7eb0d72f..08eb97ff253 100644
--- a/authentication/source/java/ch/systemsx/cisd/authentication/IAuthenticationService.java
+++ b/authentication/source/java/ch/systemsx/cisd/authentication/IAuthenticationService.java
@@ -28,7 +28,7 @@ public interface IAuthenticationService extends ISelfTestable
 
     /**
      * 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.
      * <p>
      * The returned application token can then be used to authenticate an user (via
@@ -60,8 +60,10 @@ public interface IAuthenticationService extends ISelfTestable
      * not <code>null</code>) to perform this lookup.
      * </p>
      * 
-     * @return a <code>Principal</code> object if given <var>user</var> could be found,
-     *         <code>null</code> otherwise.
+     * @return The <code>Principal</code> object for the given <var>user</var>.
+     * @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
diff --git a/authentication/source/java/ch/systemsx/cisd/authentication/crowd/CrowdAuthenticationService.java b/authentication/source/java/ch/systemsx/cisd/authentication/crowd/CrowdAuthenticationService.java
index 0227302535f..d72d0a9d899 100644
--- a/authentication/source/java/ch/systemsx/cisd/authentication/crowd/CrowdAuthenticationService.java
+++ b/authentication/source/java/ch/systemsx/cisd/authentication/crowd/CrowdAuthenticationService.java
@@ -273,11 +273,10 @@ public class CrowdAuthenticationService implements IAuthenticationService
             }
             if (principal == null)
             {
-                throw new EnvironmentFailureException("CROWD: Principal information for user '"
-                        + user + "' could not be obtained.");
+                throw new IllegalArgumentException("Cannot find user '" + user + "'.");
             }
             return principal;
-        } catch (EnvironmentFailureException ex)
+        } catch (IllegalArgumentException ex)
         {
             throw ex;
         } catch (Exception ex) // SAXException, IOException
diff --git a/authentication/sourceTest/java/ch/systemsx/cisd/authentication/crowd/CrowdAuthenticationServiceTest.java b/authentication/sourceTest/java/ch/systemsx/cisd/authentication/crowd/CrowdAuthenticationServiceTest.java
index 9724f008664..68460daa17b 100644
--- a/authentication/sourceTest/java/ch/systemsx/cisd/authentication/crowd/CrowdAuthenticationServiceTest.java
+++ b/authentication/sourceTest/java/ch/systemsx/cisd/authentication/crowd/CrowdAuthenticationServiceTest.java
@@ -28,7 +28,6 @@ import org.testng.annotations.Test;
 
 import ch.systemsx.cisd.authentication.IAuthenticationService;
 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.utilities.OSUtilities;
 
@@ -250,10 +249,9 @@ public class CrowdAuthenticationServiceTest
         {
             authenticationService.getPrincipal(APPLICATION_TOKEN, USER);
             fail("EnvironmentFailureException expected");
-        } catch (EnvironmentFailureException e)
+        } catch (IllegalArgumentException e)
         {
-            assertEquals("CROWD: Principal information for user '" + USER
-                    + "' could not be obtained.", e.getMessage());
+            assertEquals("Cannot find user '" + USER + "'.", e.getMessage());
         }
 
         assertEquals(
-- 
GitLab