X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsecurity%2Fauthentication%2FUser.java;h=82a77303f6432b0dbedef95bfc6dbbd8fcfa0bc2;hb=f4f8467b507b7bb401e4ad0749ea426208831846;hp=03c15eea9297c6296b0a21f8bd2fae93fec9bded;hpb=03b34d260efda9f7df9fe35a703acd83c0cfe317;p=utils diff --git a/security/impl/src/main/java/org/wamblee/security/authentication/User.java b/security/impl/src/main/java/org/wamblee/security/authentication/User.java index 03c15eea..82a77303 100644 --- a/security/impl/src/main/java/org/wamblee/security/authentication/User.java +++ b/security/impl/src/main/java/org/wamblee/security/authentication/User.java @@ -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(); - 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); }