1 9 10 package org.jboss.security.auth; 11 12 import javax.security.auth.Subject ; 13 import javax.security.auth.callback.CallbackHandler ; 14 import javax.security.auth.login.LoginContext ; 15 import javax.security.auth.login.LoginException ; 16 17 import org.jboss.deployment.DeploymentException; 18 import org.jboss.system.ServiceMBeanSupport; 19 20 26 public class SystemAuthenticator extends ServiceMBeanSupport 27 implements SystemAuthenticatorMBean 28 { 29 30 private Subject systemSubject; 31 32 private String securityDomain; 33 36 private CallbackHandler callbackHandler; 37 38 40 public String getSecurityDomain() 41 { 42 return this.securityDomain; 43 } 44 45 47 public void setSecurityDomain(String name) 48 { 49 this.securityDomain = name; 50 } 51 52 56 public Class getCallbackHandler() 57 { 58 Class clazz = null; 59 if( callbackHandler != null ) 60 clazz = callbackHandler.getClass(); 61 return clazz; 62 } 63 67 public void setCallbackHandler(Class callbackHandlerClass) 68 throws InstantiationException , IllegalAccessException 69 { 70 callbackHandler = (CallbackHandler ) callbackHandlerClass.newInstance(); 71 } 72 73 protected void startService() throws Exception 74 { 75 try 76 { 77 LoginContext lc = new LoginContext (securityDomain, callbackHandler); 78 lc.login(); 79 this.systemSubject = lc.getSubject(); 80 } 81 catch(Throwable t) 82 { 83 log.fatal("SystemAuthenticator failed, server will shutdown NOW!", t); 84 LoginException le = new LoginException ("SystemAuthenticator failed, msg="+t.getMessage()); 85 Thread shutdownThread = new Thread ("SystemAuthenticatorExitThread") 86 { 87 public void run() 88 { 89 System.exit(1); 90 } 91 }; 92 shutdownThread.start(); 93 } 94 } 95 96 protected void stopService() throws Exception 97 { 98 if( systemSubject != null ) 99 { 100 LoginContext lc = new LoginContext (securityDomain, systemSubject, callbackHandler); 101 lc.logout(); 102 } 103 } 104 } 105 | Popular Tags |