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.
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"),
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;
}
}