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: * Initial developer(s): Michel-Ange ANTON
022: * --------------------------------------------------------------------------
023: * $Id: ApplyGroupMemoryRealmAction.java 9680 2006-10-06 12:08:33Z danesa $
024: * --------------------------------------------------------------------------
025: */
026:
027: package org.objectweb.jonas.webapp.jonasadmin.security;
028:
029: import java.io.IOException;
030: import java.util.ArrayList;
031:
032: import javax.management.ObjectName;
033: import javax.servlet.ServletException;
034: import javax.servlet.http.HttpServletRequest;
035: import javax.servlet.http.HttpServletResponse;
036:
037: import org.apache.struts.action.ActionForm;
038: import org.apache.struts.action.ActionForward;
039: import org.apache.struts.action.ActionMapping;
040: import org.objectweb.jonas.jmx.JonasManagementRepr;
041: import org.objectweb.jonas.jmx.JonasObjectName;
042: import org.objectweb.jonas.webapp.jonasadmin.Jlists;
043: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
044:
045: /**
046: *
047: */
048:
049: public class ApplyGroupMemoryRealmAction extends BaseMemoryRealmAction {
050:
051: // --------------------------------------------------------- Public Methods
052:
053: /**
054: */
055: public ActionForward executeAction(ActionMapping p_Mapping,
056: ActionForm p_Form, HttpServletRequest p_Request,
057: HttpServletResponse p_Response) throws IOException,
058: ServletException {
059:
060: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
061: .getAttribute(WhereAreYou.SESSION_NAME);
062: String serverName = oWhere.getCurrentJonasServerName();
063:
064: // Realm Form used
065: MemoryRealmForm oRealmForm = getForm(p_Mapping, p_Request);
066:
067: // Form used
068: GroupMemoryRealmForm oForm = (GroupMemoryRealmForm) p_Form;
069:
070: oForm.setListRolesUsed(Jlists.getArrayList(
071: oForm.getRolesUsed(), Jlists.SEPARATOR));
072: oForm.setListRolesNotused(Jlists.getArrayList(oForm
073: .getRolesNotused(), Jlists.SEPARATOR));
074:
075: ArrayList alAddRoles = new ArrayList(oForm.getListRolesUsed());
076: alAddRoles.removeAll(oForm.getListRolesGroup());
077: ArrayList alRemoveRoles = new ArrayList(oForm
078: .getListRolesNotused());
079: alRemoveRoles.retainAll(oForm.getListRolesGroup());
080:
081: // Populate MBean
082: try {
083: ObjectName onGroup = null;
084: // Create a new Group
085: if (oForm.getAction().equals("create") == true) {
086: ObjectName onRealm = JonasObjectName
087: .securityMemoryFactory(oRealmForm.getResource());
088: String[] asParam = { oForm.getGroup() };
089: String[] asSignature = { "java.lang.String" };
090: JonasManagementRepr.invoke(onRealm, "addGroup",
091: asParam, asSignature, serverName);
092: // Search created Group
093: onGroup = JonasObjectName.group(oRealmForm
094: .getResource(), oForm.getGroup());
095: } else {
096: // Modify existing Group
097: onGroup = JonasObjectName.group(oRealmForm
098: .getResource(), oForm.getGroup());
099: }
100: // Description
101: setStringAttribute(onGroup, "Description", oForm
102: .getDescription());
103:
104: // Roles
105: if (alAddRoles.size() > 0) {
106: for (int i = 0; i < alAddRoles.size(); i++) {
107: String[] asParam = { alAddRoles.get(i).toString() };
108: String[] asSignature = { "java.lang.String" };
109: JonasManagementRepr.invoke(onGroup, "addRole",
110: asParam, asSignature, serverName);
111: }
112: }
113: if (alRemoveRoles.size() > 0) {
114: for (int i = 0; i < alRemoveRoles.size(); i++) {
115: String[] asParam = { alRemoveRoles.get(i)
116: .toString() };
117: String[] asSignature = { "java.lang.String" };
118: JonasManagementRepr.invoke(onGroup, "removeRole",
119: asParam, asSignature, serverName);
120: }
121: }
122: } catch (Throwable t) {
123: addGlobalError(t);
124: saveErrors(p_Request, m_Errors);
125: return (p_Mapping.findForward("Global Error"));
126: }
127: // Forward to the jsp.
128: return (p_Mapping.findForward("ActionEditMemoryRealmGroups"));
129: }
130:
131: // --------------------------------------------------------- Protected Methods
132:
133: }
|