Index: lams_admin/conf/language/lams/ApplicationResources.properties =================================================================== RCS file: /usr/local/cvsroot/lams_admin/conf/language/lams/ApplicationResources.properties,v diff -u -r1.43 -r1.44 --- lams_admin/conf/language/lams/ApplicationResources.properties 28 Sep 2008 23:56:00 -0000 1.43 +++ lams_admin/conf/language/lams/ApplicationResources.properties 4 Oct 2008 03:37:34 -0000 1.44 @@ -74,6 +74,7 @@ admin.user.delete =Delete User admin.user.actions =Actions admin.user.import =Import Users +admin.user.authentication.method=Authentication Method label.spreadsheet =spreadsheet label.download.template =Download the template role.AUTHOR =Author Index: lams_admin/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== RCS file: /usr/local/cvsroot/lams_admin/conf/language/lams/ApplicationResources_en_AU.properties,v diff -u -r1.41 -r1.42 --- lams_admin/conf/language/lams/ApplicationResources_en_AU.properties 28 Sep 2008 23:56:00 -0000 1.41 +++ lams_admin/conf/language/lams/ApplicationResources_en_AU.properties 4 Oct 2008 03:37:34 -0000 1.42 @@ -74,6 +74,7 @@ admin.user.delete =Delete User admin.user.actions =Actions admin.user.import =Import Users +admin.user.authentication.method=Authentication Method label.spreadsheet =spreadsheet label.download.template =Download the template role.AUTHOR =Author Index: lams_admin/conf/xdoclet/struts-forms.xml =================================================================== RCS file: /usr/local/cvsroot/lams_admin/conf/xdoclet/struts-forms.xml,v diff -u -r1.28 -r1.29 --- lams_admin/conf/xdoclet/struts-forms.xml 4 Jan 2008 00:27:28 -0000 1.28 +++ lams_admin/conf/xdoclet/struts-forms.xml 4 Oct 2008 03:37:34 -0000 1.29 @@ -25,6 +25,7 @@ + Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java,v diff -u -r1.47 -r1.48 --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java 29 Feb 2008 06:11:51 -0000 1.47 +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java 4 Oct 2008 03:37:34 -0000 1.48 @@ -40,6 +40,7 @@ import org.lamsfoundation.lams.admin.AdminConstants; import org.lamsfoundation.lams.admin.service.AdminServiceProxy; import org.lamsfoundation.lams.admin.web.dto.UserOrgRoleDTO; +import org.lamsfoundation.lams.usermanagement.AuthenticationMethod; import org.lamsfoundation.lams.usermanagement.Organisation; import org.lamsfoundation.lams.usermanagement.OrganisationState; import org.lamsfoundation.lams.usermanagement.OrganisationType; @@ -56,16 +57,12 @@ /** * @author Jun-Dir Liew - * + * * Created at 17:00:18 on 13/06/2006 */ /** - * @struts:action path="/user" - * name="UserForm" - * scope="request" - * parameter="method" - * validate="false" + * @struts:action path="/user" name="UserForm" scope="request" parameter="method" validate="false" * * @struts:action-forward name="user" path=".user" * @struts:action-forward name="userlist" path="/usermanage.do" @@ -75,263 +72,262 @@ */ public class UserAction extends LamsDispatchAction { - private static Logger log = Logger.getLogger(UserAction.class); - private IUserManagementService service; - private MessageService messageService; - private static List locales; - - private void initServices() { - if (service==null) { - service = AdminServiceProxy.getService(getServlet().getServletContext()); - } - if (messageService==null) { - messageService = AdminServiceProxy.getMessageService(getServlet().getServletContext()); - } + private static Logger log = Logger.getLogger(UserAction.class); + private IUserManagementService service; + private MessageService messageService; + private static List locales; + private static List authenticationMethods; + + private void initServices() { + if (service == null) { + service = AdminServiceProxy.getService(getServlet().getServletContext()); } - - public ActionForward edit(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws Exception { - - initServices(); - if (locales==null) { - locales = service.findAll(SupportedLocale.class); - Collections.sort(locales); - } - - DynaActionForm userForm = (DynaActionForm)form; - Integer orgId = WebUtil.readIntParam(request,"orgId",true); - Integer userId = WebUtil.readIntParam(request,"userId",true); - - // test requestor's permission - Organisation org = null; - Boolean canEdit = service.isUserGlobalGroupAdmin(); - if (orgId!=null) { - org = (Organisation)service.findById(Organisation.class,orgId); - if (!canEdit) { - OrganisationType orgType = org.getOrganisationType(); - Integer orgIdOfCourse = (orgType.getOrganisationTypeId().equals(OrganisationType.CLASS_TYPE)) - ? org.getParentOrganisation().getOrganisationId() : orgId; - User requestor = (User)service.getUserByLogin(request.getRemoteUser()); - if (service.isUserInRole(requestor.getUserId(), orgIdOfCourse, Role.GROUP_ADMIN) - || service.isUserInRole(requestor.getUserId(), orgIdOfCourse, Role.GROUP_MANAGER)) { - Organisation course = (Organisation)service.findById(Organisation.class, orgIdOfCourse); - canEdit = course.getCourseAdminCanAddNewUsers(); - } - } - } - - if (!(canEdit || request.isUserInRole(Role.SYSADMIN))) { - request.setAttribute("errorName", "UserAction"); - request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); - return mapping.findForward("error"); - } + if (messageService == null) { + messageService = AdminServiceProxy.getMessageService(getServlet().getServletContext()); + } + } - // editing a user - if (userId!=null && userId!=0) { - User user = (User)service.findById(User.class, userId); - log.debug("got userid to edit: "+userId); - BeanUtils.copyProperties(userForm, user); - userForm.set("password", null); - SupportedLocale locale = user.getLocale(); - userForm.set("localeId", locale.getLocaleId()); - // set user's organisations to display - request.setAttribute("userOrgRoles", getUserOrgRoles(user)); - request.setAttribute("globalRoles", getGlobalRoles(user)); - } else { // create a user - try { - SupportedLocale locale = LanguageUtil.getDefaultLocale(); - userForm.set("localeId", locale.getLocaleId()); - } catch(Exception e) { - log.debug(e); - } - } - userForm.set("orgId", (org==null ? null : org.getOrganisationId())); - - // for breadcrumb links - if (org!=null) { - request.setAttribute("orgName",org.getName()); - Organisation parentOrg = org.getParentOrganisation(); - if (parentOrg!=null && !parentOrg.equals(service.getRootOrganisation())) { - request.setAttribute("pOrgId", parentOrg.getOrganisationId()); - request.setAttribute("parentName", parentOrg.getName()); - } - } - - request.setAttribute("locales",locales); + public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { - return mapping.findForward("user"); + initServices(); + if (UserAction.locales == null) { + UserAction.locales = service.findAll(SupportedLocale.class); + Collections.sort(UserAction.locales); } - - // display user's global roles, if any - private UserOrgRoleDTO getGlobalRoles(User user) { - initServices(); - UserOrganisation uo = service.getUserOrganisation(user.getUserId(), - service.getRootOrganisation().getOrganisationId()); - if (uo==null) return null; - UserOrgRoleDTO uorDTO = new UserOrgRoleDTO(); - List roles = new ArrayList(); - for (Object uor : uo.getUserOrganisationRoles()) - roles.add(((UserOrganisationRole)uor).getRole().getName()); - Collections.sort(roles); - uorDTO.setOrgName(uo.getOrganisation().getName()); - uorDTO.setRoles(roles); - return uorDTO; + if (UserAction.authenticationMethods == null) { + UserAction.authenticationMethods = service.findAll(AuthenticationMethod.class); } - - // display user's organisations and roles in them - private List getUserOrgRoles(User user) { - - initServices(); - List uorDTOs = new ArrayList(); - List uos = service.getUserOrganisationsForUserByTypeAndStatus( - user.getLogin(), - OrganisationType.COURSE_TYPE, - OrganisationState.ACTIVE); - for (UserOrganisation uo : uos) { - UserOrgRoleDTO uorDTO = new UserOrgRoleDTO(); - List roles = new ArrayList(); - for (Object uor : uo.getUserOrganisationRoles()) - roles.add(((UserOrganisationRole)uor).getRole().getName()); - Collections.sort(roles); - uorDTO.setOrgName(uo.getOrganisation().getName()); - uorDTO.setRoles(roles); - List childDTOs = new ArrayList(); - List childuos = service.getUserOrganisationsForUserByTypeAndStatusAndParent( - user.getLogin(), - OrganisationType.CLASS_TYPE, - OrganisationState.ACTIVE, - uo.getOrganisation().getOrganisationId()); - for (UserOrganisation childuo : childuos) { - UserOrgRoleDTO childDTO = new UserOrgRoleDTO(); - List childroles = new ArrayList(); - for (Object uor : childuo.getUserOrganisationRoles()) - childroles.add(((UserOrganisationRole)uor).getRole().getName()); - Collections.sort(childroles); - childDTO.setOrgName(childuo.getOrganisation().getName()); - childDTO.setRoles(childroles); - childDTOs.add(childDTO); - } - uorDTO.setChildDTOs(childDTOs); - uorDTOs.add(uorDTO); + + DynaActionForm userForm = (DynaActionForm) form; + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + Integer userId = WebUtil.readIntParam(request, "userId", true); + + // test requestor's permission + Organisation org = null; + Boolean canEdit = service.isUserGlobalGroupAdmin(); + if (orgId != null) { + org = (Organisation) service.findById(Organisation.class, orgId); + if (!canEdit) { + OrganisationType orgType = org.getOrganisationType(); + Integer orgIdOfCourse = orgType.getOrganisationTypeId().equals(OrganisationType.CLASS_TYPE) ? org + .getParentOrganisation().getOrganisationId() : orgId; + User requestor = service.getUserByLogin(request.getRemoteUser()); + if (service.isUserInRole(requestor.getUserId(), orgIdOfCourse, Role.GROUP_ADMIN) + || service.isUserInRole(requestor.getUserId(), orgIdOfCourse, Role.GROUP_MANAGER)) { + Organisation course = (Organisation) service.findById(Organisation.class, orgIdOfCourse); + canEdit = course.getCourseAdminCanAddNewUsers(); } - - return uorDTOs; + } } - - // determine whether to disable or delete user based on their lams data - public ActionForward remove(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws Exception { - - initServices(); - - if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { - request.setAttribute("errorName","UserAction"); - request.setAttribute("errorMessage",messageService.getMessage("error.authorisation")); - return mapping.findForward("error"); - } - - Integer orgId = WebUtil.readIntParam(request,"orgId",true); - Integer userId = WebUtil.readIntParam(request,"userId"); - User user = (User)service.findById(User.class,userId); - - Boolean hasData = service.userHasData(user); - request.setAttribute("method", (hasData?"disable":"delete")); - request.setAttribute("orgId",orgId); - request.setAttribute("userId",userId); - return mapping.findForward("remove"); + if (!(canEdit || request.isUserInRole(Role.SYSADMIN))) { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return mapping.findForward("error"); } - - public ActionForward disable(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws Exception { - - initServices(); - - if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { - request.setAttribute("errorName","UserAction"); - request.setAttribute("errorMessage",messageService.getMessage("error.authorisation")); - return mapping.findForward("error"); - } - - Integer orgId = WebUtil.readIntParam(request,"orgId",true); - Integer userId = WebUtil.readIntParam(request,"userId"); - service.disableUser(userId); - String[] args = new String[1]; - args[0] = userId.toString(); - String message = messageService.getMessage("audit.user.disable", args); - AdminServiceProxy.getAuditService(getServlet().getServletContext()).log(AdminConstants.MODULE_NAME, message); - - if (orgId==null || orgId==0) { - return mapping.findForward("usersearch"); - } else { - request.setAttribute("org",orgId); - return mapping.findForward("userlist"); - } + + // editing a user + if (userId != null && userId != 0) { + User user = (User) service.findById(User.class, userId); + UserAction.log.debug("got userid to edit: " + userId); + BeanUtils.copyProperties(userForm, user); + userForm.set("password", null); + SupportedLocale locale = user.getLocale(); + userForm.set("localeId", locale.getLocaleId()); + + AuthenticationMethod authenticationMethod = user.getAuthenticationMethod(); + userForm.set("authenticationMethodId", authenticationMethod.getAuthenticationMethodId()); + // set user's organisations to display + request.setAttribute("userOrgRoles", getUserOrgRoles(user)); + request.setAttribute("globalRoles", getGlobalRoles(user)); + } else { // create a user + try { + SupportedLocale locale = LanguageUtil.getDefaultLocale(); + userForm.set("localeId", locale.getLocaleId()); + } catch (Exception e) { + UserAction.log.debug(e); + } } - - public ActionForward delete(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws Exception { - - initServices(); - - if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { - request.setAttribute("errorName","UserAction"); - request.setAttribute("errorMessage",messageService.getMessage("error.authorisation")); - return mapping.findForward("error"); - } - - Integer orgId = WebUtil.readIntParam(request,"orgId",true); - Integer userId = WebUtil.readIntParam(request,"userId"); - try { - service.removeUser(userId); - } catch (Exception e) { - request.setAttribute("errorName","UserAction"); - request.setAttribute("errorMessage",e.getMessage()); - return mapping.findForward("error"); - } - String[] args = new String[1]; - args[0] = userId.toString(); - String message = messageService.getMessage("audit.user.delete", args); - AdminServiceProxy.getAuditService(getServlet().getServletContext()).log(AdminConstants.MODULE_NAME, message); - - if (orgId==null || orgId==0) { - return mapping.findForward("usersearch"); - } else { - request.setAttribute("org",orgId); - return mapping.findForward("userlist"); - } + userForm.set("orgId", (org == null ? null : org.getOrganisationId())); + + // for breadcrumb links + if (org != null) { + request.setAttribute("orgName", org.getName()); + Organisation parentOrg = org.getParentOrganisation(); + if (parentOrg != null && !parentOrg.equals(service.getRootOrganisation())) { + request.setAttribute("pOrgId", parentOrg.getOrganisationId()); + request.setAttribute("parentName", parentOrg.getName()); + } } - - // called from disabled users screen - public ActionForward enable(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws Exception { - - initServices(); - - if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { - request.setAttribute("errorName","UserAction"); - request.setAttribute("errorMessage",messageService.getMessage("error.authorisation")); - return mapping.findForward("error"); + + request.setAttribute("locales", UserAction.locales); + request.setAttribute("authenticationMethods", UserAction.authenticationMethods); + + return mapping.findForward("user"); + } + + // display user's global roles, if any + private UserOrgRoleDTO getGlobalRoles(User user) { + initServices(); + UserOrganisation uo = service.getUserOrganisation(user.getUserId(), service.getRootOrganisation() + .getOrganisationId()); + if (uo == null) { + return null; + } + UserOrgRoleDTO uorDTO = new UserOrgRoleDTO(); + List roles = new ArrayList(); + for (Object uor : uo.getUserOrganisationRoles()) { + roles.add(((UserOrganisationRole) uor).getRole().getName()); + } + Collections.sort(roles); + uorDTO.setOrgName(uo.getOrganisation().getName()); + uorDTO.setRoles(roles); + return uorDTO; + } + + // display user's organisations and roles in them + private List getUserOrgRoles(User user) { + + initServices(); + List uorDTOs = new ArrayList(); + List uos = service.getUserOrganisationsForUserByTypeAndStatus(user.getLogin(), + OrganisationType.COURSE_TYPE, OrganisationState.ACTIVE); + for (UserOrganisation uo : uos) { + UserOrgRoleDTO uorDTO = new UserOrgRoleDTO(); + List roles = new ArrayList(); + for (Object uor : uo.getUserOrganisationRoles()) { + roles.add(((UserOrganisationRole) uor).getRole().getName()); + } + Collections.sort(roles); + uorDTO.setOrgName(uo.getOrganisation().getName()); + uorDTO.setRoles(roles); + List childDTOs = new ArrayList(); + List childuos = service.getUserOrganisationsForUserByTypeAndStatusAndParent(user + .getLogin(), OrganisationType.CLASS_TYPE, OrganisationState.ACTIVE, uo.getOrganisation() + .getOrganisationId()); + for (UserOrganisation childuo : childuos) { + UserOrgRoleDTO childDTO = new UserOrgRoleDTO(); + List childroles = new ArrayList(); + for (Object uor : childuo.getUserOrganisationRoles()) { + childroles.add(((UserOrganisationRole) uor).getRole().getName()); } - - Integer userId = WebUtil.readIntParam(request,"userId",true); - User user = (User)service.findById(User.class,userId); - - log.debug("enabling user: "+userId); - user.setDisabledFlag(false); - service.save(user); - - return mapping.findForward("disabledlist"); + Collections.sort(childroles); + childDTO.setOrgName(childuo.getOrganisation().getName()); + childDTO.setRoles(childroles); + childDTOs.add(childDTO); + } + uorDTO.setChildDTOs(childDTOs); + uorDTOs.add(uorDTO); } + return uorDTOs; + } + + // determine whether to disable or delete user based on their lams data + public ActionForward remove(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + initServices(); + + if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return mapping.findForward("error"); + } + + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + Integer userId = WebUtil.readIntParam(request, "userId"); + User user = (User) service.findById(User.class, userId); + + Boolean hasData = service.userHasData(user); + + request.setAttribute("method", (hasData ? "disable" : "delete")); + request.setAttribute("orgId", orgId); + request.setAttribute("userId", userId); + return mapping.findForward("remove"); + } + + public ActionForward disable(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + initServices(); + + if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return mapping.findForward("error"); + } + + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + Integer userId = WebUtil.readIntParam(request, "userId"); + service.disableUser(userId); + String[] args = new String[1]; + args[0] = userId.toString(); + String message = messageService.getMessage("audit.user.disable", args); + AdminServiceProxy.getAuditService(getServlet().getServletContext()).log(AdminConstants.MODULE_NAME, message); + + if (orgId == null || orgId == 0) { + return mapping.findForward("usersearch"); + } else { + request.setAttribute("org", orgId); + return mapping.findForward("userlist"); + } + } + + public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + initServices(); + + if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return mapping.findForward("error"); + } + + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + Integer userId = WebUtil.readIntParam(request, "userId"); + try { + service.removeUser(userId); + } catch (Exception e) { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", e.getMessage()); + return mapping.findForward("error"); + } + String[] args = new String[1]; + args[0] = userId.toString(); + String message = messageService.getMessage("audit.user.delete", args); + AdminServiceProxy.getAuditService(getServlet().getServletContext()).log(AdminConstants.MODULE_NAME, message); + + if (orgId == null || orgId == 0) { + return mapping.findForward("usersearch"); + } else { + request.setAttribute("org", orgId); + return mapping.findForward("userlist"); + } + } + + // called from disabled users screen + public ActionForward enable(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + initServices(); + + if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return mapping.findForward("error"); + } + + Integer userId = WebUtil.readIntParam(request, "userId", true); + User user = (User) service.findById(User.class, userId); + + UserAction.log.debug("enabling user: " + userId); + user.setDisabledFlag(false); + service.save(user); + + return mapping.findForward("disabledlist"); + } + } \ No newline at end of file Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserSaveAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserSaveAction.java,v diff -u -r1.33 -r1.34 --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserSaveAction.java 17 Sep 2007 07:00:02 -0000 1.33 +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserSaveAction.java 4 Oct 2008 03:37:34 -0000 1.34 @@ -25,7 +25,6 @@ package org.lamsfoundation.lams.admin.web; import java.util.Date; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -44,13 +43,10 @@ import org.apache.struts.action.DynaActionForm; import org.lamsfoundation.lams.admin.AdminConstants; import org.lamsfoundation.lams.admin.service.AdminServiceProxy; -import org.lamsfoundation.lams.themes.CSSThemeVisualElement; import org.lamsfoundation.lams.usermanagement.AuthenticationMethod; import org.lamsfoundation.lams.usermanagement.SupportedLocale; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; -import org.lamsfoundation.lams.util.Configuration; -import org.lamsfoundation.lams.util.ConfigurationKeys; import org.lamsfoundation.lams.util.HashUtil; /** @@ -62,8 +58,7 @@ /** * struts doclets * - * @struts:action path="/usersave" name="UserForm" input=".user" scope="request" - * validate="false" + * @struts:action path="/usersave" name="UserForm" input=".user" scope="request" validate="false" * * @struts:action-forward name="user" path="/user.do?method=edit" * @struts:action-forward name="userlist" path="/usermanage.do" @@ -72,132 +67,138 @@ */ public class UserSaveAction extends Action { - private static Logger log = Logger.getLogger(UserSaveAction.class); - private static IUserManagementService service; + private static Logger log = Logger.getLogger(UserSaveAction.class); + private static IUserManagementService service; - @SuppressWarnings("unchecked") - public ActionForward execute(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) - throws Exception { + @Override + @SuppressWarnings("unchecked") + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { - service = AdminServiceProxy.getService(getServlet().getServletContext()); - - // action input - ActionMessages errors = new ActionMessages(); - DynaActionForm userForm = (DynaActionForm) form; - Integer orgId = (Integer) userForm.get("orgId"); - Integer userId = (Integer) userForm.get("userId"); - - log.debug("orgId: " + orgId); - Boolean edit = false; - Boolean passwordChanged = true; - SupportedLocale locale = (SupportedLocale)service.findById(SupportedLocale.class, (Integer)userForm.get("localeId")); - log.debug("locale: " + locale); - - if (isCancelled(request)) { - if (orgId==null || orgId==0) { - return mapping.findForward("usersearch"); - } - request.setAttribute("org", orgId); - return mapping.findForward("userlist"); - } + UserSaveAction.service = AdminServiceProxy.getService(getServlet().getServletContext()); - User user = null; - if (userId != 0) { - edit = true; - user = (User)service.findById(User.class, userId); - } + // action input + ActionMessages errors = new ActionMessages(); + DynaActionForm userForm = (DynaActionForm) form; + Integer orgId = (Integer) userForm.get("orgId"); + Integer userId = (Integer) userForm.get("userId"); - // (dyna)form validation - userForm.set("login", userForm.getString("login").trim()); - if ((userForm.get("login") == null) || (userForm.getString("login").length() == 0)) { - errors.add("login", new ActionMessage("error.login.required")); - } - if (service.getUserByLogin(userForm.getString("login")) != null) { - if (user != null && StringUtils.equals(user.getLogin(),userForm.getString("login"))) { - // login exists - it's the user's current login - } else { - errors.add("login", new ActionMessage("error.login.unique", "("+userForm.getString("login")+")")); - } - } - if (!StringUtils.equals((String)userForm.get("password"),((String)userForm.get("password2")))) { - errors.add("password", new ActionMessage("error.newpassword.mismatch")); - } - if ((userForm.get("password") == null) || (userForm.getString("password").trim().length() == 0)) { - passwordChanged = false; - if (!edit) errors.add("password", new ActionMessage("error.password.required")); - } - if ((userForm.get("firstName") == null) || (userForm.getString("firstName").trim().length() == 0)) { - errors.add("firstName", new ActionMessage("error.firstname.required")); - } - if ((userForm.get("lastName") == null) || (userForm.getString("lastName").trim().length() == 0)) { - errors.add("lastName", new ActionMessage("error.lastname.required")); - } - if ((userForm.get("email") == null) || (userForm.getString("email").trim().length() == 0)) { - errors.add("email", new ActionMessage("error.email.required")); + UserSaveAction.log.debug("orgId: " + orgId); + Boolean edit = false; + Boolean passwordChanged = true; + SupportedLocale locale = (SupportedLocale) UserSaveAction.service.findById(SupportedLocale.class, + (Integer) userForm.get("localeId")); + AuthenticationMethod authenticationMethod = (AuthenticationMethod) UserSaveAction.service.findById( + AuthenticationMethod.class, (Integer) userForm.get("authenticationMethodId")); + UserSaveAction.log.debug("locale: " + locale); + UserSaveAction.log.debug("authenticationMethod:" + authenticationMethod); + + if (isCancelled(request)) { + if (orgId == null || orgId == 0) { + return mapping.findForward("usersearch"); + } + request.setAttribute("org", orgId); + return mapping.findForward("userlist"); + } + + User user = null; + if (userId != 0) { + edit = true; + user = (User) UserSaveAction.service.findById(User.class, userId); + } + + // (dyna)form validation + userForm.set("login", userForm.getString("login").trim()); + if (userForm.get("login") == null || userForm.getString("login").length() == 0) { + errors.add("login", new ActionMessage("error.login.required")); + } + if (UserSaveAction.service.getUserByLogin(userForm.getString("login")) != null) { + if (user != null && StringUtils.equals(user.getLogin(), userForm.getString("login"))) { + // login exists - it's the user's current login + } else { + errors.add("login", new ActionMessage("error.login.unique", "(" + userForm.getString("login") + ")")); + } + } + if (!StringUtils.equals((String) userForm.get("password"), ((String) userForm.get("password2")))) { + errors.add("password", new ActionMessage("error.newpassword.mismatch")); + } + if (userForm.get("password") == null || userForm.getString("password").trim().length() == 0) { + passwordChanged = false; + if (!edit) { + errors.add("password", new ActionMessage("error.password.required")); + } + } + if (userForm.get("firstName") == null || userForm.getString("firstName").trim().length() == 0) { + errors.add("firstName", new ActionMessage("error.firstname.required")); + } + if (userForm.get("lastName") == null || userForm.getString("lastName").trim().length() == 0) { + errors.add("lastName", new ActionMessage("error.lastname.required")); + } + if (userForm.get("email") == null || userForm.getString("email").trim().length() == 0) { + errors.add("email", new ActionMessage("error.email.required")); + } else { + Pattern p = Pattern.compile(".+@.+\\.[a-z]+"); + Matcher m = p.matcher(userForm.getString("email")); + if (!m.matches()) { + errors.add("email", new ActionMessage("error.valid.email.required")); + } + } + + if (errors.isEmpty()) { + if (edit) { // edit user + UserSaveAction.log.debug("editing userId: " + userId); + // hash the new password if necessary, and audit the fact + if (passwordChanged) { + UserSaveAction.service.auditPasswordChanged(user, AdminConstants.MODULE_NAME); + userForm.set("password", HashUtil.sha1((String) userForm.get("password"))); } else { - Pattern p = Pattern.compile(".+@.+\\.[a-z]+"); - Matcher m = p.matcher(userForm.getString("email")); - if (!m.matches()) { - errors.add("email", new ActionMessage("error.valid.email.required")); - } + userForm.set("password", user.getPassword()); } - + BeanUtils.copyProperties(user, userForm); + user.setLocale(locale); + user.setAuthenticationMethod(authenticationMethod); + } else { // create user + user = new User(); + userForm.set("password", HashUtil.sha1((String) userForm.get("password"))); + BeanUtils.copyProperties(user, userForm); + UserSaveAction.log.debug("creating user... new login: " + user.getLogin()); if (errors.isEmpty()) { - if (edit) { // edit user - log.debug("editing userId: " + userId); - // hash the new password if necessary, and audit the fact - if (passwordChanged) { - service.auditPasswordChanged(user, AdminConstants.MODULE_NAME); - userForm.set("password", HashUtil.sha1((String)userForm.get("password"))); - } else { - userForm.set("password", user.getPassword()); - } - BeanUtils.copyProperties(user, userForm); - user.setLocale(locale); - } else { // create user - user = new User(); - userForm.set("password", HashUtil.sha1((String)userForm.get("password"))); - BeanUtils.copyProperties(user, userForm); - log.debug("creating user... new login: " + user.getLogin()); - if (errors.isEmpty()) { - // TODO set flash/html themes according to user input instead of server default. - user.setFlashTheme(service.getDefaultFlashTheme()); - user.setHtmlTheme(service.getDefaultHtmlTheme()); - user.setDisabledFlag(false); - user.setCreateDate(new Date()); - user.setAuthenticationMethod((AuthenticationMethod)service.findByProperty(AuthenticationMethod.class, - "authenticationMethodName","LAMS-Database").get(0)); - user.setUserId(null); - user.setLocale(locale); - service.save(user); - - // make 'create user' audit log entry - service.auditUserCreated(user, AdminConstants.MODULE_NAME); - - log.debug("user: " + user.toString()); - } - } - } + // TODO set flash/html themes according to user input instead of server default. + user.setFlashTheme(UserSaveAction.service.getDefaultFlashTheme()); + user.setHtmlTheme(UserSaveAction.service.getDefaultHtmlTheme()); + user.setDisabledFlag(false); + user.setCreateDate(new Date()); + user.setAuthenticationMethod((AuthenticationMethod) UserSaveAction.service.findByProperty( + AuthenticationMethod.class, "authenticationMethodName", "LAMS-Database").get(0)); + user.setUserId(null); + user.setLocale(locale); + UserSaveAction.service.save(user); - - if (errors.isEmpty()) { - if (orgId==null || orgId==0) { - return mapping.findForward("usersearch"); - } - if (edit) { - request.setAttribute("org", orgId); - return mapping.findForward("userlist"); - } else { - request.setAttribute("orgId", orgId); - request.setAttribute("userId", user.getUserId()); - return mapping.findForward("userroles"); - } - } else { - saveErrors(request, errors); - request.setAttribute("orgId", orgId); - return mapping.findForward("user"); + // make 'create user' audit log entry + UserSaveAction.service.auditUserCreated(user, AdminConstants.MODULE_NAME); + + UserSaveAction.log.debug("user: " + user.toString()); } + } } - + + if (errors.isEmpty()) { + if (orgId == null || orgId == 0) { + return mapping.findForward("usersearch"); + } + if (edit) { + request.setAttribute("org", orgId); + return mapping.findForward("userlist"); + } else { + request.setAttribute("orgId", orgId); + request.setAttribute("userId", user.getUserId()); + return mapping.findForward("userroles"); + } + } else { + saveErrors(request, errors); + request.setAttribute("orgId", orgId); + return mapping.findForward("user"); + } + } + } Index: lams_admin/web/user.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_admin/web/user.jsp,v diff -u -r1.25 -r1.26 --- lams_admin/web/user.jsp 18 Jan 2008 06:31:14 -0000 1.25 +++ lams_admin/web/user.jsp 4 Oct 2008 03:37:34 -0000 1.26 @@ -47,6 +47,18 @@ + : + + + + + + + + + + + : Index: lams_build/lib/lams/lams-admin.jar =================================================================== RCS file: /usr/local/cvsroot/lams_build/lib/lams/lams-admin.jar,v diff -u -r1.2 -r1.3 Binary files differ