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: EditSecurityCatalinaRealmAction.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: 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:
046: /**
047: * @author Michel-Ange ANTON
048: */
049:
050: public class EditSecurityCatalinaRealmAction extends JonasBaseAction {
051:
052: // --------------------------------------------------------- Public Methods
053:
054: public ActionForward executeAction(ActionMapping p_Mapping,
055: ActionForm p_Form, HttpServletRequest p_Request,
056: HttpServletResponse p_Response) throws IOException,
057: ServletException {
058:
059: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
060: .getAttribute(WhereAreYou.SESSION_NAME);
061: String serverName = oWhere.getCurrentJonasServerName();
062:
063: try {
064: ArrayList al = new ArrayList();
065: // Catalina
066: if (m_WhereAreYou.isCatalinaServer() == true) {
067: try {
068: ObjectName on;
069: // Find used realm name
070: on = CatalinaObjectName.catalinaRealm(m_WhereAreYou
071: .getCurrentCatalinaServiceName());
072: String sUsedRealmName = getStringAttribute(on,
073: "resourceName");
074: // Find all realms
075: String sRealmName;
076: String sRealmType;
077: Iterator it = JonasAdminJmx.getListMbean(
078: CatalinaObjectName.catalinaRealms(),
079: serverName).iterator();
080: while (it.hasNext() == true) {
081: on = (ObjectName) it.next();
082: sRealmName = getStringAttribute(on,
083: "resourceName");
084: al.add(new RealmItem(sRealmName, null,
085: sRealmName.equals(sUsedRealmName)));
086: }
087: // Sort
088: Collections.sort(al,
089: new RealmItemByNameComparator());
090: } catch (Exception e) {
091: // no action
092: // Exception because catalina realm don't exists
093: }
094: }
095: // Set form in the request
096: p_Request.setAttribute("listSecurityRealms", al);
097: } catch (Throwable t) {
098: addGlobalError(t);
099: saveErrors(p_Request, m_Errors);
100: return (p_Mapping.findForward("Global Error"));
101: }
102: // Forward to the jsp.
103: return (p_Mapping.findForward("Security Catalina Realm"));
104: }
105: }
|