now using the simplified user management interface.
[utils] / security / impl / src / test / java / org / wamblee / security / authorization / TestUserAccessor.java
index f65609efd439caf7c9cf3d8cefd405f16989b351..73ed12c830315627a5485936538939f3c6564ed4 100644 (file)
@@ -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;
     }
 }