001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.geronimo.openejb; 019 020 import java.lang.reflect.Method; 021 import java.util.Set; 022 023 import javax.ejb.EJBHome; 024 import javax.ejb.EJBLocalHome; 025 import javax.ejb.EJBObject; 026 import javax.naming.Context; 027 import javax.security.auth.Subject; 028 import javax.security.auth.login.LoginException; 029 030 import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator; 031 import org.apache.geronimo.management.EJB; 032 import org.apache.geronimo.security.ContextManager; 033 import org.apache.geronimo.security.jacc.RunAsSource; 034 import org.apache.openejb.BeanType; 035 import org.apache.openejb.Container; 036 import org.apache.openejb.InterfaceType; 037 import org.apache.openejb.core.CoreDeploymentInfo; 038 import org.apache.openejb.core.ivm.EjbObjectProxyHandler; 039 040 public class EjbDeployment implements EJB { 041 private final String objectName; 042 private final String deploymentId; 043 private final String ejbName; 044 045 private final String homeInterfaceName; 046 private final String remoteInterfaceName; 047 private final String localHomeInterfaceName; 048 private final String localInterfaceName; 049 private final String serviceEndpointInterfaceName; 050 private final String beanClassName; 051 private final ClassLoader classLoader; 052 053 private final boolean securityEnabled; 054 private final Subject defaultSubject; 055 private final Subject runAs; 056 057 private final Context componentContext; 058 059 // connector stuff 060 private final Set unshareableResources; 061 private final Set applicationManagedSecurityResources; 062 private final TrackedConnectionAssociator trackedConnectionAssociator; 063 064 private final OpenEjbSystem openEjbSystem; 065 066 private CoreDeploymentInfo deploymentInfo; 067 068 private Context javaCompSubContext; 069 070 public EjbDeployment() throws LoginException { 071 this(null, null, null, null, null, null, null, null, null, null, 072 false, null, null, null, null, null, null, null, null); 073 } 074 075 public EjbDeployment(String objectName, 076 String deploymentId, 077 String ejbName, 078 String homeInterfaceName, 079 String remoteInterfaceName, 080 String localHomeInterfaceName, 081 String localInterfaceName, 082 String serviceEndpointInterfaceName, 083 String beanClassName, 084 ClassLoader classLoader, 085 boolean securityEnabled, 086 String defaultRole, 087 String runAsRole, 088 RunAsSource runAsSource, 089 Context componentContext, 090 Set unshareableResources, 091 Set applicationManagedSecurityResources, 092 TrackedConnectionAssociator trackedConnectionAssociator, 093 OpenEjbSystem openEjbSystem) throws LoginException { 094 this.objectName = objectName; 095 this.deploymentId = deploymentId; 096 this.ejbName = ejbName; 097 this.homeInterfaceName = homeInterfaceName; 098 this.remoteInterfaceName = remoteInterfaceName; 099 this.localHomeInterfaceName = localHomeInterfaceName; 100 this.localInterfaceName = localInterfaceName; 101 this.serviceEndpointInterfaceName = serviceEndpointInterfaceName; 102 this.beanClassName = beanClassName; 103 this.classLoader = classLoader; 104 this.securityEnabled = securityEnabled; 105 if (runAsSource == null) { 106 runAsSource = RunAsSource.NULL; 107 } 108 this.defaultSubject = defaultRole == null? runAsSource.getDefaultSubject(): runAsSource.getSubjectForRole(defaultRole); 109 this.runAs = runAsSource.getSubjectForRole(runAsRole); 110 this.componentContext = componentContext; 111 this.unshareableResources = unshareableResources; 112 this.applicationManagedSecurityResources = applicationManagedSecurityResources; 113 this.trackedConnectionAssociator = trackedConnectionAssociator; 114 this.openEjbSystem = openEjbSystem; 115 } 116 117 public CoreDeploymentInfo getDeploymentInfo() { 118 return deploymentInfo; 119 } 120 121 public String getDeploymentId() { 122 return deploymentId; 123 } 124 125 public String getEjbName() { 126 return ejbName; 127 } 128 129 public String getHomeInterfaceName() { 130 return homeInterfaceName; 131 } 132 133 public String getRemoteInterfaceName() { 134 return remoteInterfaceName; 135 } 136 137 public String getLocalHomeInterfaceName() { 138 return localHomeInterfaceName; 139 } 140 141 public String getLocalInterfaceName() { 142 return localInterfaceName; 143 } 144 145 public String getServiceEndpointInterfaceName() { 146 return serviceEndpointInterfaceName; 147 } 148 149 public String getBeanClassName() { 150 return beanClassName; 151 } 152 153 public ClassLoader getClassLoader() { 154 return classLoader; 155 } 156 157 public boolean isSecurityEnabled() { 158 return securityEnabled; 159 } 160 161 public Subject getDefaultSubject() { 162 return defaultSubject; 163 } 164 165 public Subject getRunAs() { 166 return runAs; 167 } 168 169 public Context getComponentContext() { 170 return javaCompSubContext; 171 } 172 173 public Set getUnshareableResources() { 174 return unshareableResources; 175 } 176 177 public Set getApplicationManagedSecurityResources() { 178 return applicationManagedSecurityResources; 179 } 180 181 public TrackedConnectionAssociator getTrackedConnectionAssociator() { 182 return trackedConnectionAssociator; 183 } 184 185 public EJBHome getEJBHome() { 186 return deploymentInfo.getEJBHome(); 187 } 188 189 public EJBLocalHome getEJBLocalHome() { 190 return deploymentInfo.getEJBLocalHome(); 191 } 192 193 public Object getBusinessLocalHome() { 194 return deploymentInfo.getBusinessLocalHome(); 195 } 196 197 public Object getBusinessRemoteHome() { 198 return deploymentInfo.getBusinessRemoteHome(); 199 } 200 201 public EJBObject getEjbObject(Object primaryKey) { 202 return (EJBObject) EjbObjectProxyHandler.createProxy(deploymentInfo, primaryKey, InterfaceType.EJB_HOME); 203 } 204 205 public Class getHomeInterface() { 206 return deploymentInfo.getHomeInterface(); 207 } 208 209 public Class getRemoteInterface() { 210 return deploymentInfo.getRemoteInterface(); 211 } 212 213 public Class getLocalHomeInterface() { 214 return deploymentInfo.getLocalHomeInterface(); 215 } 216 217 public Class getLocalInterface() { 218 return deploymentInfo.getLocalInterface(); 219 } 220 221 public Class getBeanClass() { 222 return deploymentInfo.getBeanClass(); 223 } 224 225 public Class getBusinessLocalInterface() { 226 return deploymentInfo.getBusinessLocalInterface(); 227 } 228 229 public Class getBusinessRemoteInterface() { 230 return deploymentInfo.getBusinessRemoteInterface(); 231 } 232 233 public Class getMdbInterface() { 234 return deploymentInfo.getMdbInterface(); 235 } 236 237 public Class getServiceEndpointInterface() { 238 return deploymentInfo.getServiceEndpointInterface(); 239 } 240 241 public BeanType getComponentType() { 242 return deploymentInfo.getComponentType(); 243 } 244 245 public Container getContainer() { 246 return deploymentInfo.getContainer(); 247 } 248 249 public boolean isBeanManagedTransaction() { 250 return deploymentInfo.isBeanManagedTransaction(); 251 } 252 253 public byte getTransactionAttribute(Method method) { 254 return deploymentInfo.getTransactionAttribute(method); 255 } 256 257 public String getObjectName() { 258 return objectName; 259 } 260 261 public boolean isStateManageable() { 262 return true; 263 } 264 265 public boolean isStatisticsProvider() { 266 return false; 267 } 268 269 public boolean isEventProvider() { 270 return true; 271 } 272 273 protected void start() throws Exception { 274 deploymentInfo = (CoreDeploymentInfo) openEjbSystem.getDeploymentInfo(deploymentId); 275 if (deploymentInfo == null) { 276 throw new IllegalStateException("Ejb does not exist " + deploymentId); 277 } 278 279 javaCompSubContext = (Context) deploymentInfo.getJndiEnc().lookup("java:comp"); 280 if (componentContext != null) { 281 javaCompSubContext.bind("geronimo", componentContext); 282 } 283 deploymentInfo.set(EjbDeployment.class, this); 284 } 285 286 protected void stop() { 287 if (deploymentInfo != null) { 288 deploymentInfo.set(EjbDeployment.class, null); 289 deploymentInfo = null; 290 } 291 } 292 }