ItEr39S10CUAltaUsuario: implemented the password field in user edition page
If the password field is left empty when *editing* a user, its password remains unchanged. If it's left empty when *creating* a user, the business layer will complain. TODO: make this behaviour explicit for the user (label with instructions, ConstraintChecker when creating a user...)
This commit is contained in:
parent
1882bcbe6d
commit
a0ebc8343e
4 changed files with 54 additions and 0 deletions
|
|
@ -112,4 +112,11 @@ public interface IUserModel {
|
|||
*/
|
||||
void addProfile(Profile profile);
|
||||
|
||||
/**
|
||||
* Sets the password attribute to the inner {@ link User} object.
|
||||
*
|
||||
* @param password String with the <b>unencrypted</b> password.
|
||||
*/
|
||||
void setPassword(String password);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -189,6 +189,16 @@ public class UserCRUDController extends GenericForwardComposer implements
|
|||
Util.reloadBindings(createWindow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the XXXModel to set the password attribute of the inner
|
||||
* {@ link User} object.
|
||||
*
|
||||
* @param password String with the <b>unencrypted</b> password.
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
userModel.setPassword(password);
|
||||
}
|
||||
|
||||
private OnlyOneVisible getVisibility() {
|
||||
return (visibility == null) ? new OnlyOneVisible(createWindow,
|
||||
listWindow)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.navalplanner.business.users.daos.IUserDAO;
|
|||
import org.navalplanner.business.users.entities.Profile;
|
||||
import org.navalplanner.business.users.entities.User;
|
||||
import org.navalplanner.business.users.entities.UserRole;
|
||||
import org.navalplanner.web.users.services.IDBPasswordEncoderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
|
@ -48,8 +49,13 @@ public class UserModel implements IUserModel {
|
|||
@Autowired
|
||||
private IUserDAO userDAO;
|
||||
|
||||
@Autowired
|
||||
private IDBPasswordEncoderService dbPasswordEncoderService;
|
||||
|
||||
private User user;
|
||||
|
||||
private String clearNewPassword;
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly=true)
|
||||
public List<User> getUsers() {
|
||||
|
|
@ -59,6 +65,19 @@ public class UserModel implements IUserModel {
|
|||
@Override
|
||||
@Transactional
|
||||
public void confirmSave() throws ValidationException {
|
||||
try {
|
||||
//user.getLoginName() has to be validated before encoding password,
|
||||
//because it must exist to perform the encoding
|
||||
Validate.notEmpty(user.getLoginName());
|
||||
|
||||
if (clearNewPassword != null) {
|
||||
user.setPassword(dbPasswordEncoderService.
|
||||
encodePassword(clearNewPassword, user.getLoginName()));
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException e) {}
|
||||
|
||||
user.validate();
|
||||
userDAO.save(user);
|
||||
}
|
||||
|
||||
|
|
@ -147,4 +166,17 @@ public class UserModel implements IUserModel {
|
|||
public void addProfile(Profile profile) {
|
||||
user.addProfile(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassword(String password) {
|
||||
//password is not encrypted right away, because
|
||||
//user.getLoginName must exist to do that, and we're
|
||||
//not sure at this point
|
||||
if(password != "") {
|
||||
clearNewPassword = password;
|
||||
}
|
||||
else{
|
||||
clearNewPassword = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@
|
|||
value="@{controller.user.loginName}" width="300px"
|
||||
constraint="no empty:${i18n:_('cannot be null or empty')}"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('Password')}:" />
|
||||
<textbox id="password" type="password"
|
||||
onChange="controller.setPassword(self.value);" width="300px"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('Disabled')}:" />
|
||||
<checkbox id="disabled"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue