001
014
015 package com.liferay.portlet.enterpriseadmin.action;
016
017 import com.liferay.portal.DuplicatePasswordPolicyException;
018 import com.liferay.portal.NoSuchPasswordPolicyException;
019 import com.liferay.portal.PasswordPolicyNameException;
020 import com.liferay.portal.RequiredPasswordPolicyException;
021 import com.liferay.portal.kernel.servlet.SessionErrors;
022 import com.liferay.portal.kernel.util.Constants;
023 import com.liferay.portal.kernel.util.ParamUtil;
024 import com.liferay.portal.security.auth.PrincipalException;
025 import com.liferay.portal.service.PasswordPolicyServiceUtil;
026 import com.liferay.portal.struts.PortletAction;
027
028 import javax.portlet.ActionRequest;
029 import javax.portlet.ActionResponse;
030 import javax.portlet.PortletConfig;
031 import javax.portlet.RenderRequest;
032 import javax.portlet.RenderResponse;
033
034 import org.apache.struts.action.ActionForm;
035 import org.apache.struts.action.ActionForward;
036 import org.apache.struts.action.ActionMapping;
037
038
041 public class EditPasswordPolicyAction extends PortletAction {
042
043 public void processAction(
044 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
045 ActionRequest actionRequest, ActionResponse actionResponse)
046 throws Exception {
047
048 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
049
050 try {
051 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
052 updatePasswordPolicy(actionRequest);
053 }
054 else if (cmd.equals(Constants.DELETE)) {
055 deletePasswordPolicy(actionRequest);
056 }
057
058 sendRedirect(actionRequest, actionResponse);
059 }
060 catch (Exception e) {
061 if (e instanceof PrincipalException) {
062 SessionErrors.add(actionRequest, e.getClass().getName());
063
064 setForward(actionRequest, "portlet.enterprise_admin.error");
065 }
066 else if (e instanceof DuplicatePasswordPolicyException ||
067 e instanceof PasswordPolicyNameException ||
068 e instanceof NoSuchPasswordPolicyException ||
069 e instanceof RequiredPasswordPolicyException) {
070
071 SessionErrors.add(actionRequest, e.getClass().getName());
072
073 if (cmd.equals(Constants.DELETE)) {
074 actionResponse.sendRedirect(
075 ParamUtil.getString(actionRequest, "redirect"));
076 }
077 }
078 else {
079 throw e;
080 }
081 }
082 }
083
084 public ActionForward render(
085 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
086 RenderRequest renderRequest, RenderResponse renderResponse)
087 throws Exception {
088
089 try {
090 ActionUtil.getPasswordPolicy(renderRequest);
091 }
092 catch (Exception e) {
093 if (e instanceof NoSuchPasswordPolicyException ||
094 e instanceof PrincipalException) {
095
096 SessionErrors.add(renderRequest, e.getClass().getName());
097
098 return mapping.findForward("portlet.enterprise_admin.error");
099 }
100 else {
101 throw e;
102 }
103 }
104
105 return mapping.findForward(getForward(
106 renderRequest, "portlet.enterprise_admin.edit_password_policy"));
107 }
108
109 protected void deletePasswordPolicy(ActionRequest actionRequest)
110 throws Exception {
111
112 long passwordPolicyId = ParamUtil.getLong(
113 actionRequest, "passwordPolicyId");
114
115 PasswordPolicyServiceUtil.deletePasswordPolicy(passwordPolicyId);
116 }
117
118 protected void updatePasswordPolicy(ActionRequest actionRequest)
119 throws Exception {
120
121 long passwordPolicyId = ParamUtil.getLong(
122 actionRequest, "passwordPolicyId");
123
124 String name = ParamUtil.getString(actionRequest, "name");
125 String description = ParamUtil.getString(actionRequest, "description");
126 boolean changeable = ParamUtil.getBoolean(actionRequest, "changeable");
127 boolean changeRequired = ParamUtil.getBoolean(
128 actionRequest, "changeRequired");
129 long minAge = ParamUtil.getLong(actionRequest, "minAge");
130 boolean checkSyntax = ParamUtil.getBoolean(
131 actionRequest, "checkSyntax");
132 boolean allowDictionaryWords = ParamUtil.getBoolean(
133 actionRequest, "allowDictionaryWords");
134 int minAlphanumeric = ParamUtil.getInteger(
135 actionRequest, "minAlphanumeric");
136 int minLength = ParamUtil.getInteger(actionRequest, "minLength");
137 int minLowerCase = ParamUtil.getInteger(actionRequest, "minLowerCase");
138 int minNumbers = ParamUtil.getInteger(actionRequest, "minNumbers");
139 int minSymbols = ParamUtil.getInteger(actionRequest, "minSymbols");
140 int minUpperCase = ParamUtil.getInteger(actionRequest, "minUpperCase");
141 boolean history = ParamUtil.getBoolean(actionRequest, "history");
142 int historyCount = ParamUtil.getInteger(actionRequest, "historyCount");
143 boolean expireable = ParamUtil.getBoolean(actionRequest, "expireable");
144 long maxAge = ParamUtil.getLong(actionRequest, "maxAge");
145 long warningTime = ParamUtil.getLong(actionRequest, "warningTime");
146 int graceLimit = ParamUtil.getInteger(actionRequest, "graceLimit");
147 boolean lockout = ParamUtil.getBoolean(actionRequest, "lockout");
148 int maxFailure = ParamUtil.getInteger(actionRequest, "maxFailure");
149 long lockoutDuration = ParamUtil.getLong(
150 actionRequest, "lockoutDuration");
151 long resetFailureCount = ParamUtil.getLong(
152 actionRequest, "resetFailureCount");
153 long resetTicketMaxAge = ParamUtil.getLong(
154 actionRequest, "resetTicketMaxAge");
155
156 if (passwordPolicyId <= 0) {
157
158
159
160 PasswordPolicyServiceUtil.addPasswordPolicy(
161 name, description, changeable, changeRequired, minAge,
162 checkSyntax, allowDictionaryWords, minAlphanumeric, minLength,
163 minLowerCase, minNumbers, minSymbols, minUpperCase, history,
164 historyCount, expireable, maxAge, warningTime, graceLimit,
165 lockout, maxFailure, lockoutDuration, resetFailureCount,
166 resetTicketMaxAge);
167 }
168 else {
169
170
171
172 PasswordPolicyServiceUtil.updatePasswordPolicy(
173 passwordPolicyId, name, description, changeable, changeRequired,
174 minAge, checkSyntax, allowDictionaryWords, minAlphanumeric,
175 minLength, minLowerCase, minNumbers, minSymbols, minUpperCase,
176 history, historyCount, expireable, maxAge, warningTime,
177 graceLimit, lockout, maxFailure, lockoutDuration,
178 resetFailureCount, resetTicketMaxAge);
179 }
180 }
181
182 }