001: /*
002: * JOSSO: Java Open Single Sign-On
003: *
004: * Copyright 2004-2008, Atricore, Inc.
005: *
006: * This is free software; you can redistribute it and/or modify it
007: * under the terms of the GNU Lesser General Public License as
008: * published by the Free Software Foundation; either version 2.1 of
009: * the License, or (at your option) any later version.
010: *
011: * This software 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 software; if not, write to the Free
018: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
020: */
021: package org.josso.agent;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.josso.util.mbeans.JOSSOBaseMBean;
026:
027: import javax.management.MBeanException;
028: import javax.management.Notification;
029: import javax.management.RuntimeOperationsException;
030: import java.util.List;
031:
032: /**
033: * @author <a href="mailto:sgonzalez@josso.org">Sebastian Gonzalez Oyuela</a>
034: * @version $Id: SSOAgentMBean.java 508 2008-02-18 13:32:29Z sgonzalez $
035: */
036:
037: public class SSOAgentMBean extends JOSSOBaseMBean {
038:
039: /**
040: * String used as event type when notifying new partner app configurations using JMX.
041: */
042: public static final String JOSSO_AGENT_EVENT_ADD_PARTNER_APP = "josso.agent.addPartnerApp";
043:
044: /**
045: * String used as event type when notifying partner app configuration removal using JMX.
046: */
047: public static final String JOSSO_AGENT_EVENT_REMOVE_PARTNER_APP = "josso.agent.removePartnerApp";
048:
049: private static final Log logger = LogFactory
050: .getLog(SSOAgentMBean.class);
051:
052: private int _seq = 0;
053:
054: public SSOAgentMBean() throws MBeanException,
055: RuntimeOperationsException {
056: super ();
057: }
058:
059: public void addPartnerApp(String context,
060: String[] ignoredWebResources) {
061:
062: if (context == null) {
063: logger.warn("Tryint to add 'null' context as partner app.");
064: return;
065: }
066:
067: if (ignoredWebResources == null) {
068: ignoredWebResources = new String[0];
069: }
070:
071: SSOAgent a = getSSOAgent();
072: SSOAgentConfiguration cfg = a.getConfiguration();
073: cfg.addSSOPartnerApp(context, ignoredWebResources);
074:
075: List papps = cfg.getSSOPartnerApps();
076:
077: for (int i = 0; i < papps.size(); i++) {
078: SSOPartnerAppConfig papp = (SSOPartnerAppConfig) papps
079: .get(i);
080: if (papp.getContext().equals(context)) {
081:
082: // Send a JMX notification, use parent ObjectName instance (oname).
083: Notification n = new SSOAgentMBeanNotification(
084: JOSSO_AGENT_EVENT_ADD_PARTNER_APP, oname,
085: _seq++);
086: n.setUserData(papp);
087:
088: try {
089: this .sendNotification(n);
090: return;
091:
092: } catch (MBeanException e) {
093: logger.warn("Can't send JMX notificatin : \n"
094: + e.getMessage(), e);
095: }
096: }
097: }
098:
099: }
100:
101: public void addPartnerApp(String context) {
102: this .addPartnerApp(context, new String[0]);
103: }
104:
105: public void removePartnerApp(String context) {
106:
107: if (context == null) {
108: logger.warn("Trying to remove 'null' context");
109: return;
110: }
111: SSOAgent a = getSSOAgent();
112: a.getConfiguration().removeSSOPartnerApp(context);
113: try {
114: // Send a JMX notification, use parent ObjectName instance (oname).
115: Notification n = new SSOAgentMBeanNotification(
116: JOSSO_AGENT_EVENT_REMOVE_PARTNER_APP, oname, _seq++);
117: n.setUserData(context);
118: this .sendNotification(n);
119:
120: } catch (MBeanException e) {
121: logger.warn("Can't send JMX notificatin : \n"
122: + e.getMessage(), e);
123: }
124: }
125:
126: public SSOPartnerAppConfig[] listPartnerApps() {
127: SSOAgent a = getSSOAgent();
128: return (SSOPartnerAppConfig[]) a.getConfiguration()
129: .getSSOPartnerApps()
130: .toArray(new SSOPartnerAppConfig[0]);
131: }
132:
133: protected SSOAgent getSSOAgent() {
134: return (SSOAgent) this .resource;
135: }
136:
137: public class SSOAgentMBeanNotification extends Notification {
138:
139: public SSOAgentMBeanNotification(String type, Object source,
140: long sequence) {
141: super(type, source, sequence);
142: }
143: }
144:
145: }
|