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;
022:
023: import org.apache.commons.configuration.Configuration;
024: import org.apache.commons.configuration.ConfigurationException;
025: import org.apache.commons.configuration.ConfigurationFactory;
026: import org.apache.commons.configuration.SubsetConfiguration;
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029: import org.josso.agent.SSOAgent;
030: import org.josso.agent.SSOAgentConfiguration;
031: import org.josso.agent.SSOAgentConfigurationImpl;
032: import org.josso.auth.Authenticator;
033: import org.josso.auth.CredentialStore;
034: import org.josso.auth.CredentialStoreKeyAdapter;
035: import org.josso.auth.scheme.AuthenticationScheme;
036: import org.josso.gateway.GatewayServiceLocator;
037: import org.josso.gateway.SSOWebConfiguration;
038: import org.josso.gateway.SSOWebConfigurationImpl;
039: import org.josso.gateway.audit.SSOAuditManager;
040: import org.josso.gateway.audit.service.handler.SSOAuditTrailHandler;
041: import org.josso.gateway.event.SSOEventListener;
042: import org.josso.gateway.event.SSOEventManager;
043: import org.josso.gateway.identity.service.SSOIdentityManager;
044: import org.josso.gateway.identity.service.store.IdentityStore;
045: import org.josso.gateway.identity.service.store.IdentityStoreKeyAdapter;
046: import org.josso.gateway.reverseproxy.ReverseProxyConfiguration;
047: import org.josso.gateway.reverseproxy.ReverseProxyConfigurationImpl;
048: import org.josso.gateway.session.service.SSOSessionManager;
049: import org.josso.gateway.session.service.SessionIdGenerator;
050: import org.josso.gateway.session.service.store.SessionStore;
051: import org.josso.util.config.ConfigurationContext;
052:
053: import java.io.File;
054: import java.lang.reflect.Method;
055: import java.net.MalformedURLException;
056: import java.net.URL;
057: import java.util.*;
058:
059: /**
060: * This is the base implementation for all ComponentKeeper instances.
061: * Currently, this implementation cannot be used directly because JOSSO has new components that depends on JMX support.
062: *
063: * @see MBeanComponentKeeper
064: *
065: * @author <a href="mailto:gbrigand@josso.org">Gianluca Brigandi</a>
066: * @version CVS $Id: ComponentKeeperImpl.java 508 2008-02-18 13:32:29Z sgonzalez $
067: */
068:
069: public class ComponentKeeperImpl implements ComponentKeeper {
070:
071: /**
072: * JOSSO Agent confreturn null; //To change body of implemented methods use File | Settings | File Templates.ig file name.
073: */
074: public static final String JOSSO_AGENT_CONFIG = "josso-agent-config.xml";
075:
076: /**
077: * JOSSO Gateway config file name.
078: */
079: public static final String JOSSO_GWY_CONFIG = "josso-gateway-config.xml";
080:
081: private static final Log logger = LogFactory
082: .getLog(ComponentKeeperImpl.class);
083:
084: // TODO : Support multiple security domains ?
085: protected String _securityDomainName;
086:
087: // Stack to keep track of configuration process. Components are pushed/poped from the stack as they are built.
088: protected Stack _cfg;
089:
090: // JOSSO Config URL
091: private URL jossoCfgUrl;
092:
093: // JOSSO Confi file name
094: private ConfigurationContext jossoAgentConfigurationContext;
095:
096: private ConfigurationContext jossoGatewayConfigurationContext;
097:
098: /**
099: * Package private constructor so that it can be instantiated
100: * only by Lookup.
101: */
102: public ComponentKeeperImpl() {
103: // Stack to keep track of configuration tree.
104: _cfg = new Stack();
105:
106: // TODO : make this server independent
107: // TODO : this should be used by the ComponenetKeeper, to avoid updating a different config file ?
108: String url = null;
109: if (System.getProperty("josso.config.url") != null) {
110: url = System.getProperty("josso.config.url");
111: if (logger.isDebugEnabled())
112: logger.debug("Using josso.config.url : " + url);
113:
114: } else if (System.getProperty("jboss.server.config.url") != null) {
115: url = System.getProperty("jboss.server.config.url");
116: if (logger.isDebugEnabled())
117: logger.debug("Using jboss.server.config.url : " + url);
118:
119: } else if (System.getProperty("catalina.home") != null) {
120: url = "file:" + System.getProperty("catalina.home")
121: + "/bin/";
122:
123: if (logger.isDebugEnabled()) {
124: logger.debug("Using catalina.home : "
125: + System.getProperty("catalina.home"));
126: }
127: }
128:
129: // Verify if configuration files should be dinamically updated.
130: boolean allowCfgUpdates = true;
131: if (System
132: .getProperty(ConfigurationContext.SYS_PROP_CONFIGURATION_UPDATABLE) != null) {
133: allowCfgUpdates = Boolean
134: .valueOf(
135: System
136: .getProperty(ConfigurationContext.SYS_PROP_CONFIGURATION_UPDATABLE))
137: .booleanValue();
138: }
139:
140: // Verify if configuration files should be copied prior to modification.
141: boolean backupConfiguration = true;
142: if (System
143: .getProperty(ConfigurationContext.SYS_PROP_CONFIGURATION_BACKUP) != null) {
144: backupConfiguration = Boolean
145: .valueOf(
146: System
147: .getProperty(ConfigurationContext.SYS_PROP_CONFIGURATION_BACKUP))
148: .booleanValue();
149: }
150:
151: logger.info("Configuration files : " + url);
152: logger.info("Allow configuration updates : "
153: + allowCfgUpdates);
154: logger.info("Backup configuration on updates : "
155: + backupConfiguration);
156:
157: // Build file descriptors from system properties :
158: if (url != null) {
159:
160: try {
161:
162: jossoCfgUrl = new URL(url);
163:
164: File f1 = new File(jossoCfgUrl.getFile()
165: + JOSSO_AGENT_CONFIG);
166: jossoAgentConfigurationContext = new ConfigurationContextImpl(
167: f1, allowCfgUpdates, backupConfiguration);
168:
169: File f2 = new File(jossoCfgUrl.getFile()
170: + JOSSO_GWY_CONFIG);
171: jossoGatewayConfigurationContext = new ConfigurationContextImpl(
172: f2, allowCfgUpdates, backupConfiguration);
173:
174: } catch (MalformedURLException e) {
175: logger.error("Invalid JOSSO config URL : " + url);
176: }
177: }
178:
179: }
180:
181: public SecurityDomain fetchSecurityDomain() throws Exception {
182:
183: try {
184:
185: Configuration config = loadConfig("josso-config.xml");
186:
187: SecurityDomain sd = new SecurityDomainImpl();
188: fillProperties(config, sd, new String[] { "class" });
189: // Set security domain name before start fetching ...
190: _securityDomainName = sd.getName();
191:
192: _cfg.clear();
193: _cfg.push(sd);
194:
195: // This service should be available when all other services start ...
196: SSOEventManager em = fetchEventManager(config
197: .subset("sso-event-manager"));
198: sd.setEventManager(em);
199:
200: // JOSSO Standard services
201: Authenticator a = fetchAuthenticator(config
202: .subset("authenticator"));
203: sd.setAuthenticator(a);
204:
205: SSOIdentityManager im = fetchIdentityManager(config
206: .subset("sso-identity-manager"));
207: sd.setIdentityManager(im);
208:
209: SSOSessionManager sm = fetchSessionManager(config
210: .subset("sso-session-manager"));
211: sd.setSessionManager(sm);
212:
213: SSOAuditManager am = fetchAuditManager(config
214: .subset("sso-audit-manager"));
215: sd.setAuditManager(am);
216:
217: _cfg.pop();
218:
219: return sd;
220:
221: } catch (ConfigurationException ce) {
222: logger.error(ce.getMessage(), ce);
223: return null;
224: }
225:
226: }
227:
228: protected Authenticator fetchAuthenticator(Configuration config)
229: throws Exception {
230: String clazz = config.getString("class");
231: Authenticator a = (Authenticator) Class.forName(clazz)
232: .newInstance();
233: fillProperties(config, a, new String[] { "class" });
234:
235: _cfg.push(a);
236: // The AuthenticationScheme
237: AuthenticationScheme[] as = fetchAuthenticationSchemes(config);
238: a.setAuthenticationSchemes(as);
239: _cfg.pop();
240:
241: return a;
242: }
243:
244: protected AuthenticationScheme[] fetchAuthenticationSchemes(
245: Configuration config) throws Exception {
246:
247: List authSchemes = new ArrayList();
248: Collection c;
249:
250: if (!(config
251: .getProperty("authentication-schemes.authentication-scheme.name") instanceof java.util.Collection)) {
252: List nCol = new ArrayList();
253: nCol
254: .add(config
255: .getProperty("authentication-schemes.authentication-scheme.name"));
256: c = nCol;
257: } else
258: c = (Collection) config
259: .getProperty("authentication-schemes.authentication-scheme.name");
260:
261: for (int i = 0; i < c.size(); i++) {
262: Configuration asConfig = config
263: .subset("authentication-schemes.authentication-scheme("
264: + i + ")");
265: AuthenticationScheme as = fetchAuthenticationScheme(asConfig);
266: authSchemes.add(as);
267: }
268:
269: return (AuthenticationScheme[]) authSchemes
270: .toArray(new AuthenticationScheme[authSchemes.size()]);
271: }
272:
273: /**
274: public AuthenticationScheme fetchAuthenticationScheme() throws Exception {
275:
276: Configuration config = loadConfig("josso-config.xml");
277: AuthenticationScheme as = fetchAuthenticationScheme(config.subset("authenticator.authentication-scheme"));
278: return as;
279:
280: }
281: **/
282:
283: protected SSOIdentityManager fetchIdentityManager(
284: Configuration config) throws Exception {
285:
286: String clazz = config.getString("class");
287: SSOIdentityManager im = (SSOIdentityManager) Class.forName(
288: clazz).newInstance();
289:
290: // the identity store
291: IdentityStore is = fetchIdentityStore(config
292: .subset("sso-identity-store"));
293:
294: IdentityStoreKeyAdapter iska = fetchIdentityStoreKeyAdapter(config
295: .subset("sso-identity-store-key-adapter"));
296:
297: im.setIdentityStore(is);
298: im.setIdentityStoreKeyAdapter(iska);
299:
300: fillProperties(config, im, new String[] { "class" });
301:
302: return im;
303: }
304:
305: protected IdentityStore fetchIdentityStore(Configuration config)
306: throws Exception {
307: String clazz = config.getString("class");
308: IdentityStore is = (IdentityStore) Class.forName(clazz)
309: .newInstance();
310:
311: fillProperties(config, is, new String[] { "class" });
312: return is;
313: }
314:
315: protected IdentityStoreKeyAdapter fetchIdentityStoreKeyAdapter(
316: Configuration config) throws Exception {
317: String clazz = config.getString("class");
318: IdentityStoreKeyAdapter iska = (IdentityStoreKeyAdapter) Class
319: .forName(clazz).newInstance();
320:
321: fillProperties(config, iska, new String[] { "class" });
322: return iska;
323: }
324:
325: protected AuthenticationScheme fetchAuthenticationScheme(
326: Configuration config) throws Exception {
327:
328: String clazz = config.getString("class");
329: AuthenticationScheme as = (AuthenticationScheme) Class.forName(
330: clazz).newInstance();
331: fillProperties(config, as, new String[] { "class" });
332:
333: _cfg.push(as);
334:
335: CredentialStore cs = fetchCredentialStore(config
336: .subset("credential-store"));
337:
338: cs.setAuthenticationScheme(as);
339: as.setCredentialStore(cs);
340:
341: CredentialStoreKeyAdapter cska = fetchCredentialStoreKeyAdapter(config
342: .subset("credential-store-key-adapter"));
343: as.setCredentialStoreKeyAdapter(cska);
344:
345: _cfg.pop();
346:
347: return as;
348: }
349:
350: protected CredentialStore fetchCredentialStore(Configuration config)
351: throws Exception {
352: String clazz = config.getString("class");
353: CredentialStore cs = (CredentialStore) Class.forName(clazz)
354: .newInstance();
355: fillProperties(config, cs, new String[] { "class" });
356: _cfg.push(cs);
357: _cfg.pop();
358: return cs;
359: }
360:
361: protected CredentialStoreKeyAdapter fetchCredentialStoreKeyAdapter(
362: Configuration config) throws Exception {
363: String clazz = config.getString("class");
364: CredentialStoreKeyAdapter cska = (CredentialStoreKeyAdapter) Class
365: .forName(clazz).newInstance();
366: fillProperties(config, cska, new String[] { "class" });
367: _cfg.push(cska);
368: _cfg.pop();
369: return cska;
370: }
371:
372: protected SSOSessionManager fetchSessionManager(Configuration config)
373: throws Exception {
374:
375: String clazz = config.getString("class");
376: SSOSessionManager sm = (SSOSessionManager) Class.forName(clazz)
377: .newInstance();
378:
379: // the session store
380: SessionStore ss = fetchSessionStore(config
381: .subset("sso-session-store"));
382: SessionIdGenerator sig = fetchSessionIdGenerator(config
383: .subset("sso-session-id-generator"));
384:
385: sm.setSessionStore(ss);
386: sm.setSessionIdGenerator(sig);
387:
388: fillProperties(config, sm, new String[] { "class" });
389:
390: return sm;
391: }
392:
393: protected SessionStore fetchSessionStore(Configuration config)
394: throws Exception {
395: String clazz = config.getString("class");
396: SessionStore ss = (SessionStore) Class.forName(clazz)
397: .newInstance();
398:
399: fillProperties(config, ss, new String[] { "class" });
400: return ss;
401: }
402:
403: protected SessionIdGenerator fetchSessionIdGenerator(
404: Configuration config) throws Exception {
405: String clazz = config.getString("class");
406: SessionIdGenerator sig = (SessionIdGenerator) Class.forName(
407: clazz).newInstance();
408:
409: fillProperties(config, sig, new String[] { "class" });
410: return sig;
411: }
412:
413: protected SSOEventManager fetchEventManager(Configuration config)
414: throws Exception {
415:
416: String clazz = config.getString("class");
417:
418: if (logger.isDebugEnabled())
419: logger.debug("Using SSOEventManager : " + clazz);
420:
421: SSOEventManager em = (SSOEventManager) Class.forName(clazz)
422: .newInstance();
423: fillProperties(config, em, new String[] { "class" });
424:
425: List listeners = fetchEventListeners(config);
426: for (int i = 0; i < listeners.size(); i++) {
427: org.josso.gateway.event.SSOEventListener listener = (SSOEventListener) listeners
428: .get(i);
429: em.registerListener(listener);
430: }
431:
432: return em;
433:
434: }
435:
436: protected List fetchEventListeners(Configuration config)
437: throws Exception {
438: List listeners = new ArrayList();
439: Collection c;
440: if (!(config.getProperty("listeners.listener.class") instanceof java.util.Collection)) {
441: List nCol = new ArrayList();
442: nCol.add(config.getProperty("listeners.listener.class"));
443: c = nCol;
444: } else
445: c = (Collection) config
446: .getProperty("listeners.listener.class");
447:
448: for (int i = 0; i < c.size(); i++) {
449: String clazz = config.getString("listeners.listener(" + i
450: + ").class");
451: if (clazz != null) {
452: SSOEventListener listener = (SSOEventListener) Class
453: .forName(clazz).newInstance();
454:
455: Configuration subset = config
456: .subset("listeners.listener(" + i + ")");
457: fillProperties(subset, listener,
458: new String[] { "class" });
459: listeners.add(listener);
460: }
461: }
462:
463: return listeners;
464: }
465:
466: protected SSOAuditManager fetchAuditManager(Configuration config)
467: throws Exception {
468:
469: String clazz = config.getString("class");
470: SSOAuditManager am;
471:
472: // If no class was specified ...
473: if (logger.isDebugEnabled())
474: logger.debug("Using SSOAuditManager : " + clazz);
475:
476: am = (SSOAuditManager) Class.forName(clazz).newInstance();
477: fillProperties(config, am, new String[] { "class", "handlers" });
478:
479: // Only if this is configured, we add handlers ...
480: List handlers = fetchAuditHandlers(config);
481: for (int i = 0; i < handlers.size(); i++) {
482: SSOAuditTrailHandler handler = (SSOAuditTrailHandler) handlers
483: .get(i);
484: am.addHandler(handler);
485: }
486:
487: return am;
488:
489: }
490:
491: protected List fetchAuditHandlers(Configuration config)
492: throws Exception {
493: List handlers = new ArrayList();
494: Collection c;
495: if (!(config.getProperty("handlers.handler.class") instanceof java.util.Collection)) {
496: List nCol = new ArrayList();
497: nCol.add(config.getProperty("handlers.handler.class"));
498: c = nCol;
499: } else
500: c = (Collection) config
501: .getProperty("handlers.handler.class");
502:
503: for (int i = 0; i < c.size(); i++) {
504: String clazz = config.getString("handlers.handler(" + i
505: + ").class");
506: if (clazz != null) {
507: SSOAuditTrailHandler handler = (SSOAuditTrailHandler) Class
508: .forName(clazz).newInstance();
509:
510: Configuration subset = config
511: .subset("handlers.handler(" + i + ")");
512: fillProperties(subset, handler,
513: new String[] { "class" });
514: handlers.add(handler);
515: } else {
516: logger.warn("No SSOAuditTrailHandler configured");
517: }
518: }
519:
520: return handlers;
521: }
522:
523: // ----------------------------------------------------------------------------------------
524:
525: /**
526: * Instantiates and configurates an SSOAgent.
527: */
528: public SSOAgent fetchSSOAgent() throws Exception {
529: try {
530: Configuration config = loadConfig("josso-config.xml");
531:
532: String agentClass = config.getString("class");
533:
534: SSOAgent agent = (SSOAgent) Class.forName(agentClass)
535: .newInstance();
536: SSOAgentConfiguration cfg = fetchSSOAgentConfiguration(config);
537: agent.setConfiguration(cfg);
538:
539: GatewayServiceLocator gsl = fetchGatewayServiceLocator(config
540: .subset("service-locator"));
541:
542: agent.setGatewayServiceLocator(gsl);
543:
544: fillProperties(config, agent, new String[] { "class" });
545:
546: return agent;
547: } catch (ConfigurationException ce) {
548: throw ce;
549: }
550:
551: }
552:
553: public SSOAgentConfiguration fetchSSOAgentConfiguration(
554: Configuration config) {
555:
556: SSOAgentConfiguration cfg = new SSOAgentConfigurationImpl();
557: if (config.getList("partner-apps.partner-app.context").size() < 1) {
558: return cfg;
559: }
560:
561: Collection c;
562: if (!(config.getProperty("partner-apps.partner-app.context") instanceof java.util.Collection)) {
563: List nCol = new ArrayList();
564: nCol.add(config
565: .getProperty("partner-apps.partner-app.context"));
566: c = nCol;
567: } else
568: c = (Collection) config
569: .getProperty("partner-apps.partner-app.context");
570:
571: for (int i = 0; i < c.size(); i++) {
572: String context = config
573: .getString("partner-apps.partner-app(" + i
574: + ").context");
575: String[] ignoredWebResources = fetchIgnoredWebResources(c
576: .size() <= 1 ? config
577: .subset("partner-apps.partner-app") : config
578: .subset("partner-apps.partner-app(" + i + ")"));
579:
580: cfg.addSSOPartnerApp(context, ignoredWebResources);
581: }
582:
583: return cfg;
584:
585: }
586:
587: protected String[] fetchIgnoredWebResources(Configuration config) {
588:
589: if (config.getList(
590: "security-constraint.ignore-web-resource-collection")
591: .size() < 1) {
592: return new String[0];
593: }
594:
595: return config
596: .getStringArray("security-constraint.ignore-web-resource-collection");
597:
598: }
599:
600: /**
601: * Instantiates and configures an SSOAgent.
602: */
603: public ReverseProxyConfiguration fetchReverseProxyConfiguration()
604: throws Exception {
605: try {
606: ReverseProxyConfiguration rpConfig = new ReverseProxyConfigurationImpl();
607:
608: Configuration config = loadConfig("josso-config.xml");
609:
610: Collection c;
611: if (!(config
612: .getProperty("proxy-contexts.proxy-context.name") instanceof java.util.Collection)) {
613: List nCol = new ArrayList();
614: nCol
615: .add(config
616: .getProperty("proxy-contexts.proxy-context.name"));
617: c = nCol;
618: } else
619: c = (Collection) config
620: .getProperty("proxy-contexts.proxy-context.name");
621:
622: for (int i = 0; i < c.size(); i++) {
623: String name = config
624: .getString("proxy-contexts.proxy-context(" + i
625: + ").name");
626: String context = config
627: .getString("proxy-contexts.proxy-context(" + i
628: + ").context");
629: String forwardHost = config
630: .getString("proxy-contexts.proxy-context(" + i
631: + ").forward-host");
632: String forwardUri = null;
633:
634: // Uri is optional
635: if (config.containsKey("proxy-contexts.proxy-context("
636: + i + ").forward-uri")) {
637: forwardUri = config
638: .getString("proxy-contexts.proxy-context("
639: + i + ").forward-uri");
640: }
641:
642: rpConfig.addProxyContext(name, context, forwardHost,
643: forwardUri);
644:
645: }
646:
647: return rpConfig;
648: } catch (ConfigurationException ce) {
649: return null;
650: }
651:
652: }
653:
654: /**
655: * Instantiates and configures a Gateway Service Locator.
656: *
657: */
658: public GatewayServiceLocator fetchGatewayServiceLocator(
659: Configuration config) throws Exception {
660: String clazz = config.getString("class");
661: GatewayServiceLocator gsl = (GatewayServiceLocator) Class
662: .forName(clazz).newInstance();
663:
664: fillProperties(config, gsl, new String[] { "class" });
665:
666: return gsl;
667: }
668:
669: public SSOWebConfiguration fetchSSOWebConfiguration()
670: throws Exception {
671: try {
672: SSOWebConfigurationImpl ssoWebConfig = new SSOWebConfigurationImpl();
673:
674: Configuration config = loadConfig("josso-config.xml");
675:
676: // Get SSO Web configuration.
677: Configuration subConfig = config.subset("sso-web-config");
678: fillProperties(subConfig, ssoWebConfig, new String[0]);
679:
680: // Get session token configuration
681: Configuration sessionTokenCfg = config
682: .subset("sso-web-config.session-token");
683: if (!sessionTokenCfg.isEmpty()) {
684:
685: String secure = sessionTokenCfg.getString("secure");
686:
687: ssoWebConfig.setSessionTokenSecure(secure);
688: }
689:
690: return ssoWebConfig;
691:
692: } catch (ConfigurationException ce) {
693: return null;
694: }
695: }
696:
697: // Utils
698:
699: private Configuration loadConfig(String configResourceName)
700: throws Exception {
701: ConfigurationFactory factory = new ConfigurationFactory();
702: URL configURL = getClass()
703: .getResource("/" + configResourceName);
704:
705: // try current directory if can't find in classpath
706: if (configURL == null)
707: configURL = new File(configResourceName).toURL();
708:
709: if (configURL == null)
710: throw new java.lang.UnsupportedOperationException(
711: "Can't find '" + configResourceName + "'");
712:
713: factory.setConfigurationURL(configURL);
714:
715: Configuration c = factory.getConfiguration();
716:
717: logger.info("SSO Config from [" + configURL + "]");
718:
719: // System.out.println("----------------------------------");
720: // ConfigurationUtils.dump(c, System.out);
721: // System.out.println("\n----------------------------------");
722:
723: return c;
724: }
725:
726: private void fillProperties(Configuration config, Object target,
727: String exclude[]) throws Exception {
728: Iterator keys = getKeys(config);
729:
730: while (keys.hasNext()) {
731: String key = (String) keys.next();
732:
733: boolean excluded = false;
734: for (int i = 0; i < exclude.length; i++)
735: if (exclude[i].equalsIgnoreCase(key)) {
736: excluded = true;
737: break;
738: }
739:
740: if (excluded)
741: continue;
742:
743: if (logger.isDebugEnabled())
744: logger.debug("Trying to set property [" + key
745: + "] to component : "
746: + target.getClass().getName());
747:
748: String propertyMethodName = "set"
749: + Character.toUpperCase(key.charAt(0))
750: + key.substring(1);
751:
752: if (!config.containsKey(key))
753: continue;
754:
755: String propertyValue = config.getString(key);
756:
757: try {
758: Method m = target.getClass().getMethod(
759: propertyMethodName,
760: new Class[] { String.class });
761: m.invoke(target, new String[] { propertyValue });
762: } catch (NoSuchMethodException e) {
763: if (logger.isDebugEnabled())
764: logger.debug("Method : " + propertyMethodName
765: + " not defined in component : "
766: + target.getClass().getName());
767: }
768: }
769:
770: }
771:
772: /**
773: * Given a Configuration of SubsetConfiguration instance, returns the associated
774: * relative keys.
775: *
776: * @param cfg the Configuration instance for whom keys are needed.
777: *
778: */
779: private Iterator getKeys(Configuration cfg) {
780: List targetKeys = new ArrayList();
781:
782: if (!(cfg instanceof SubsetConfiguration)) {
783: Iterator keys = cfg.getKeys();
784: while (keys.hasNext()) {
785: String key = (String) keys.next();
786:
787: if (key.indexOf('.') == -1) {
788: targetKeys.add(key);
789: }
790: }
791:
792: } else {
793:
794: SubsetConfiguration sc = (SubsetConfiguration) cfg;
795:
796: String prefix = sc.getPrefix();
797:
798: prefix = prefix.replaceAll("\\([0-9]+\\)", "");
799:
800: Iterator keys = sc.getParent().getKeys(prefix);
801:
802: while (keys.hasNext()) {
803: String key = (String) keys.next();
804: String key2 = key.substring(prefix.length() + 1);
805: if (key2.indexOf('.') != -1)
806: continue;
807:
808: String propertyName = key.substring(key
809: .lastIndexOf(".") + 1);
810: targetKeys.add(propertyName);
811: }
812: }
813: return targetKeys.iterator();
814: }
815:
816: protected ConfigurationContext getSSOAgentConfigurationContext() {
817: return jossoAgentConfigurationContext;
818: }
819:
820: protected ConfigurationContext getSSOGatewayConfigurationContext() {
821: return jossoGatewayConfigurationContext;
822: }
823:
824: }
|