KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > auth > spi > ProxyLoginModule


1 /*
2  * JBoss, the OpenSource WebOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.security.auth.spi;
8
9 import java.util.Map JavaDoc;
10
11 import javax.security.auth.Subject JavaDoc;
12 import javax.security.auth.callback.CallbackHandler JavaDoc;
13 import javax.security.auth.login.LoginException JavaDoc;
14 import javax.security.auth.spi.LoginModule JavaDoc;
15
16 /** A proxy LoginModule that loads a delegate LoginModule using
17 the current thread context class loader. The purpose of this
18 module is to work around the current JAAS class loader limitation
19 that requires LoginModules to be on the classpath. Some LoginModules
20 use core JBoss classes that would have to be moved into the jboss-jaas.jar
21 and packaging becomes a mess. Instead, these LoginModules are left
22 in the jbosssx.jar and the ProxyLoginModule is used to bootstrap
23 the non-classpath LoginModule.
24
25 @author Scott.Stark@jboss.org
26 @version $Revision: 1.6 $
27 */

28 public class ProxyLoginModule implements LoginModule JavaDoc
29 {
30     private String JavaDoc moduleName;
31     private LoginModule JavaDoc delegate;
32
33     public ProxyLoginModule()
34     {
35     }
36
37 // --- Begin LoginModule interface methods
38
/** Initialize this LoginModule. This method loads the LoginModule
39         specified by the moduleName option using the current thread
40         context class loader and then delegates the initialize call
41         to it.
42
43     @param options, include:
44         moduleName: the classname of the module that this proxy module
45         delegates all calls to.
46      */

47     public void initialize(Subject JavaDoc subject, CallbackHandler JavaDoc callbackHandler, Map JavaDoc sharedState, Map JavaDoc options)
48     {
49         moduleName = (String JavaDoc) options.get("moduleName");
50         if( moduleName == null )
51         {
52             System.out.println("Required moduleName option not given");
53             return;
54         }
55
56         // Load the delegate module using the thread class loader
57
ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
58         try
59         {
60             Class JavaDoc clazz = loader.loadClass(moduleName);
61             delegate = (LoginModule JavaDoc) clazz.newInstance();
62         }
63         catch(Throwable JavaDoc t)
64         {
65             System.out.println("ProxyLoginModule failed to load: "+moduleName);
66             t.printStackTrace();
67             return;
68         }
69
70         delegate.initialize(subject, callbackHandler, sharedState, options);
71     }
72
73     /** Perform the login. If either the moduleName option was not
74         specified or the module could not be loaded in initalize(),
75         this method throws a LoginException.
76     @exception LoginException, throw in the delegate login module failed.
77     */

78     public boolean login() throws LoginException JavaDoc
79     {
80         if( moduleName == null )
81             throw new LoginException JavaDoc("Required moduleName option not given");
82         if( delegate == null )
83             throw new LoginException JavaDoc("Failed to load LoginModule: "+moduleName);
84
85         return delegate.login();
86     }
87
88     public boolean commit() throws LoginException JavaDoc
89     {
90         boolean ok = false;
91         if( delegate != null )
92             ok = delegate.commit();
93         return ok;
94     }
95
96     public boolean abort() throws LoginException JavaDoc
97     {
98         boolean ok = true;
99         if( delegate != null )
100             ok = delegate.abort();
101         return ok;
102     }
103
104     public boolean logout() throws LoginException JavaDoc
105     {
106         boolean ok = true;
107         if( delegate != null )
108             ok = delegate.logout();
109         return ok;
110     }
111 // --- End LoginModule interface methods
112

113 }
114
Popular Tags