Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FISH-7340 Remove obsolete EJBContext methods #6268

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -50,17 +50,23 @@

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;
import jakarta.transaction.Transaction;
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.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -70,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,
Expand Down Expand Up @@ -133,7 +139,8 @@ protected EJBContextImpl(Object ejb, BaseContainer container) {
isRemoteInterfaceSupported = container.isRemoteInterfaceSupported();
isLocalInterfaceSupported = container.isLocalInterfaceSupported();
}


@Override
public Transaction getTransaction() {
return transaction;
}
Expand Down Expand Up @@ -237,11 +244,12 @@ public void touch() {
/**
*
*/
@Override
public Object getEJB() {
return ejb;
}


@Override
public Container getContainer() {
return container;
}
Expand All @@ -251,26 +259,30 @@ public Container getContainer() {
* associated with this Context.
*/
public void registerResource(ResourceHandle h) {
if ( resources == null )
if (resources == null) {
resources = new ArrayList();
}
resources.add(h);
}

/**
* Unregister a resource from this Context.
*/
public void unregisterResource(ResourceHandle h) {
if ( resources == null )
if (resources == null) {
resources = new ArrayList();
}
resources.remove(h);
}

/**
* Get all the resources associated with the context
*/
@Override
public List getResourceList() {
if (resources == null)
if (resources == null) {
resources = new ArrayList(0);
}
return resources;
}

Expand Down Expand Up @@ -316,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");
}
Expand All @@ -329,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");
}
Expand All @@ -344,6 +352,7 @@ public EJBLocalObject getEJBLocalObject()
/**
*
*/
@Override
public EJBHome getEJBHome() {
if (! isRemoteInterfaceSupported) {
throw new IllegalStateException("EJBHome not available");
Expand All @@ -356,34 +365,16 @@ public EJBHome getEJBHome() {
/**
*
*/
@Override
public EJBLocalHome getEJBLocalHome() {
if (! isLocalInterfaceSupported) {
throw new IllegalStateException("EJBLocalHome not available");
}

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;

Expand All @@ -409,6 +400,7 @@ public Object lookup(String name) {
/**
*
*/
@Override
public Principal getCallerPrincipal() {

checkAccessToCallerSecurity();
Expand All @@ -421,8 +413,9 @@ public Principal getCallerPrincipal() {
/**
* @return Returns the contextMetaData.
*/
@Override
public Map<String, Object> getContextData() {
Map<String, Object> contextData = (Map<String, Object>) Collections.EMPTY_MAP;
Map<String, Object> contextData = Collections.emptyMap();
ComponentInvocation inv = EjbContainerUtilImpl.getInstance().getCurrentInvocation();
if ( inv instanceof EjbInvocation ) {
EjbInvocation ejbInv = (EjbInvocation) inv;
Expand All @@ -431,55 +424,42 @@ public Map<String, Object> 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 )
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");
}

/**
*
*/
public UserTransaction getUserTransaction()
throws IllegalStateException
{
@Override
public UserTransaction getUserTransaction() throws IllegalStateException {
throw new IllegalStateException("Operation not allowed");
}

/**
*
*/
public void setRollbackOnly()
throws IllegalStateException
{
@Override
public void setRollbackOnly() throws IllegalStateException {
if (state == BeanState.CREATED)
throw new IllegalStateException("EJB not in READY state");

Expand Down Expand Up @@ -509,18 +489,15 @@ public void setRollbackOnly()
tm.setRollbackOnly();

} catch (Exception ex) {
IllegalStateException illEx = new IllegalStateException(ex.toString());
illEx.initCause(ex);
throw illEx;
throw new IllegalStateException(ex);
}
}

/**
*
*/
public boolean getRollbackOnly()
throws IllegalStateException
{
@Override
public boolean getRollbackOnly() throws IllegalStateException {
if (state == BeanState.CREATED)
throw new IllegalStateException("EJB not in READY state");

Expand Down Expand Up @@ -595,21 +572,17 @@ public Object[] getInterceptorInstances() {
* is covered by this check. It is overridden in the applicable concrete
* context impl subclasses.
*/
public void checkTimerServiceMethodAccess()
throws IllegalStateException
{
@Override
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() {
Expand Down Expand Up @@ -657,5 +630,4 @@ void deleteAllReferences() {
ejbLocalObjectImpl = null;
ejbLocalBusinessObjectImpl = null;
}

}