now using the simplified user management interface.
[utils] / security / impl / src / main / java / org / wamblee / security / authentication / User.java
index 03c15eea9297c6296b0a21f8bd2fae93fec9bded..82a77303f6432b0dbedef95bfc6dbbd8fcfa0bc2 100644 (file)
@@ -98,18 +98,14 @@ public class User implements Serializable, Comparable {
      *            User name.
      * @param aPassword
      *            Password.
-     * @param aGroup
-     *            Group the user belongs to.
      */
-    User(String aName, String aPassword, Group aGroup,
-        NameValidator aPasswordValidator, MessageDigester aPasswordEncoder)
-        throws UserMgtException {
+    User(String aName, String aPassword, NameValidator aPasswordValidator,
+        MessageDigester aPasswordEncoder) {
         super();
         name = aName;
         aPasswordValidator.validate(aPassword);
         password = aPasswordEncoder.hash(aPassword);
         groups = new TreeSet<Group>();
-        groups.add(aGroup);
         passwordValidator = aPasswordValidator;
         passwordEncoder = aPasswordEncoder;
     }
@@ -179,15 +175,12 @@ public class User implements Serializable, Comparable {
      * @param aPassword
      *            Password to check.
      * 
-     * @throws UserMgtException
-     *             In case the password is incorrect.
+     * @return True iff the password is correct.
      */
-    public void checkPassword(String aPassword) throws UserMgtException {
+    public boolean checkPassword(String aPassword) {
         String encoded = passwordEncoder.hash(aPassword);
 
-        if (!password.equals(encoded)) {
-            throw new UserMgtException(Reason.INVALID_PASSWORD, this);
-        }
+        return password.equals(encoded);
     }
 
     /**
@@ -198,14 +191,15 @@ public class User implements Serializable, Comparable {
      * @param aNewPassword
      *            New password.
      * 
-     * @throws UserMgtException
-     *             In case the old password is incorrect.
+     * @return True iff the password was changed successfully.
      */
-    public void changePassword(String aOldPassword, String aNewPassword)
-        throws UserMgtException {
-        checkPassword(aOldPassword);
+    public boolean changePassword(String aOldPassword, String aNewPassword) {
+        if (!checkPassword(aOldPassword)) {
+            return false;
+        }
         passwordValidator.validate(aNewPassword);
         setPassword(aNewPassword);
+        return true;
     }
 
     /**
@@ -214,7 +208,7 @@ public class User implements Serializable, Comparable {
      *            The password to set.
      * 
      */
-    public void setPassword(String aPassword) throws UserMgtException {
+    public void setPassword(String aPassword) {
         passwordValidator.validate(aPassword);
         password = passwordEncoder.hash(aPassword);
     }
@@ -336,16 +330,11 @@ public class User implements Serializable, Comparable {
      * @throws UserMgtException
      *             In case the user does not belong to the group.
      */
-    void removeGroup(Group aGroup) throws UserMgtException {
+    void removeGroup(Group aGroup) {
         if (!groups.contains(aGroup)) {
             throw new UserMgtException(Reason.USER_NOT_IN_GROUP, this, aGroup);
         }
 
-        if (groups.size() == 1) {
-            throw new UserMgtException(Reason.USER_MUST_BE_IN_A_GROUP, this,
-                aGroup);
-        }
-
         groups.remove(aGroup);
     }