Search in sources :

Example 46 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class ContextSetupProviderImpl method createComponentInvocation.

private ComponentInvocation createComponentInvocation(ComponentInvocation currInv) {
    ComponentInvocation newInv = currInv.clone();
    newInv.setResourceTableKey(null);
    newInv.instance = currInv.getInstance();
    if (!naming) {
        newInv.setJNDIEnvironment(null);
    }
    return newInv;
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation)

Example 47 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class ContextSetupProviderImpl method saveContext.

@Override
public ContextHandle saveContext(ContextService contextService, Map<String, String> contextObjectProperties) {
    // Capture the current thread context
    ClassLoader contextClassloader = null;
    SecurityContext currentSecurityContext = null;
    ComponentInvocation savedInvocation = null;
    if (classloading) {
        contextClassloader = Utility.getClassLoader();
    }
    if (security) {
        currentSecurityContext = SecurityContext.getCurrent();
    }
    ComponentInvocation currentInvocation = invocationManager.getCurrentInvocation();
    if (currentInvocation != null) {
        savedInvocation = createComponentInvocation(currentInvocation);
    }
    boolean useTransactionOfExecutionThread = transactionManager == null && useTransactionOfExecutionThread(contextObjectProperties);
    // TODO - support workarea propagation
    return new InvocationContext(savedInvocation, contextClassloader, currentSecurityContext, useTransactionOfExecutionThread);
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) SecurityContext(com.sun.enterprise.security.SecurityContext)

Example 48 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class EjbNamingReferenceManagerImpl method getEJBContextObject.

public Object getEJBContextObject(String contextType) {
    ComponentInvocation currentInv = invMgr.getCurrentInvocation();
    if (currentInv == null) {
        throw new IllegalStateException("no current invocation");
    } else if (currentInv.getInvocationType() != ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) {
        throw new IllegalStateException("Illegal invocation type for EJB Context : " + currentInv.getInvocationType());
    }
    EjbInvocation ejbInv = (EjbInvocation) currentInv;
    Object returnObject = ejbInv.context;
    if (contextType.equals("javax.ejb.TimerService")) {
        if (EJBTimerService.getEJBTimerService() == null) {
            throw new IllegalStateException("EJB Timer Service not " + "available");
        }
        returnObject = new EJBTimerServiceWrapper(EJBTimerService.getEJBTimerService(), (EJBContextImpl) ejbInv.context);
    }
    return returnObject;
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) EJBContextImpl(com.sun.ejb.containers.EJBContextImpl) EJBTimerServiceWrapper(com.sun.ejb.containers.EJBTimerServiceWrapper)

Example 49 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class SecurityMechanismSelector method selectSecurityContext.

/**
 * Select the security context to be used by the CSIV2 layer based on whether the current component
 * is an application client or a web/EJB component.
 */
public SecurityContext selectSecurityContext(IOR ior) throws InvalidIdentityTokenException, InvalidMechanismException, SecurityMechanismException {
    SecurityContext context = null;
    ConnectionContext cc = new ConnectionContext();
    // print CSIv2 mechanism definition in IOR
    if (traceIORs()) {
        _logger.info("\nCSIv2 Mechanism List:" + getSecurityMechanismString(ctc, ior));
    }
    getSSLPort(ior, cc);
    setClientConnectionContext(cc);
    CompoundSecMech mechanism = cc.getMechanism();
    if (mechanism == null) {
        return null;
    }
    boolean sslUsed = cc.getSSLUsed();
    boolean clientAuthOccurred = cc.getSSLClientAuthenticationOccurred();
    // Standalone client
    if (isNotServerOrACC()) {
        context = getSecurityContextForAppClient(null, sslUsed, clientAuthOccurred, mechanism);
        return context;
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "SSL used:" + sslUsed + " SSL Mutual auth:" + clientAuthOccurred);
    }
    ComponentInvocation ci = null;
    /*
         * // BEGIN IASRI# 4646060 ci = invMgr.getCurrentInvocation(); if (ci == null) { // END IASRI#
         * 4646060 return null; } Object obj = ci.getContainerContext();
         */
    if (isACC()) {
        context = getSecurityContextForAppClient(ci, sslUsed, clientAuthOccurred, mechanism);
    } else {
        context = getSecurityContextForWebOrEJB(ci, sslUsed, clientAuthOccurred, mechanism);
    }
    return context;
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) ClientSecurityContext(com.sun.enterprise.security.common.ClientSecurityContext) SecurityContext(com.sun.enterprise.common.iiop.security.SecurityContext)

Example 50 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class EJBSecurityManager method isCallerInRole.

/**
 * This method returns a boolean value indicating whether or not the
 * caller is in the specified role.
 *
 * @param role role name in the form of java.lang.String
 * @return A boolean true/false depending on whether or not the caller
 *         has the specified role.
 */
public boolean isCallerInRole(String role) {
    /* In case of Run As - Should check isCallerInRole with
       * respect to the old security context.
       */
    boolean ret = false;
    if (_logger.isLoggable(Level.FINE)) {
        _logger.entering("EJBSecurityManager", "isCallerInRole", role);
    }
    EJBRoleRefPermission ejbrr = new EJBRoleRefPermission(ejbName, role);
    SecurityContext sc;
    if (runAs != null) {
        ComponentInvocation ci = invMgr.getCurrentInvocation();
        sc = (SecurityContext) ci.getOldSecurityContext();
    } else {
        sc = SecurityContext.getCurrent();
    }
    Set principalSet = (sc != null) ? sc.getPrincipalSet() : null;
    ProtectionDomain prdm = getCachedProtectionDomain(principalSet, true);
    String oldContextId = null;
    try {
        // set the policy context in the TLS.
        oldContextId = setPolicyContext(this.contextId);
        ret = policy.implies(prdm, ejbrr);
    } catch (SecurityException se) {
        _logger.log(Level.SEVERE, "jacc_is_caller_in_role_exception", se);
        ret = false;
    } catch (Throwable t) {
        _logger.log(Level.SEVERE, "jacc_is_caller_in_role_exception", t);
        ret = false;
    } finally {
        try {
            resetPolicyContext(oldContextId, this.contextId);
        } catch (Throwable ex) {
            _logger.log(Level.SEVERE, "jacc_policy_context_exception", ex);
            ret = false;
        }
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("JACC: isCallerInRole Result: " + ret + " EJBRoleRefPermission (Name) = " + ejbrr.getName() + " (Action) = " + ejbrr.getActions() + " (Codesource) = " + prdm.getCodeSource());
    }
    return ret;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Set(java.util.Set) HashSet(java.util.HashSet) EJBRoleRefPermission(javax.security.jacc.EJBRoleRefPermission) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) SecurityContext(com.sun.enterprise.security.SecurityContext)

Aggregations

ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)67 InvocationManager (org.glassfish.api.invocation.InvocationManager)13 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)8 EjbInvocation (com.sun.ejb.EjbInvocation)7 InvocationException (org.glassfish.api.invocation.InvocationException)7 SecurityContext (com.sun.enterprise.security.SecurityContext)6 WebModule (com.sun.enterprise.web.WebModule)6 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)5 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)5 WebComponentInvocation (com.sun.enterprise.web.WebComponentInvocation)5 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)4 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)4 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)4 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)4 RemoteException (java.rmi.RemoteException)4 EJBInvocation (org.glassfish.ejb.api.EJBInvocation)4 ArrayList (java.util.ArrayList)3 NamingException (javax.naming.NamingException)3 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)3 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)3