From 280b0f88cdafb8df4219b00f5c0d71386b262703 Mon Sep 17 00:00:00 2001 From: Eirik Bjorsnos Date: Thu, 20 Apr 2023 08:23:43 +0200 Subject: [PATCH 1/2] Remove the EJBContextImpl implementation of methods getEnvironment, getCallerIdentity removed in Jakarta EE 9. Also add @Override for all overriding methods such that future removals may be detected. --- .../sun/ejb/containers/EJBContextImpl.java | 51 ++++++------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContextImpl.java b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContextImpl.java index f164a6591d2..a6c771438dd 100644 --- a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContextImpl.java +++ b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContextImpl.java @@ -58,7 +58,6 @@ import jakarta.transaction.TransactionManager; import jakarta.transaction.UserTransaction; import java.lang.reflect.Method; -import java.security.Identity; import java.security.Principal; import java.util.*; import java.util.logging.Level; @@ -133,7 +132,8 @@ protected EJBContextImpl(Object ejb, BaseContainer container) { isRemoteInterfaceSupported = container.isRemoteInterfaceSupported(); isLocalInterfaceSupported = container.isLocalInterfaceSupported(); } - + + @Override public Transaction getTransaction() { return transaction; } @@ -237,11 +237,12 @@ public void touch() { /** * */ + @Override public Object getEJB() { return ejb; } - - + + @Override public Container getContainer() { return container; } @@ -268,6 +269,7 @@ public void unregisterResource(ResourceHandle h) { /** * Get all the resources associated with the context */ + @Override public List getResourceList() { if (resources == null) resources = new ArrayList(0); @@ -344,6 +346,7 @@ public EJBLocalObject getEJBLocalObject() /** * */ + @Override public EJBHome getEJBHome() { if (! isRemoteInterfaceSupported) { throw new IllegalStateException("EJBHome not available"); @@ -356,6 +359,7 @@ public EJBHome getEJBHome() { /** * */ + @Override public EJBLocalHome getEJBLocalHome() { if (! isLocalInterfaceSupported) { throw new IllegalStateException("EJBLocalHome not available"); @@ -363,27 +367,8 @@ public EJBLocalHome getEJBLocalHome() { return container.getEJBLocalHome(); } - - - /** - * - */ - public Properties getEnvironment() { - // This is deprecated, see EJB2.0 section 20.6. - return container.getEnvironmentProperties(); - } - - /** - * @deprecated - */ - public Identity getCallerIdentity() { - // This method is deprecated. - // see EJB2.0 section 21.2.5 - throw new RuntimeException( - "getCallerIdentity() is deprecated, please use getCallerPrincipal()."); - } - + @Override public Object lookup(String name) { Object o = null; @@ -409,6 +394,7 @@ public Object lookup(String name) { /** * */ + @Override public Principal getCallerPrincipal() { checkAccessToCallerSecurity(); @@ -421,6 +407,7 @@ public Principal getCallerPrincipal() { /** * @return Returns the contextMetaData. */ + @Override public Map getContextData() { Map contextData = (Map) Collections.EMPTY_MAP; ComponentInvocation inv = EjbContainerUtilImpl.getInstance().getCurrentInvocation(); @@ -431,20 +418,10 @@ public Map getContextData() { return contextData; } - - /** - * @deprecated - */ - public boolean isCallerInRole(Identity identity) { - // THis method is deprecated. - // This implementation is as in EJB2.0 section 21.2.5 - return isCallerInRole(identity.getName()); - } - - /** * */ + @Override public boolean isCallerInRole(String roleRef) { if ( roleRef == null ) throw new IllegalStateException("Argument is null"); @@ -468,6 +445,7 @@ protected void checkAccessToCallerSecurity() /** * */ + @Override public UserTransaction getUserTransaction() throws IllegalStateException { @@ -477,6 +455,7 @@ public UserTransaction getUserTransaction() /** * */ + @Override public void setRollbackOnly() throws IllegalStateException { @@ -518,6 +497,7 @@ public void setRollbackOnly() /** * */ + @Override public boolean getRollbackOnly() throws IllegalStateException { @@ -595,6 +575,7 @@ public Object[] getInterceptorInstances() { * is covered by this check. It is overridden in the applicable concrete * context impl subclasses. */ + @Override public void checkTimerServiceMethodAccess() throws IllegalStateException { From 83b152f0b4d0b389148a9c9f05fd908cb7d05d15 Mon Sep 17 00:00:00 2001 From: Petr Aubrecht Date: Thu, 17 Aug 2023 15:37:21 +0200 Subject: [PATCH 2/2] FISH-7340 update copyright, improve formatting a bit --- .../sun/ejb/containers/EJBContextImpl.java | 73 ++++++++----------- 1 file changed, 32 insertions(+), 41 deletions(-) diff --git a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContextImpl.java b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContextImpl.java index a6c771438dd..eccd492dbde 100644 --- a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContextImpl.java +++ b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContextImpl.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2021] [Payara Foundation and/or its affiliates.] +// Portions Copyright [2016-2023] [Payara Foundation and/or its affiliates.] package com.sun.ejb.containers; @@ -50,7 +50,11 @@ import com.sun.enterprise.container.common.spi.JCDIService; -import jakarta.ejb.*; +import jakarta.ejb.EJBContext; +import jakarta.ejb.EJBHome; +import jakarta.ejb.EJBLocalHome; +import jakarta.ejb.EJBLocalObject; +import jakarta.ejb.EJBObject; import javax.naming.Context; import javax.naming.InitialContext; import jakarta.transaction.Status; @@ -59,7 +63,10 @@ import jakarta.transaction.UserTransaction; import java.lang.reflect.Method; import java.security.Principal; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -69,8 +76,8 @@ */ public abstract class EJBContextImpl - implements EJBContext, ComponentContext, java.io.Serializable -{ + implements EJBContext, ComponentContext, java.io.Serializable { + static final Logger _logger = EjbContainerUtilImpl.getLogger(); public enum BeanState {CREATED, POOLED, READY, INVOKING, INCOMPLETE_TX, @@ -252,8 +259,9 @@ public Container getContainer() { * associated with this Context. */ public void registerResource(ResourceHandle h) { - if ( resources == null ) + if (resources == null) { resources = new ArrayList(); + } resources.add(h); } @@ -261,8 +269,9 @@ public void registerResource(ResourceHandle h) { * Unregister a resource from this Context. */ public void unregisterResource(ResourceHandle h) { - if ( resources == null ) + if (resources == null) { resources = new ArrayList(); + } resources.remove(h); } @@ -271,8 +280,9 @@ public void unregisterResource(ResourceHandle h) { */ @Override public List getResourceList() { - if (resources == null) + if (resources == null) { resources = new ArrayList(0); + } return resources; } @@ -318,9 +328,7 @@ public synchronized void decrementConcurrentInvokeCount() { /** * This is a SessionContext/EntityContext method. */ - public EJBObject getEJBObject() - throws IllegalStateException - { + public EJBObject getEJBObject() throws IllegalStateException { if (ejbStub == null) { throw new IllegalStateException("EJBObject not available"); } @@ -331,9 +339,7 @@ public EJBObject getEJBObject() /** * This is a SessionContext/EntityContext method. */ - public EJBLocalObject getEJBLocalObject() - throws IllegalStateException - { + public EJBLocalObject getEJBLocalObject() throws IllegalStateException { if ( ejbLocalObjectImpl == null ) { throw new IllegalStateException("EJBLocalObject not available"); } @@ -407,9 +413,9 @@ public Principal getCallerPrincipal() { /** * @return Returns the contextMetaData. */ - @Override + @Override public Map getContextData() { - Map contextData = (Map) Collections.EMPTY_MAP; + Map contextData = Collections.emptyMap(); ComponentInvocation inv = EjbContainerUtilImpl.getInstance().getCurrentInvocation(); if ( inv instanceof EjbInvocation ) { EjbInvocation ejbInv = (EjbInvocation) inv; @@ -423,22 +429,21 @@ public Map getContextData() { */ @Override public boolean isCallerInRole(String roleRef) { - if ( roleRef == null ) + if (roleRef == null) { throw new IllegalStateException("Argument is null"); + } checkAccessToCallerSecurity(); com.sun.enterprise.security.SecurityManager sm = container.getSecurityManager(); - return sm.isCallerInRole(roleRef); + return sm.isCallerInRole(roleRef); } /** * Overridden in containers that allow access to isCallerInRole() and * getCallerPrincipal() */ - protected void checkAccessToCallerSecurity() - throws IllegalStateException - { + protected void checkAccessToCallerSecurity() throws IllegalStateException { throw new IllegalStateException("Operation not allowed"); } @@ -446,9 +451,7 @@ protected void checkAccessToCallerSecurity() * */ @Override - public UserTransaction getUserTransaction() - throws IllegalStateException - { + public UserTransaction getUserTransaction() throws IllegalStateException { throw new IllegalStateException("Operation not allowed"); } @@ -456,9 +459,7 @@ public UserTransaction getUserTransaction() * */ @Override - public void setRollbackOnly() - throws IllegalStateException - { + public void setRollbackOnly() throws IllegalStateException { if (state == BeanState.CREATED) throw new IllegalStateException("EJB not in READY state"); @@ -488,9 +489,7 @@ public void setRollbackOnly() tm.setRollbackOnly(); } catch (Exception ex) { - IllegalStateException illEx = new IllegalStateException(ex.toString()); - illEx.initCause(ex); - throw illEx; + throw new IllegalStateException(ex); } } @@ -498,9 +497,7 @@ public void setRollbackOnly() * */ @Override - public boolean getRollbackOnly() - throws IllegalStateException - { + public boolean getRollbackOnly() throws IllegalStateException { if (state == BeanState.CREATED) throw new IllegalStateException("EJB not in READY state"); @@ -576,21 +573,16 @@ public Object[] getInterceptorInstances() { * context impl subclasses. */ @Override - public void checkTimerServiceMethodAccess() - throws IllegalStateException - { + public void checkTimerServiceMethodAccess() throws IllegalStateException { throw new IllegalStateException("EJB Timer Service method calls " + "cannot be called in this context"); } // Throw exception if EJB is in ejbActivate/Passivate - protected void checkActivatePassivate() - throws IllegalStateException - { + protected void checkActivatePassivate() throws IllegalStateException { if( inActivatePassivate() ) { throw new IllegalStateException("Operation not allowed."); } - } protected boolean inActivatePassivate() { @@ -638,5 +630,4 @@ void deleteAllReferences() { ejbLocalObjectImpl = null; ejbLocalBusinessObjectImpl = null; } - }