1 7 package org.jboss.security.auth.spi; 8 9 import java.util.Map ; 10 11 import javax.security.auth.Subject ; 12 import javax.security.auth.callback.CallbackHandler ; 13 import javax.security.auth.login.LoginException ; 14 import javax.security.auth.spi.LoginModule ; 15 16 28 public class ProxyLoginModule implements LoginModule 29 { 30 private String moduleName; 31 private LoginModule delegate; 32 33 public ProxyLoginModule() 34 { 35 } 36 37 47 public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) 48 { 49 moduleName = (String ) options.get("moduleName"); 50 if( moduleName == null ) 51 { 52 System.out.println("Required moduleName option not given"); 53 return; 54 } 55 56 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 58 try 59 { 60 Class clazz = loader.loadClass(moduleName); 61 delegate = (LoginModule ) clazz.newInstance(); 62 } 63 catch(Throwable 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 78 public boolean login() throws LoginException 79 { 80 if( moduleName == null ) 81 throw new LoginException ("Required moduleName option not given"); 82 if( delegate == null ) 83 throw new LoginException ("Failed to load LoginModule: "+moduleName); 84 85 return delegate.login(); 86 } 87 88 public boolean commit() throws LoginException 89 { 90 boolean ok = false; 91 if( delegate != null ) 92 ok = delegate.commit(); 93 return ok; 94 } 95 96 public boolean abort() throws LoginException 97 { 98 boolean ok = true; 99 if( delegate != null ) 100 ok = delegate.abort(); 101 return ok; 102 } 103 104 public boolean logout() throws LoginException 105 { 106 boolean ok = true; 107 if( delegate != null ) 108 ok = delegate.logout(); 109 return ok; 110 } 111 113 } 114 | Popular Tags |