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: EditLdapRealmAction.java 4408 2004-03-19 14:31:54Z sauthieg $
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.JonasObjectName;
039: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
040: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
041:
042: /**
043: * @author Michel-Ange ANTON
044: */
045: public class EditLdapRealmAction extends JonasBaseAction {
046:
047: // --------------------------------------------------------- Public Methods
048:
049: public ActionForward executeAction(ActionMapping p_Mapping,
050: ActionForm p_Form, HttpServletRequest p_Request,
051: HttpServletResponse p_Response) throws IOException,
052: ServletException {
053:
054: String sResource = p_Request.getParameter("resource");
055: String sAction = p_Request.getParameter("action");
056:
057: // Form used
058: LdapRealmForm oForm = null;
059: if (sResource != null) {
060: // Editing a new realm
061: oForm = new LdapRealmForm();
062: m_Session.setAttribute("ldapRealmForm", oForm);
063: oForm.setResource(sResource);
064: oForm.setAction("apply");
065: } else {
066: // Creating
067: if ((sAction != null) && (sAction.equals("create") == true)) {
068: oForm = new LdapRealmForm();
069: oForm.reset(p_Mapping, p_Request);
070: m_Session.setAttribute("ldapRealmForm", oForm);
071: oForm.setAction("create");
072: }
073: // Editing a realm in session (Show after apply or save)
074: else {
075: oForm = (LdapRealmForm) m_Session
076: .getAttribute("ldapRealmForm");
077: oForm.reset(p_Mapping, p_Request);
078: }
079: }
080:
081: // Populate
082: try {
083: // Populate only if action is 'apply'
084: if (oForm.getAction().equals("apply") == true) {
085: ObjectName oObjectName = JonasObjectName
086: .securityLdapFactory(oForm.getResource());
087: oForm.setName(getStringAttribute(oObjectName, "Name"));
088: oForm.setAuthenticationMode(getStringAttribute(
089: oObjectName, "AuthenticationMode"));
090: oForm.setBaseDn(getStringAttribute(oObjectName,
091: "BaseDN"));
092: oForm.setInitialContextFactory(getStringAttribute(
093: oObjectName, "InitialContextFactory"));
094: oForm.setLanguage(getStringAttribute(oObjectName,
095: "Language"));
096: oForm.setProviderUrl(getStringAttribute(oObjectName,
097: "ProviderUrl"));
098: oForm.setReferral(getStringAttribute(oObjectName,
099: "Referral"));
100: oForm.setRoleDn(getStringAttribute(oObjectName,
101: "RoleDN"));
102: oForm.setRoleNameAttribute(getStringAttribute(
103: oObjectName, "RoleNameAttribute"));
104: oForm.setRoleSearchFilter(getStringAttribute(
105: oObjectName, "RoleSearchFilter"));
106: oForm.setSecurityAuthentication(getStringAttribute(
107: oObjectName, "SecurityAuthentication"));
108: oForm.setSecurityCredentials(getStringAttribute(
109: oObjectName, "SecurityCredentials"));
110: oForm.setSecurityPrincipal(getStringAttribute(
111: oObjectName, "SecurityPrincipal"));
112: oForm.setSecurityProtocol(getStringAttribute(
113: oObjectName, "SecurityProtocol"));
114: oForm.setStateFactories(getStringAttribute(oObjectName,
115: "StateFactories"));
116: oForm.setUserDn(getStringAttribute(oObjectName,
117: "UserDN"));
118: oForm.setUserPasswordAttribute(getStringAttribute(
119: oObjectName, "UserPasswordAttribute"));
120: oForm.setUserRolesAttribute(getStringAttribute(
121: oObjectName, "UserRolesAttribute"));
122: oForm.setUserSearchFilter(getStringAttribute(
123: oObjectName, "UserSearchFilter"));
124: oForm.setAlgorithm(getStringAttribute(oObjectName,
125: "Algorithm"));
126: // Force the node selected in tree
127: m_WhereAreYou.selectNameNode(
128: getTreeBranchName(DEPTH_SERVER)
129: + WhereAreYou.NODE_SEPARATOR
130: + "security"
131: + WhereAreYou.NODE_SEPARATOR
132: + "factory.ldap"
133: + WhereAreYou.NODE_SEPARATOR
134: + oForm.getName(), true);
135: }
136: } catch (Throwable t) {
137: addGlobalError(t);
138: saveErrors(p_Request, m_Errors);
139: return (p_Mapping.findForward("Global Error"));
140: }
141: // Forward to the jsp.
142: return (p_Mapping.findForward("Ldap Realm"));
143: }
144:
145: // --------------------------------------------------------- Protected Methods
146:
147: }
|