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.PasswordPolicyNameException;
025: import com.liferay.portal.RequiredPasswordPolicyException;
026: import com.liferay.portal.kernel.util.Constants;
027: import com.liferay.portal.kernel.util.ParamUtil;
028: import com.liferay.portal.security.auth.PrincipalException;
029: import com.liferay.portal.service.PasswordPolicyServiceUtil;
030: import com.liferay.portal.struts.PortletAction;
031: import com.liferay.util.servlet.SessionErrors;
032:
033: import javax.portlet.ActionRequest;
034: import javax.portlet.ActionResponse;
035: import javax.portlet.PortletConfig;
036: import javax.portlet.RenderRequest;
037: import javax.portlet.RenderResponse;
038:
039: import org.apache.struts.action.ActionForm;
040: import org.apache.struts.action.ActionForward;
041: import org.apache.struts.action.ActionMapping;
042:
043: /**
044: * <a href="EditPasswordPolicyAction.java.html"><b><i>View Source</i></b></a>
045: *
046: * @author Scott Lee
047: *
048: */
049: public class EditPasswordPolicyAction extends PortletAction {
050:
051: public void processAction(ActionMapping mapping, ActionForm form,
052: PortletConfig config, ActionRequest req, ActionResponse res)
053: throws Exception {
054:
055: String cmd = ParamUtil.getString(req, Constants.CMD);
056:
057: try {
058: if (cmd.equals(Constants.ADD)
059: || cmd.equals(Constants.UPDATE)) {
060: updatePasswordPolicy(req);
061: } else if (cmd.equals(Constants.DELETE)) {
062: deletePasswordPolicy(req);
063: }
064:
065: sendRedirect(req, res);
066: } catch (Exception e) {
067: if (e instanceof PrincipalException) {
068: SessionErrors.add(req, e.getClass().getName());
069:
070: setForward(req, "portlet.enterprise_admin.error");
071: } else if (e instanceof PasswordPolicyNameException
072: || e instanceof NoSuchPasswordPolicyException
073: || e instanceof RequiredPasswordPolicyException) {
074:
075: SessionErrors.add(req, e.getClass().getName());
076:
077: if (cmd.equals(Constants.DELETE)) {
078: res.sendRedirect(ParamUtil.getString(req,
079: "redirect"));
080: }
081: } else {
082: throw e;
083: }
084: }
085: }
086:
087: public ActionForward render(ActionMapping mapping, ActionForm form,
088: PortletConfig config, RenderRequest req, RenderResponse res)
089: throws Exception {
090:
091: try {
092: ActionUtil.getPasswordPolicy(req);
093: } catch (Exception e) {
094: if (e instanceof NoSuchPasswordPolicyException
095: || e instanceof PrincipalException) {
096:
097: SessionErrors.add(req, e.getClass().getName());
098:
099: return mapping
100: .findForward("portlet.enterprise_admin.error");
101: } else {
102: throw e;
103: }
104: }
105:
106: return mapping.findForward(getForward(req,
107: "portlet.enterprise_admin.edit_password_policy"));
108: }
109:
110: protected void deletePasswordPolicy(ActionRequest req)
111: throws Exception {
112: long passwordPolicyId = ParamUtil.getLong(req,
113: "passwordPolicyId");
114:
115: PasswordPolicyServiceUtil
116: .deletePasswordPolicy(passwordPolicyId);
117: }
118:
119: protected void updatePasswordPolicy(ActionRequest req)
120: throws Exception {
121: long passwordPolicyId = ParamUtil.getLong(req,
122: "passwordPolicyId");
123:
124: String name = ParamUtil.getString(req, "name");
125: String description = ParamUtil.getString(req, "description");
126: boolean changeable = ParamUtil.getBoolean(req, "changeable");
127: boolean changeRequired = ParamUtil.getBoolean(req,
128: "changeRequired");
129: long minAge = ParamUtil.getLong(req, "minAge");
130: boolean checkSyntax = ParamUtil.getBoolean(req, "checkSyntax");
131: boolean allowDictionaryWords = ParamUtil.getBoolean(req,
132: "allowDictionaryWords");
133: int minLength = ParamUtil.getInteger(req, "minLength");
134: boolean history = ParamUtil.getBoolean(req, "history");
135: int historyCount = ParamUtil.getInteger(req, "historyCount");
136: boolean expireable = ParamUtil.getBoolean(req, "expireable");
137: long maxAge = ParamUtil.getLong(req, "maxAge");
138: long warningTime = ParamUtil.getLong(req, "warningTime");
139: int graceLimit = ParamUtil.getInteger(req, "graceLimit");
140: boolean lockout = ParamUtil.getBoolean(req, "lockout");
141: int maxFailure = ParamUtil.getInteger(req, "maxFailure");
142: long lockoutDuration = ParamUtil
143: .getLong(req, "lockoutDuration");
144: long resetFailureCount = ParamUtil.getLong(req,
145: "resetFailureCount");
146:
147: if (passwordPolicyId <= 0) {
148:
149: // Add password policy
150:
151: PasswordPolicyServiceUtil.addPasswordPolicy(name,
152: description, changeable, changeRequired, minAge,
153: checkSyntax, allowDictionaryWords, minLength,
154: history, historyCount, expireable, maxAge,
155: warningTime, graceLimit, lockout, maxFailure,
156: lockoutDuration, resetFailureCount);
157: } else {
158:
159: // Update password policy
160:
161: PasswordPolicyServiceUtil.updatePasswordPolicy(
162: passwordPolicyId, name, description, changeable,
163: changeRequired, minAge, checkSyntax,
164: allowDictionaryWords, minLength, history,
165: historyCount, expireable, maxAge, warningTime,
166: graceLimit, lockout, maxFailure, lockoutDuration,
167: resetFailureCount);
168: }
169: }
170:
171: }
|