Skip to content
Snippets Groups Projects
Commit 7eb201cb authored by sveseli's avatar sveseli
Browse files

updated user create and edit functionality to crypt password if one is provided

parent ed9a9d9e
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ import gov.anl.aps.dm.portal.model.beans.UserInfoFacade;
import gov.anl.aps.dm.portal.model.entities.CloneableEntity;
import gov.anl.aps.dm.portal.model.entities.Experiment;
import gov.anl.aps.dm.portal.model.entities.RoleType;
import gov.anl.aps.dm.portal.utilities.CryptUtility;
import gov.anl.aps.dm.portal.utilities.SessionUtility;
import java.util.ArrayList;
import java.util.Collection;
......@@ -156,7 +157,7 @@ public class UserInfoController extends CrudEntityController<UserInfo, UserInfoF
public UserInfoController() {
}
public int getRows() {
return rows;
}
......@@ -173,7 +174,7 @@ public class UserInfoController extends CrudEntityController<UserInfo, UserInfoF
}
initialized = true;
}
@Override
public void clear() {
userExperimentsListTable.resetList();
......@@ -187,7 +188,7 @@ public class UserInfoController extends CrudEntityController<UserInfo, UserInfoF
public void setUserExperimentsListTable(UserExperimentsTable userExperimentsListTable) {
this.userExperimentsListTable = userExperimentsListTable;
}
@Override
protected UserInfoFacade getFacade() {
return userInfoFacade;
......@@ -223,15 +224,21 @@ public class UserInfoController extends CrudEntityController<UserInfo, UserInfoF
}
@Override
public void prepareEntityInsert(UserInfo user) throws ObjectAlreadyExists, MissingProperty{
public void prepareEntityInsert(UserInfo user) throws ObjectAlreadyExists, MissingProperty {
verifyMandatoryParam(user);
UserInfo existingUser = userInfoFacade.findByUsername(user.getUsername());
if (existingUser != null) {
throw new ObjectAlreadyExists("User " + user.getUsername() + " already exists.");
}
if (passwordEntry != null && !passwordEntry.isEmpty()) {
logger.debug("Will crypt provided password for user " + user.getUsername());
String cryptedPassword = CryptUtility.cryptPasswordWithPbkdf2(passwordEntry);
user.setPassword(cryptedPassword);
}
passwordEntry = null;
logger.debug("Inserting new user " + user.getUsername());
}
private void verifyMandatoryParam(UserInfo user) throws MissingProperty {
int missing = 0;
if ((user.getUsername() == null) || (user.getUsername().length() == 0)) {
......@@ -260,26 +267,28 @@ public class UserInfoController extends CrudEntityController<UserInfo, UserInfoF
case 1:
throw new MissingProperty("Username is missing.");
}
}
}
}
@Override
public void prepareEntityUpdate(UserInfo user) throws DmPortalException {
verifyMandatoryParam(user);
if (passwordEntry != null && !passwordEntry.isEmpty()) {
user.setPassword(passwordEntry);
logger.debug("Will crypt provided password for user " + user.getUsername());
String cryptedPassword = CryptUtility.cryptPasswordWithPbkdf2(passwordEntry);
user.setPassword(cryptedPassword);
}
passwordEntry = null;
}
@Override
protected String getObjectAlreadyExistMessage(UserInfo user) {
@Override
protected String getObjectAlreadyExistMessage(UserInfo user) {
if (user == null) {
return null;
}
return "User " + user.getUsername() + " already exists.";
return "User " + user.getUsername() + " already exists.";
}
public String prepareSessionUserEdit(String viewPath) {
UserInfo sessionUser = (UserInfo) SessionUtility.getUser();
if (sessionUser == null) {
......@@ -288,7 +297,7 @@ public class UserInfoController extends CrudEntityController<UserInfo, UserInfoF
prepareEdit(sessionUser);
return viewPath + "?faces-redirect=true";
}
public String getPasswordEntry() {
return passwordEntry;
}
......@@ -300,10 +309,9 @@ public class UserInfoController extends CrudEntityController<UserInfo, UserInfoF
public boolean notSelected() {
return current == null;
}
@FacesConverter(forClass = UserInfo.class)
public static class UserInfoControllerConverter implements Converter
{
public static class UserInfoControllerConverter implements Converter {
@Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
......@@ -335,12 +343,11 @@ public class UserInfoController extends CrudEntityController<UserInfo, UserInfoF
if (object instanceof UserInfo) {
UserInfo o = (UserInfo) object;
return getStringKey(o.getId());
}
else {
} else {
throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + UserInfo.class.getName());
}
}
}
}
\ No newline at end of file
}
......@@ -28,7 +28,7 @@
<h:inputText id="email" value="#{userInfoObject.email}" title="Email" styleClass="entityDataText"/>
<h:outputLabel for="password" value="Password" styleClass="entityDataLabel"/>
<p:password id="password" value="#{userInfoObject.password}" title="Password" feedback="true" styleClass="entityDataText"/>
<p:password id="password" value="#{userInfoController.passwordEntry}" title="Password" feedback="true" styleClass="entityDataText"/>
<h:outputLabel for="globusUsername" value="Globus Username" styleClass="entityDataEmphasizedLabel"/>
<h:inputText id="globusUsername" value="#{userInfoObject.globusUsername}" title="Globus Username" styleClass="entityDataEmphasizedText"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment