From bf23c512f150b33b71b10e91bb28e2aafb8ce3f9 Mon Sep 17 00:00:00 2001
From: brinn <brinn>
Date: Mon, 14 Apr 2008 19:56:29 +0000
Subject: [PATCH] LMS-327 change: - add call to userStore.check() to the
 constructor - throw an IllegalArgumentException if information about a user
 cannot be obtained from the store

SVN: 5510
---
 .../authentication/file/FileAuthenticationService.java | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/authentication/source/java/ch/systemsx/cisd/authentication/file/FileAuthenticationService.java b/authentication/source/java/ch/systemsx/cisd/authentication/file/FileAuthenticationService.java
index 28b4791bee5..38da1e6f549 100644
--- a/authentication/source/java/ch/systemsx/cisd/authentication/file/FileAuthenticationService.java
+++ b/authentication/source/java/ch/systemsx/cisd/authentication/file/FileAuthenticationService.java
@@ -68,6 +68,7 @@ public class FileAuthenticationService implements IAuthenticationService
     public FileAuthenticationService(IUserStore userStore)
     {
         this.userStore = userStore;
+        userStore.check();
     }
 
     private String getToken()
@@ -76,7 +77,7 @@ public class FileAuthenticationService implements IAuthenticationService
     }
 
     /**
-     * Returns the path of the password file, which we consider to be the token.
+     * Returns the id of the password store, which we consider to be the token.
      */
     public String authenticateApplication()
     {
@@ -102,7 +103,12 @@ public class FileAuthenticationService implements IAuthenticationService
             operationLog.warn(String.format(TOKEN_FAILURE_MSG_TEMPLATE, token, applicationToken));
             return null;
         }
-        return userStore.tryGetUser(user).asPrincial();
+        final UserEntry userOrNull = userStore.tryGetUser(user);
+        if (userOrNull == null)
+        {
+            throw new IllegalArgumentException("Cannot find user '" + user + "'.");
+        }
+        return userOrNull.asPrincial();
     }
 
     public void check() throws EnvironmentFailureException, ConfigurationFailureException
-- 
GitLab