/* * @(#)ManageUsersAction.java * * Copyright 2009 Instituto Superior Tecnico * Founding Authors: João Figueiredo, Luis Cruz, Paulo Abrantes, Susana Fernandes * * https://fenix-ashes.ist.utl.pt/ * * This file is part of the Bennu Web Application Infrastructure. * * The Bennu Web Application Infrastructure is free software: you can * redistribute it and/or modify it under the terms of the GNU Lesser General * Public License as published by the Free Software Foundation, either version * 3 of the License, or (at your option) any later version. * * Bennu is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Bennu. If not, see . * */ package pt.ist.bennu.manager.presentation.actions; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import pt.ist.bennu.core.annotation.Functionality; import pt.ist.bennu.core.domain.RoleType; import pt.ist.bennu.core.domain.SearchUsers; import pt.ist.bennu.core.domain.User; import pt.ist.bennu.core.domain.groups.People; import pt.ist.bennu.core.presentation.actions.ContextBaseAction; import pt.ist.bennu.core.security.UserView; import pt.ist.renderers.utils.RenderUtils; import pt.ist.struts.dispatch.annotation.Mapping; /** * * @author Luis Cruz * */ @Mapping(path = "/manageUsers") public class ManageUsersAction extends ContextBaseAction { @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { final User user = UserView.getUser(); if (user == null || !user.hasRoleType(RoleType.MANAGER)) { throw new Error("unauthorized.access"); } return super.execute(mapping, form, request, response); } @Functionality(bundle = "resources/BennuManagerResources", groupKey = "label.application", key = "label.application.users") public ActionForward searchUsers(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) { SearchUsers searchUsers = RenderUtils.getRenderedObject("searchUsers"); if (searchUsers == null) { searchUsers = new SearchUsers(); final User user = UserView.getUser(); if (user != null) { searchUsers.setUser(user); searchUsers.setUsername(user.getUsername()); } } request.setAttribute("searchUsers", searchUsers); return forward(request, "/myorg/searchUsers.jsp"); } public ActionForward generatePassword(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) { final User user = getDomainObject(request, "userId"); user.generatePassword(); request.setAttribute("password", user.getPassword()); final SearchUsers searchUsers = new SearchUsers(); searchUsers.setUser(user); searchUsers.setUsername(user.getUsername()); request.setAttribute("searchUsers", searchUsers); return forward(request, "/myorg/searchUsers.jsp"); } public ActionForward prepareCreateNewUser(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) { final SearchUsers searchUsers = new SearchUsers(); request.setAttribute("searchUsers", searchUsers); return forward(request, "/myorg/createNewUser.jsp"); } public ActionForward createNewUser(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) { final SearchUsers searchUsers = RenderUtils.getRenderedObject("searchUsers"); final User user = User.createNewUser(searchUsers.getUsername()); searchUsers.setUser(user); return searchUsers(mapping, form, request, response); } public ActionForward prepareAddGroup(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) { final User user = getDomainObject(request, "userId"); request.setAttribute("user", user); request.setAttribute("roleTypes", RoleType.values()); return forward(request, "/myorg/addGroup.jsp"); } public ActionForward addGroup(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) { final User user = getDomainObject(request, "userId"); final String roleTypeString = request.getParameter("roleType"); final RoleType roleType = RoleType.valueOf(roleTypeString); user.addRoleType(roleType); final SearchUsers searchUsers = new SearchUsers(); searchUsers.setUser(user); searchUsers.setUsername(user.getUsername()); request.setAttribute("searchUsers", searchUsers); return forward(request, "/myorg/searchUsers.jsp"); } public ActionForward removeGroup(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) { final User user = getDomainObject(request, "userId"); final SearchUsers searchUsers = new SearchUsers(); searchUsers.setUser(user); searchUsers.setUsername(user.getUsername()); request.setAttribute("searchUsers", searchUsers); final People people = getDomainObject(request, "peopleId"); user.removePeopleGroups(people); return forward(request, "/myorg/searchUsers.jsp"); } public ActionForward editUser(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) { final User user = getDomainObject(request, "userId"); request.setAttribute("user", user); return forward(request, "/myorg/editUser.jsp"); } public ActionForward forwardToSearchUser(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) { final User user = getDomainObject(request, "userId"); final SearchUsers searchUsers = new SearchUsers(); searchUsers.setUser(user); searchUsers.setUsername(user.getUsername()); request.setAttribute("searchUsers", searchUsers); return forward(request, "/myorg/searchUsers.jsp"); } public ActionForward changePassword(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) { final User user = getDomainObject(request, "userId"); request.setAttribute("user", user); return forward(request, "/myorg/changePassword.jsp"); } }