1 23 package com.sun.enterprise.appclient; 24 25 import javax.naming.InitialContext ; 26 import javax.security.auth.callback.CallbackHandler ; 27 import javax.security.auth.login.LoginContext ; 28 import javax.security.auth.login.LoginException ; 29 import com.sun.enterprise.Switch; 30 import com.sun.enterprise.NamingManager; 31 import com.sun.enterprise.InvocationManager; 32 import com.sun.enterprise.InjectionManager; 33 import com.sun.enterprise.util.InjectionManagerImpl; 34 import com.sun.enterprise.ComponentInvocation; 35 import com.sun.enterprise.J2EETransactionManager; 36 import com.sun.enterprise.deployment.ApplicationClientDescriptor; 37 import com.sun.enterprise.naming.NamingManagerImpl; 38 import com.sun.enterprise.util.InvocationManagerImpl; 39 import com.sun.enterprise.distributedtx.J2EETransactionManagerImpl; 40 import com.sun.enterprise.security.auth.LoginContextDriver; 41 import com.sun.enterprise.iiop.PEORBConfigurator; 42 43 import java.util.logging.Logger ; 44 import java.util.logging.Level ; 45 import com.sun.logging.LogDomains; 46 47 import java.util.Properties ; 48 55 public class AppContainer 56 { 57 public static final int USERNAME_PASSWORD = 1; 58 public static final int CERTIFICATE = 2; 59 public static final int ALL = 3; 61 private static final boolean debug = false; 62 63 private ApplicationClientDescriptor descriptor = null; 64 private Switch sw = null; 65 private NamingManager nm = null; 66 67 private static CallbackHandler handler = null; 71 private boolean guiAuth = true; 72 73 private static Logger _logger = LogDomains.getLogger(LogDomains.ACC_LOGGER); 74 75 78 public AppContainer(ApplicationClientDescriptor desc, boolean useGuiAuth) 79 { 80 sw = Switch.getSwitch(); 81 sw.setContainerType(Switch.APPCLIENT_CONTAINER); 82 descriptor = desc; 86 guiAuth = useGuiAuth; 87 } 88 89 93 public static CallbackHandler getCallbackHandler() { 94 return handler; 95 } 96 97 103 public String preInvoke(Properties props) throws Exception 104 { 105 InitialContext ic = new InitialContext (props); 106 107 ComponentInvocation ci = new ComponentInvocation(null, this); 108 109 InvocationManager im = new InvocationManagerImpl(); 110 sw.setInvocationManager(im); 111 112 PEORBConfigurator.initTransactionService(null, new Properties () ); 116 117 118 J2EETransactionManager tm = new J2EETransactionManagerImpl(); 119 sw.setTransactionManager(tm); 120 121 im.preInvoke(ci); 122 123 String callbackHandler = descriptor.getCallbackHandler(); 125 126 _logger.fine("Callback Handler:" + callbackHandler); 127 128 initializeCallbackHandler(callbackHandler); 129 130 131 boolean doLogin = 133 Boolean.valueOf(System.getProperty("startup.login", "false")).booleanValue(); 134 if(doLogin) { 135 _logger.info("acc.init_login"); 136 String loginMech = System.getProperty( 137 "com.sun.enterprise.loginMech", "password"); 138 if(loginMech.equalsIgnoreCase("ssl")) { 139 LoginContextDriver.doClientLogin(CERTIFICATE, handler); 140 } else if(loginMech.equalsIgnoreCase("all")) { 141 LoginContextDriver.doClientLogin(ALL, handler); 142 } else { 143 LoginContextDriver.doClientLogin(USERNAME_PASSWORD, handler); 144 } 145 } 146 147 148 nm = new NamingManagerImpl(ic); 149 sw.setNamingManager(nm); 150 151 String mainClass = descriptor.getMainClassName(); 152 sw.setDescriptorFor(this, descriptor); 153 nm.bindObjects(descriptor); 154 155 InjectionManager injectionMgr = new InjectionManagerImpl(); 157 sw.setInjectionManager(injectionMgr); 158 159 return mainClass; 160 } 161 162 166 public void postInvoke() throws Exception 167 { 168 nm.unbindObjects(descriptor); 169 } 170 171 172 178 private void initializeCallbackHandler(String callbackHandler){ 179 Class handlerClass = null; 180 handler = null; 181 182 try { 183 if(callbackHandler != null) { 184 handlerClass = Class.forName(callbackHandler); 185 handler = (CallbackHandler ) handlerClass.newInstance(); 186 } else { 187 handler = new com.sun.enterprise.security.auth.login.LoginCallbackHandler(guiAuth); 188 } 189 } catch(Exception e) { 190 _logger.log(Level.FINE, "Could not instantiate specified " + 191 "callback handler:" + e.getMessage(), e); 192 _logger.info("acc.using_default_callback"); 193 handler = new com.sun.enterprise.security.auth.login.LoginCallbackHandler(guiAuth); 194 } 195 } 196 } 197 198 | Popular Tags |