now using the simplified user management interface.
[utils] / security / impl / src / test / java / org / wamblee / security / authorization / TestUserAccessor.java
index c4cadcc851236d27e779f3fa6ab55a6d5df1ee17..73ed12c830315627a5485936538939f3c6564ed4 100644 (file)
@@ -17,18 +17,18 @@ package org.wamblee.security.authorization;
 
 import junit.framework.TestCase;
 
+import org.wamblee.security.authentication.Group;
+import org.wamblee.security.authentication.InMemoryGroupSet;
+import org.wamblee.security.authentication.InMemoryUserSet;
+import org.wamblee.security.authentication.RegexpNameValidator;
+import org.wamblee.security.authentication.User;
+import org.wamblee.security.authentication.UserAccessor;
+import org.wamblee.security.authentication.UserAdministration;
+import org.wamblee.security.authentication.UserAdministrationImpl;
+import org.wamblee.security.authentication.UserMgtException;
+import org.wamblee.security.authentication.UserMgtException.Reason;
 import org.wamblee.security.encryption.Md5HexMessageDigester;
 
-import org.wamblee.usermgt.Group;
-import org.wamblee.usermgt.InMemoryGroupSet;
-import org.wamblee.usermgt.InMemoryUserSet;
-import org.wamblee.usermgt.RegexpNameValidator;
-import org.wamblee.usermgt.User;
-import org.wamblee.usermgt.UserAccessor;
-import org.wamblee.usermgt.UserAdministration;
-import org.wamblee.usermgt.UserAdministrationImpl;
-import org.wamblee.usermgt.UserMgtException;
-import org.wamblee.usermgt.UserMgtException.Reason;
 
 /**
  * User access that always returns a user that belongs to a fixed group.
@@ -42,13 +42,10 @@ public class TestUserAccessor implements UserAccessor {
 
     private static final String GROUP = "users";
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.wamblee.usermgt.UserAccessor#getCurrentUser()
-     */
-    public User getCurrentUser() {
-        UserAdministration admin = new UserAdministrationImpl(
+    private UserAdministration userAdmin; 
+    
+    public TestUserAccessor() { 
+        userAdmin = new UserAdministrationImpl(
             new InMemoryUserSet(new RegexpNameValidator(
                 RegexpNameValidator.PASSWORD_PATTERN, Reason.INVALID_PASSWORD,
                 "Password must contain at least 6 characters"),
@@ -58,13 +55,24 @@ public class TestUserAccessor implements UserAccessor {
             new RegexpNameValidator(RegexpNameValidator.ID_PATTERN,
                 Reason.INVALID_GROUPNAME, "Invalid group"));
 
-        try {
-            Group group = admin.createGroup(GROUP);
-
-            return admin.createUser(USER, PASSWORD, group);
-        } catch (UserMgtException e) {
-            TestCase.fail(e.getMessage());
-            throw new RuntimeException(e);
-        }
+            userAdmin.createGroup(GROUP);
+            userAdmin.createUser(USER, PASSWORD);
+            userAdmin.addUserToGroup(USER, GROUP);
+    }
+    
+    // NOTE: This is only for test. Normally the user accessor would not depend
+    // on user administration. This just ensures that a user administration is created
+    // that knows about the given user. 
+    public UserAdministration getUserAdmin() {
+        return userAdmin;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.wamblee.usermgt.UserAccessor#getCurrentUser()
+     */
+    public String getCurrentUser() {
+        return USER;
     }
 }