001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.enterpriseadmin.action;
022:
023: import com.liferay.portal.NoSuchPasswordPolicyException;
024: import com.liferay.portal.kernel.util.Constants;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.kernel.util.StringUtil;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.security.auth.PrincipalException;
029: import com.liferay.portal.service.OrganizationServiceUtil;
030: import com.liferay.portal.service.UserServiceUtil;
031: import com.liferay.portal.struts.PortletAction;
032: import com.liferay.util.servlet.SessionErrors;
033:
034: import javax.portlet.ActionRequest;
035: import javax.portlet.ActionResponse;
036: import javax.portlet.PortletConfig;
037: import javax.portlet.RenderRequest;
038: import javax.portlet.RenderResponse;
039:
040: import org.apache.struts.action.ActionForm;
041: import org.apache.struts.action.ActionForward;
042: import org.apache.struts.action.ActionMapping;
043:
044: /**
045: * <a href="EditPasswordPolicyAssignmentsAction.java.html"><b><i>View Source</i>
046: * </b></a>
047: *
048: * @author Scott Lee
049: *
050: */
051: public class EditPasswordPolicyAssignmentsAction extends PortletAction {
052:
053: public void processAction(ActionMapping mapping, ActionForm form,
054: PortletConfig config, ActionRequest req, ActionResponse res)
055: throws Exception {
056:
057: String cmd = ParamUtil.getString(req, Constants.CMD);
058:
059: try {
060: if (cmd.equals("password_policy_organizations")) {
061: updatePasswordPolicyOrganizations(req);
062: } else if (cmd.equals("password_policy_users")) {
063: updatePasswordPolicyUsers(req);
064: }
065:
066: if (Validator.isNotNull(cmd)) {
067: String redirect = ParamUtil.getString(req,
068: "assignmentsRedirect");
069:
070: sendRedirect(req, res, redirect);
071: }
072: } catch (Exception e) {
073: if (e instanceof NoSuchPasswordPolicyException
074: || e instanceof PrincipalException) {
075:
076: SessionErrors.add(req, e.getClass().getName());
077:
078: setForward(req, "portlet.enterprise_admin.error");
079: } else {
080: throw e;
081: }
082: }
083: }
084:
085: public ActionForward render(ActionMapping mapping, ActionForm form,
086: PortletConfig config, RenderRequest req, RenderResponse res)
087: throws Exception {
088:
089: try {
090: ActionUtil.getPasswordPolicy(req);
091: } catch (Exception e) {
092: if (e instanceof NoSuchPasswordPolicyException
093: || e instanceof PrincipalException) {
094:
095: SessionErrors.add(req, e.getClass().getName());
096:
097: return mapping
098: .findForward("portlet.enterprise_admin.error");
099: } else {
100: throw e;
101: }
102: }
103:
104: return mapping
105: .findForward(getForward(req,
106: "portlet.enterprise_admin.edit_password_policy_assignments"));
107: }
108:
109: protected void updatePasswordPolicyOrganizations(ActionRequest req)
110: throws Exception {
111:
112: long passwordPolicyId = ParamUtil.getLong(req,
113: "passwordPolicyId");
114:
115: long[] addOrganizationIds = StringUtil.split(ParamUtil
116: .getString(req, "addOrganizationIds"), 0L);
117: long[] removeOrganizationIds = StringUtil.split(ParamUtil
118: .getString(req, "removeOrganizationIds"), 0L);
119:
120: OrganizationServiceUtil.addPasswordPolicyOrganizations(
121: passwordPolicyId, addOrganizationIds);
122: OrganizationServiceUtil.unsetPasswordPolicyOrganizations(
123: passwordPolicyId, removeOrganizationIds);
124: }
125:
126: protected void updatePasswordPolicyUsers(ActionRequest req)
127: throws Exception {
128:
129: long passwordPolicyId = ParamUtil.getLong(req,
130: "passwordPolicyId");
131:
132: long[] addUserIds = StringUtil.split(ParamUtil.getString(req,
133: "addUserIds"), 0L);
134: long[] removeUserIds = StringUtil.split(ParamUtil.getString(
135: req, "removeUserIds"), 0L);
136:
137: UserServiceUtil.addPasswordPolicyUsers(passwordPolicyId,
138: addUserIds);
139: UserServiceUtil.unsetPasswordPolicyUsers(passwordPolicyId,
140: removeUserIds);
141: }
142:
143: }
|