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.kernel.util.Constants;
024: import com.liferay.portal.kernel.util.ParamUtil;
025: import com.liferay.portal.kernel.util.Validator;
026: import com.liferay.portal.model.Company;
027: import com.liferay.portal.model.impl.RoleImpl;
028: import com.liferay.portal.security.auth.PrincipalException;
029: import com.liferay.portal.security.ldap.PortalLDAPUtil;
030: import com.liferay.portal.service.CompanyServiceUtil;
031: import com.liferay.portal.service.RoleLocalServiceUtil;
032: import com.liferay.portal.servlet.filters.sso.cas.CASFilter;
033: import com.liferay.portal.struts.PortletAction;
034: import com.liferay.portal.util.PortalUtil;
035: import com.liferay.portal.util.PrefsPropsUtil;
036: import com.liferay.portal.util.PropsUtil;
037: import com.liferay.util.ldap.LDAPUtil;
038: import com.liferay.util.servlet.SessionErrors;
039:
040: import javax.portlet.ActionRequest;
041: import javax.portlet.ActionResponse;
042: import javax.portlet.PortletConfig;
043: import javax.portlet.PortletPreferences;
044:
045: import org.apache.struts.action.ActionForm;
046: import org.apache.struts.action.ActionMapping;
047:
048: /**
049: * <a href="EditSettingsAction.java.html"><b><i>View Source</i></b></a>
050: *
051: * @author Brian Wing Shun Chan
052: * @author Scott Lee
053: *
054: */
055: public class EditSettingsAction extends PortletAction {
056:
057: public void processAction(ActionMapping mapping, ActionForm form,
058: PortletConfig config, ActionRequest req, ActionResponse res)
059: throws Exception {
060:
061: long companyId = PortalUtil.getCompanyId(req);
062: long userId = PortalUtil.getUserId(req);
063:
064: if (!RoleLocalServiceUtil.hasUserRole(userId, companyId,
065: RoleImpl.ADMINISTRATOR, true)) {
066:
067: SessionErrors.add(req, PrincipalException.class.getName());
068:
069: setForward(req, "portlet.enterprise_admin.error");
070:
071: return;
072: }
073:
074: PortletPreferences prefs = PrefsPropsUtil
075: .getPreferences(companyId);
076:
077: String cmd = ParamUtil.getString(req, Constants.CMD);
078:
079: if (cmd.equals("updateCAS")) {
080: updateCAS(req, companyId, prefs);
081: } else if (cmd.equals("updateDefaultGroupsAndRoles")) {
082: updateDefaultGroupsAndRoles(req, prefs);
083: } else if (cmd.equals("updateEmails")) {
084: updateEmails(req, prefs);
085: } else if (cmd.equals("updateLdap")) {
086: updateLdap(req, companyId, prefs);
087: } else if (cmd.equals("updateMailHostNames")) {
088: updateMailHostNames(req, prefs);
089: } else if (cmd.equals("updateNtlm")) {
090: updateNtlm(req, companyId, prefs);
091: } else if (cmd.equals("updateOpenId")) {
092: updateOpenId(req, prefs);
093: } else if (cmd.equals("updateOpenSSO")) {
094: updateOpenSSO(req, companyId, prefs);
095: } else if (cmd.equals("updateReservedUsers")) {
096: updateReservedUsers(req, prefs);
097: } else if (cmd.equals("updateSecurity")) {
098: updateSecurity(req);
099: }
100:
101: if (SessionErrors.isEmpty(req)) {
102: if (!cmd.equals("updateLdap")
103: && !cmd.equals("updateSecurity")) {
104: prefs.store();
105: }
106:
107: sendRedirect(req, res);
108: } else {
109: setForward(req, "portlet.enterprise_admin.view");
110: }
111: }
112:
113: protected void updateCAS(ActionRequest req, long companyId,
114: PortletPreferences prefs) throws Exception {
115:
116: boolean enabled = ParamUtil.getBoolean(req, "enabled");
117: boolean importFromLdap = ParamUtil.getBoolean(req,
118: "importFromLdap");
119: String loginUrl = ParamUtil.getString(req, "loginUrl");
120: String logoutUrl = ParamUtil.getString(req, "logoutUrl");
121: String serverName = ParamUtil.getString(req, "serverName");
122: String serviceUrl = ParamUtil.getString(req, "serviceUrl");
123: String validateUrl = ParamUtil.getString(req, "validateUrl");
124:
125: prefs.setValue(PropsUtil.CAS_AUTH_ENABLED, String
126: .valueOf(enabled));
127: prefs.setValue(PropsUtil.CAS_IMPORT_FROM_LDAP, String
128: .valueOf(importFromLdap));
129: prefs.setValue(PropsUtil.CAS_LOGIN_URL, loginUrl);
130: prefs.setValue(PropsUtil.CAS_LOGOUT_URL, logoutUrl);
131: prefs.setValue(PropsUtil.CAS_SERVER_NAME, serverName);
132: prefs.setValue(PropsUtil.CAS_SERVICE_URL, serviceUrl);
133: prefs.setValue(PropsUtil.CAS_VALIDATE_URL, validateUrl);
134:
135: prefs.store();
136:
137: CASFilter.reload(companyId);
138: }
139:
140: protected void updateDefaultGroupsAndRoles(ActionRequest req,
141: PortletPreferences prefs) throws Exception {
142:
143: String defaultGroupNames = ParamUtil.getString(req,
144: "defaultGroupNames");
145: String defaultRoleNames = ParamUtil.getString(req,
146: "defaultRoleNames");
147: String defaultUserGroupNames = ParamUtil.getString(req,
148: "defaultUserGroupNames");
149:
150: prefs.setValue(PropsUtil.ADMIN_DEFAULT_GROUP_NAMES,
151: defaultGroupNames);
152: prefs.setValue(PropsUtil.ADMIN_DEFAULT_ROLE_NAMES,
153: defaultRoleNames);
154: prefs.setValue(PropsUtil.ADMIN_DEFAULT_USER_GROUP_NAMES,
155: defaultUserGroupNames);
156: }
157:
158: protected void updateEmails(ActionRequest req,
159: PortletPreferences prefs) throws Exception {
160:
161: String tabs3 = ParamUtil.getString(req, "tabs3");
162:
163: if (tabs3.equals("account-created-notification")) {
164: String emailUserAddedEnabled = ParamUtil.getString(req,
165: "emailUserAddedEnabled");
166: String emailUserAddedSubject = ParamUtil.getString(req,
167: "emailUserAddedSubject");
168: String emailUserAddedBody = ParamUtil.getString(req,
169: "emailUserAddedBody");
170:
171: if (Validator.isNull(emailUserAddedSubject)) {
172: SessionErrors.add(req, "emailUserAddedSubject");
173: } else if (Validator.isNull(emailUserAddedBody)) {
174: SessionErrors.add(req, "emailUserAddedBody");
175: } else {
176: prefs.setValue(
177: PropsUtil.ADMIN_EMAIL_USER_ADDED_ENABLED,
178: emailUserAddedEnabled);
179: prefs.setValue(
180: PropsUtil.ADMIN_EMAIL_USER_ADDED_SUBJECT,
181: emailUserAddedSubject);
182: prefs.setValue(PropsUtil.ADMIN_EMAIL_USER_ADDED_BODY,
183: emailUserAddedBody);
184: }
185: } else if (tabs3.equals("password-changed-notification")) {
186: String emailPasswordSentEnabled = ParamUtil.getString(req,
187: "emailPasswordSentEnabled");
188: String emailPasswordSentSubject = ParamUtil.getString(req,
189: "emailPasswordSentSubject");
190: String emailPasswordSentBody = ParamUtil.getString(req,
191: "emailPasswordSentBody");
192:
193: if (Validator.isNull(emailPasswordSentSubject)) {
194: SessionErrors.add(req, "emailPasswordSentSubject");
195: } else if (Validator.isNull(emailPasswordSentBody)) {
196: SessionErrors.add(req, "emailPasswordSentBody");
197: } else {
198: prefs.setValue(
199: PropsUtil.ADMIN_EMAIL_PASSWORD_SENT_ENABLED,
200: emailPasswordSentEnabled);
201: prefs.setValue(
202: PropsUtil.ADMIN_EMAIL_PASSWORD_SENT_SUBJECT,
203: emailPasswordSentSubject);
204: prefs.setValue(
205: PropsUtil.ADMIN_EMAIL_PASSWORD_SENT_BODY,
206: emailPasswordSentBody);
207: }
208: } else {
209: String emailFromName = ParamUtil.getString(req,
210: "emailFromName");
211: String emailFromAddress = ParamUtil.getString(req,
212: "emailFromAddress");
213:
214: if (Validator.isNull(emailFromName)) {
215: SessionErrors.add(req, "emailFromName");
216: } else if (!Validator.isEmailAddress(emailFromAddress)) {
217: SessionErrors.add(req, "emailFromAddress");
218: } else {
219: prefs.setValue(PropsUtil.ADMIN_EMAIL_FROM_NAME,
220: emailFromName);
221: prefs.setValue(PropsUtil.ADMIN_EMAIL_FROM_ADDRESS,
222: emailFromAddress);
223: }
224: }
225: }
226:
227: protected void updateLdap(ActionRequest req, long companyId,
228: PortletPreferences prefs) throws Exception {
229:
230: boolean enabled = ParamUtil.getBoolean(req, "enabled");
231: boolean required = ParamUtil.getBoolean(req, "required");
232: String baseProviderURL = ParamUtil.getString(req,
233: "baseProviderURL");
234: String baseDN = ParamUtil.getString(req, "baseDN");
235: String principal = ParamUtil.getString(req, "principal");
236: String credentials = ParamUtil.getString(req, "credentials");
237: String searchFilter = ParamUtil.getString(req, "searchFilter");
238: String userDefaultObjectClasses = ParamUtil.getString(req,
239: "userDefaultObjectClasses");
240:
241: String userMappings = "screenName="
242: + ParamUtil.getString(req, "userMappingScreenName")
243: + "\npassword="
244: + ParamUtil.getString(req, "userMappingPassword")
245: + "\nemailAddress="
246: + ParamUtil.getString(req, "userMappingEmailAddress")
247: + "\nfullName="
248: + ParamUtil.getString(req, "userMappingFullName")
249: + "\nfirstName="
250: + ParamUtil.getString(req, "userMappingFirstName")
251: + "\nlastName="
252: + ParamUtil.getString(req, "userMappingLastName")
253: + "\njobTitle="
254: + ParamUtil.getString(req, "userMappingJobTitle")
255: + "\ngroup="
256: + ParamUtil.getString(req, "userMappingGroup");
257:
258: String groupMappings = "groupName="
259: + ParamUtil.getString(req, "groupMappingGroupName")
260: + "\ndescription="
261: + ParamUtil.getString(req, "groupMappingDescription")
262: + "\nuser="
263: + ParamUtil.getString(req, "groupMappingUser");
264:
265: boolean importEnabled = ParamUtil.getBoolean(req,
266: "importEnabled");
267: boolean importOnStartup = ParamUtil.getBoolean(req,
268: "importOnStartup");
269: long importInterval = ParamUtil.getLong(req, "importInterval");
270: String importUserSearchFilter = ParamUtil.getString(req,
271: "importUserSearchFilter");
272: String importGroupSearchFilter = ParamUtil.getString(req,
273: "importGroupSearchFilter");
274: boolean exportEnabled = ParamUtil.getBoolean(req,
275: "exportEnabled");
276: String usersDN = ParamUtil.getString(req, "usersDN");
277: String groupsDN = ParamUtil.getString(req, "groupsDN");
278: boolean passwordPolicyEnabled = ParamUtil.getBoolean(req,
279: "passwordPolicyEnabled");
280:
281: try {
282: if (enabled) {
283: String fullProviderURL = LDAPUtil.getFullProviderURL(
284: baseProviderURL, baseDN);
285:
286: PortalLDAPUtil.getContext(companyId, fullProviderURL,
287: principal, credentials);
288: }
289: } catch (Exception e) {
290: SessionErrors.add(req, "ldapAuthentication");
291:
292: return;
293: }
294:
295: prefs.setValue(PropsUtil.LDAP_AUTH_ENABLED, String
296: .valueOf(enabled));
297: prefs.setValue(PropsUtil.LDAP_AUTH_REQUIRED, String
298: .valueOf(required));
299: prefs.setValue(PropsUtil.LDAP_BASE_PROVIDER_URL,
300: baseProviderURL);
301: prefs.setValue(PropsUtil.LDAP_BASE_DN, baseDN);
302: prefs.setValue(PropsUtil.LDAP_SECURITY_PRINCIPAL, principal);
303: prefs
304: .setValue(PropsUtil.LDAP_SECURITY_CREDENTIALS,
305: credentials);
306: prefs.setValue(PropsUtil.LDAP_AUTH_SEARCH_FILTER, searchFilter);
307: prefs.setValue(PropsUtil.LDAP_USER_DEFAULT_OBJECT_CLASSES,
308: userDefaultObjectClasses);
309: prefs.setValue(PropsUtil.LDAP_USER_MAPPINGS, userMappings);
310: prefs.setValue(PropsUtil.LDAP_GROUP_MAPPINGS, groupMappings);
311: prefs.setValue(PropsUtil.LDAP_IMPORT_ENABLED, String
312: .valueOf(importEnabled));
313: prefs.setValue(PropsUtil.LDAP_IMPORT_ON_STARTUP, String
314: .valueOf(importOnStartup));
315: prefs.setValue(PropsUtil.LDAP_IMPORT_INTERVAL, String
316: .valueOf(importInterval));
317: prefs.setValue(PropsUtil.LDAP_IMPORT_USER_SEARCH_FILTER,
318: importUserSearchFilter);
319: prefs.setValue(PropsUtil.LDAP_IMPORT_GROUP_SEARCH_FILTER,
320: importGroupSearchFilter);
321: prefs.setValue(PropsUtil.LDAP_EXPORT_ENABLED, String
322: .valueOf(exportEnabled));
323: prefs.setValue(PropsUtil.LDAP_USERS_DN, usersDN);
324: prefs.setValue(PropsUtil.LDAP_GROUPS_DN, groupsDN);
325: prefs.setValue(PropsUtil.LDAP_PASSWORD_POLICY_ENABLED, String
326: .valueOf(passwordPolicyEnabled));
327:
328: prefs.store();
329: }
330:
331: protected void updateMailHostNames(ActionRequest req,
332: PortletPreferences prefs) throws Exception {
333:
334: String mailHostNames = ParamUtil
335: .getString(req, "mailHostNames");
336:
337: prefs.setValue(PropsUtil.ADMIN_MAIL_HOST_NAMES, mailHostNames);
338: }
339:
340: protected void updateNtlm(ActionRequest req, long companyId,
341: PortletPreferences prefs) throws Exception {
342:
343: boolean enabled = ParamUtil.getBoolean(req, "enabled");
344: String domainController = ParamUtil.getString(req,
345: "domainController");
346: String domain = ParamUtil.getString(req, "domain");
347:
348: prefs.setValue(PropsUtil.NTLM_AUTH_ENABLED, String
349: .valueOf(enabled));
350: prefs.setValue(PropsUtil.NTLM_DOMAIN_CONTROLLER,
351: domainController);
352: prefs.setValue(PropsUtil.NTLM_DOMAIN, domain);
353:
354: prefs.store();
355: }
356:
357: protected void updateOpenId(ActionRequest req,
358: PortletPreferences prefs) throws Exception {
359:
360: boolean enabled = ParamUtil.getBoolean(req, "enabled");
361:
362: prefs.setValue(PropsUtil.OPEN_ID_AUTH_ENABLED, String
363: .valueOf(enabled));
364:
365: prefs.store();
366: }
367:
368: protected void updateOpenSSO(ActionRequest req, long companyId,
369: PortletPreferences prefs) throws Exception {
370:
371: boolean enabled = ParamUtil.getBoolean(req, "enabled");
372: String loginUrl = ParamUtil.getString(req, "loginUrl");
373: String logoutUrl = ParamUtil.getString(req, "logoutUrl");
374: String serviceUrl = ParamUtil.getString(req, "serviceUrl");
375: String subjectCookieName = ParamUtil.getString(req,
376: "subjectCookieName");
377:
378: prefs.setValue(PropsUtil.OPEN_SSO_AUTH_ENABLED, String
379: .valueOf(enabled));
380: prefs.setValue(PropsUtil.OPEN_SSO_LOGIN_URL, loginUrl);
381: prefs.setValue(PropsUtil.OPEN_SSO_LOGOUT_URL, logoutUrl);
382: prefs.setValue(PropsUtil.OPEN_SSO_SERVICE_URL, serviceUrl);
383: prefs.setValue(PropsUtil.OPEN_SSO_SUBJECT_COOKIE_NAME,
384: subjectCookieName);
385:
386: prefs.store();
387: }
388:
389: protected void updateReservedUsers(ActionRequest req,
390: PortletPreferences prefs) throws Exception {
391:
392: String reservedScreenNames = ParamUtil.getString(req,
393: "reservedScreenNames");
394: String reservedEmailAddresses = ParamUtil.getString(req,
395: "reservedEmailAddresses");
396:
397: prefs.setValue(PropsUtil.ADMIN_RESERVED_SCREEN_NAMES,
398: reservedScreenNames);
399: prefs.setValue(PropsUtil.ADMIN_RESERVED_EMAIL_ADDRESSES,
400: reservedEmailAddresses);
401: }
402:
403: protected void updateSecurity(ActionRequest req) throws Exception {
404: Company company = PortalUtil.getCompany(req);
405:
406: String authType = ParamUtil.getString(req, "authType");
407: boolean autoLogin = ParamUtil.getBoolean(req, "autoLogin");
408: boolean sendPassword = ParamUtil
409: .getBoolean(req, "sendPassword");
410: boolean strangers = ParamUtil.getBoolean(req, "strangers");
411: boolean strangersWithMx = ParamUtil.getBoolean(req,
412: "strangersWithMx");
413: boolean strangersVerify = ParamUtil.getBoolean(req,
414: "strangersVerify");
415:
416: CompanyServiceUtil.updateSecurity(company.getCompanyId(),
417: authType, autoLogin, sendPassword, strangers,
418: strangersWithMx, strangersVerify, company
419: .isCommunityLogo());
420: }
421:
422: }
|