* 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;
}
* @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);
}
/**
* @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;
}
/**
* The password to set.
*
*/
- public void setPassword(String aPassword) throws UserMgtException {
+ public void setPassword(String aPassword) {
passwordValidator.validate(aPassword);
password = passwordEncoder.hash(aPassword);
}
* @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);
}