001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ApplyLdapRealmAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.webapp.jonasadmin.security;
027:
028: import java.io.IOException;
029:
030: import javax.management.ObjectName;
031: import javax.servlet.ServletException;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionForward;
037: import org.apache.struts.action.ActionMapping;
038: import org.objectweb.jonas.jmx.JonasManagementRepr;
039: import org.objectweb.jonas.jmx.JonasObjectName;
040: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
041:
042: /**
043: * @author Michel-Ange ANTON
044: */
045:
046: public class ApplyLdapRealmAction extends BaseMemoryRealmAction {
047:
048: // --------------------------------------------------------- Public Methods
049:
050: public ActionForward executeAction(ActionMapping p_Mapping,
051: ActionForm p_Form, HttpServletRequest p_Request,
052: HttpServletResponse p_Response) throws IOException,
053: ServletException {
054:
055: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
056: .getAttribute(WhereAreYou.SESSION_NAME);
057: String serverName = oWhere.getCurrentJonasServerName();
058:
059: // Form used
060: LdapRealmForm oForm = (LdapRealmForm) p_Form;
061:
062: // Populate MBean
063: try {
064: // Create new
065: if (oForm.getAction().equals("create") == true) {
066: oForm.setResource(oForm.getName());
067: // Add resource
068: ObjectName oObjectName = JonasObjectName
069: .securityService();
070: String[] asParam = { oForm.getName(),
071: oForm.getInitialContextFactory(),
072: oForm.getProviderUrl(),
073: oForm.getSecurityAuthentication(),
074: oForm.getSecurityPrincipal(),
075: oForm.getSecurityCredentials(),
076: oForm.getSecurityProtocol(),
077: oForm.getLanguage(), oForm.getReferral(),
078: oForm.getStateFactories(),
079: oForm.getAuthenticationMode(),
080: oForm.getUserPasswordAttribute(),
081: oForm.getUserRolesAttribute(),
082: oForm.getRoleNameAttribute(),
083: oForm.getBaseDn(), oForm.getUserDn(),
084: oForm.getUserSearchFilter(), oForm.getRoleDn(),
085: oForm.getRoleSearchFilter(),
086: oForm.getAlgorithm() };
087: String[] asSignature = { "java.lang.String",
088: "java.lang.String", "java.lang.String",
089: "java.lang.String", "java.lang.String",
090: "java.lang.String", "java.lang.String",
091: "java.lang.String", "java.lang.String",
092: "java.lang.String", "java.lang.String",
093: "java.lang.String", "java.lang.String",
094: "java.lang.String", "java.lang.String",
095: "java.lang.String", "java.lang.String",
096: "java.lang.String", "java.lang.String",
097: "java.lang.String" };
098: JonasManagementRepr.invoke(oObjectName,
099: "addJResourceLDAP", asParam, asSignature,
100: serverName);
101: // refresh tree
102: refreshTree(p_Request);
103: // Force the node selected in tree
104: m_WhereAreYou.selectNameNode(
105: getTreeBranchName(DEPTH_SERVER)
106: + WhereAreYou.NODE_SEPARATOR
107: + "security"
108: + WhereAreYou.NODE_SEPARATOR
109: + "factory.ldap"
110: + WhereAreYou.NODE_SEPARATOR
111: + oForm.getName(), true);
112: // To see the form
113: oForm.setAction("apply");
114: } else {
115: // Modify existing
116: ObjectName oObjectName = JonasObjectName
117: .securityLdapFactory(oForm.getResource());
118: setStringAttribute(oObjectName, "AuthenticationMode",
119: oForm.getAuthenticationMode());
120: setStringAttribute(oObjectName, "BaseDN", oForm
121: .getBaseDn());
122: setStringAttribute(oObjectName,
123: "InitialContextFactory", oForm
124: .getInitialContextFactory());
125: setStringAttribute(oObjectName, "Language", oForm
126: .getLanguage());
127: setStringAttribute(oObjectName, "ProviderUrl", oForm
128: .getProviderUrl());
129: setStringAttribute(oObjectName, "Referral", oForm
130: .getReferral());
131: setStringAttribute(oObjectName, "RoleDN", oForm
132: .getRoleDn());
133: setStringAttribute(oObjectName, "RoleNameAttribute",
134: oForm.getRoleNameAttribute());
135: setStringAttribute(oObjectName, "RoleSearchFilter",
136: oForm.getRoleSearchFilter());
137: setStringAttribute(oObjectName,
138: "SecurityAuthentication", oForm
139: .getSecurityAuthentication());
140: setStringAttribute(oObjectName, "SecurityCredentials",
141: oForm.getSecurityCredentials());
142: setStringAttribute(oObjectName, "SecurityPrincipal",
143: oForm.getSecurityPrincipal());
144: setStringAttribute(oObjectName, "SecurityProtocol",
145: oForm.getSecurityProtocol());
146: setStringAttribute(oObjectName, "StateFactories", oForm
147: .getStateFactories());
148: setStringAttribute(oObjectName, "UserDN", oForm
149: .getUserDn());
150: setStringAttribute(oObjectName,
151: "UserPasswordAttribute", oForm
152: .getUserPasswordAttribute());
153: setStringAttribute(oObjectName, "UserRolesAttribute",
154: oForm.getUserRolesAttribute());
155: setStringAttribute(oObjectName, "UserSearchFilter",
156: oForm.getUserSearchFilter());
157: setStringAttribute(oObjectName, "Algorithm", oForm
158: .getAlgorithm());
159: }
160: // Save
161: if (oForm.isSave()) {
162: ObjectName onRealm = JonasObjectName
163: .securityLdapFactory(oForm.getResource());
164: JonasManagementRepr.invoke(onRealm, "saveConfig", null,
165: null, serverName);
166: }
167: } catch (Throwable t) {
168: addGlobalError(t);
169: saveErrors(p_Request, m_Errors);
170: return (p_Mapping.findForward("Global Error"));
171: }
172: // Forward to the jsp.
173: return (p_Mapping.findForward("Ldap Realm"));
174: }
175:
176: // --------------------------------------------------------- Protected Methods
177:
178: }
|