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: EditServiceSecurityAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.webapp.jonasadmin.service;
027:
028: import java.io.IOException;
029: import java.util.ArrayList;
030: import java.util.Collections;
031: import java.util.Iterator;
032:
033: import javax.management.ObjectName;
034: import javax.servlet.ServletException;
035: import javax.servlet.http.HttpServletRequest;
036: import javax.servlet.http.HttpServletResponse;
037:
038: import org.apache.struts.action.ActionForm;
039: import org.apache.struts.action.ActionForward;
040: import org.apache.struts.action.ActionMapping;
041: import org.objectweb.jonas.jmx.CatalinaObjectName;
042: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
043: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
044: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
045: import org.objectweb.jonas.webapp.jonasadmin.security.RealmItem;
046: import org.objectweb.jonas.webapp.jonasadmin.security.RealmItemByNameComparator;
047:
048: /**
049: * @author Michel-Ange ANTON
050: */
051:
052: public class EditServiceSecurityAction extends JonasBaseAction {
053:
054: // --------------------------------------------------------- Public Methods
055:
056: public ActionForward executeAction(ActionMapping p_Mapping,
057: ActionForm p_Form, HttpServletRequest p_Request,
058: HttpServletResponse p_Response) throws IOException,
059: ServletException {
060:
061: // Force the node selected in tree
062: m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
063: + WhereAreYou.NODE_SEPARATOR + "services"
064: + WhereAreYou.NODE_SEPARATOR + "security", true);
065:
066: // Current server
067: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
068: .getAttribute(WhereAreYou.SESSION_NAME);
069: String sServerName = oWhere.getCurrentJonasServerName();
070:
071: try {
072: ArrayList al = new ArrayList();
073: // Catalina
074: if (m_WhereAreYou.isCatalinaServer() == true) {
075: try {
076: ObjectName on;
077: // Find used realm name
078: on = CatalinaObjectName.catalinaRealm(m_WhereAreYou
079: .getCurrentCatalinaDomainName());
080: String sUsedRealmName = getStringAttribute(on,
081: "resourceName");
082: // Find all realms
083: String sRealmName;
084: String sRealmType;
085: String sPathContext = null;
086: Iterator it = JonasAdminJmx.getListMbean(
087: CatalinaObjectName.catalinaRealms(),
088: sServerName).iterator();
089: while (it.hasNext() == true) {
090: on = (ObjectName) it.next();
091: sRealmName = getStringAttribute(on,
092: "resourceName");
093: sRealmType = JonasAdminJmx
094: .findSecurityFactorySubType(sRealmName,
095: sServerName);
096: try {
097: sPathContext = on.getKeyProperty("path");
098: } catch (NullPointerException e) {
099: // Not possible as "path" is not null
100: }
101: if (sPathContext != null) {
102: al.add(new RealmItem(sRealmName,
103: sRealmType, sPathContext,
104: sRealmName.equals(sUsedRealmName)));
105: }
106: }
107: // Sort
108: Collections.sort(al,
109: new RealmItemByNameComparator());
110: } catch (Exception e) {
111: // no action
112: // Exception because catalina realm don't exists
113: }
114: }
115: // Set form in the request
116: p_Request.setAttribute("listSecurityRealms", al);
117: } catch (Throwable t) {
118: addGlobalError(t);
119: saveErrors(p_Request, m_Errors);
120: return (p_Mapping.findForward("Global Error"));
121: }
122: // Forward to the jsp.
123: return (p_Mapping.findForward("Service Security"));
124: }
125: }
|