Search in sources :

Example 36 with ComponentInvocation

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

the class EntityManagerWrapper method getNonTxEMFromCurrentInvocation.

private EntityManager getNonTxEMFromCurrentInvocation() {
    // We store nonTxEM as a payload in a map from EMF to EM inside current invocation.
    // It will be closed during  NonTxEntityManagerCleaner.beforePostInvoke() below
    ComponentInvocation currentInvocation = invMgr.getCurrentInvocation();
    Map<EntityManagerFactory, EntityManager> nonTxEMs = getNonTxEMsFromCurrentInvocation(currentInvocation);
    if (nonTxEMs == null) {
        nonTxEMs = new HashMap<>();
        currentInvocation.setRegistryFor(INVOCATION_PAYLOAD_KEY, nonTxEMs);
    }
    EntityManager nonTxEM = nonTxEMs.get(entityManagerFactory);
    if (nonTxEM == null) {
        // Could not find one, create new one and store it within current invocation for cleanup
        nonTxEM = entityManagerFactory.createEntityManager(synchronizationType, emProperties);
        nonTxEMs.put(entityManagerFactory, nonTxEM);
    }
    return nonTxEM;
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation)

Example 37 with ComponentInvocation

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

the class BasicPasswordAuthenticationService method doMap.

/**
 * Performs the actual mapping of the principal/userGroup to the
 * backendPrincipal by checking at the connector registry for all the
 * existing mapping. If a map is found the backendPrincipal is
 * returned else null is returned .
 */
private Principal doMap(String principalName, List groupNames, String roleName, RuntimeSecurityMap runtimeSecurityMap) {
    // Policy:
    // user_1, user_2, ... user_n
    // group_1/role_1, group_2/role_2, ... group_n/role_n
    // user contains *
    // role/group contains *
    HashMap userNameSecurityMap = (HashMap) runtimeSecurityMap.getUserMap();
    HashMap groupNameSecurityMap = (HashMap) runtimeSecurityMap.getGroupMap();
    // Check if caller's user-name is preset in the User Map
    if (userNameSecurityMap.containsKey(principalName)) {
        return (Principal) userNameSecurityMap.get(principalName);
    }
    // Check if caller's role is present in the Group Map
    if (isContainerContextAWebModuleObject() && roleName != null) {
        if (groupNameSecurityMap.containsKey(roleName)) {
            return (Principal) groupNameSecurityMap.get(roleName);
        }
    }
    // If ejb, use isCallerInRole
    if (isContainerContextAEJBContainerObject() && roleName == null) {
        ComponentInvocation componentInvocation = ConnectorRuntime.getRuntime().getInvocationManager().getCurrentInvocation();
        EJBInvocation ejbInvocation = (EJBInvocation) componentInvocation;
        EJBContext ejbcontext = ejbInvocation.getEJBContext();
        Set<Map.Entry> s = (Set<Map.Entry>) groupNameSecurityMap.entrySet();
        Iterator i = s.iterator();
        while (i.hasNext()) {
            Map.Entry mapEntry = (Map.Entry) i.next();
            String key = (String) mapEntry.getKey();
            Principal entry = (Principal) mapEntry.getValue();
            boolean isInRole = false;
            try {
                isInRole = ejbcontext.isCallerInRole(key);
            } catch (Exception ex) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "BasicPasswordAuthentication::caller not in role " + key);
                }
            }
            if (isInRole) {
                return entry;
            }
        }
    }
    // Check if caller's group(s) is/are present in the Group Map
    for (int j = 0; j < groupNames.size(); j++) {
        String groupName = (String) groupNames.get(j);
        if (groupNameSecurityMap.containsKey(groupName)) {
            return (Principal) groupNameSecurityMap.get(groupName);
        }
    }
    // Check if user name is * in Security Map
    if (userNameSecurityMap.containsKey(ConnectorConstants.SECURITYMAPMETACHAR)) {
        return (Principal) userNameSecurityMap.get(ConnectorConstants.SECURITYMAPMETACHAR);
    }
    // Check if role/group name is * in Security Map
    if (groupNameSecurityMap.containsKey(ConnectorConstants.SECURITYMAPMETACHAR)) {
        return (Principal) groupNameSecurityMap.get(ConnectorConstants.SECURITYMAPMETACHAR);
    }
    return null;
}
Also used : EJBContext(javax.ejb.EJBContext) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) EJBInvocation(org.glassfish.ejb.api.EJBInvocation) Principal(java.security.Principal)

Example 38 with ComponentInvocation

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

the class ResourceManagerImpl method rollBackTransaction.

/**
 * Get's the component's transaction and marks it for rolling back.
 */
public void rollBackTransaction() {
    InvocationManager invmgr = ConnectorRuntime.getRuntime().getInvocationManager();
    JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
    Transaction tran = null;
    try {
        ComponentInvocation inv = invmgr.getCurrentInvocation();
        if (inv == null) {
            // in that, you return the transaction from the TxManager
            try {
                tran = tm.getTransaction();
            } catch (Exception e) {
                tran = null;
                _logger.log(Level.INFO, e.getMessage());
            }
        } else {
            tran = (Transaction) inv.getTransaction();
        }
        if (tran != null) {
            tran.setRollbackOnly();
        }
    } catch (SystemException ex) {
        _logger.log(Level.WARNING, "poolmgr.system_exception", ex);
    } catch (IllegalStateException ex) {
    // ignore
    }
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) InvocationException(org.glassfish.api.invocation.InvocationException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException)

Example 39 with ComponentInvocation

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

the class ResourceManagerImpl method registerResource.

/**
 * Register the <code>ResourceHandle</code> in the transaction
 *
 * @param handle	<code>ResourceHandle</code> object
 * @exception <code>PoolingException</code>
 */
public void registerResource(ResourceHandle handle) throws PoolingException {
    try {
        Transaction tran = null;
        JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
        // enlist if necessary
        if (handle.isTransactional()) {
            InvocationManager invmgr = ConnectorRuntime.getRuntime().getInvocationManager();
            ComponentInvocation inv = invmgr.getCurrentInvocation();
            if (inv == null) {
                // in that, you return the transaction from the TxManager
                try {
                    tran = tm.getTransaction();
                } catch (Exception e) {
                    tran = null;
                    _logger.log(Level.INFO, e.getMessage());
                }
            } else {
                tran = (Transaction) inv.getTransaction();
                tm.registerComponentResource(handle);
            }
            if (tran != null) {
                try {
                    tm.enlistResource(tran, handle);
                } catch (Exception ex) {
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.fine("Exception whle trying to enlist resource " + ex.getMessage());
                    }
                    // to enlist the resource
                    if (inv != null) {
                        if (_logger.isLoggable(Level.FINE)) {
                            _logger.fine("Attempting to unregister component resource");
                        }
                        tm.unregisterComponentResource(handle);
                    }
                    throw ex;
                }
            }
        }
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "poolmgr.component_register_exception", ex);
        throw new PoolingException(ex.toString(), ex);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) InvocationException(org.glassfish.api.invocation.InvocationException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException)

Example 40 with ComponentInvocation

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

the class ResourceManagerImpl method getComponent.

/**
 * Returns the component invoking resource request.
 *
 * @return Handle to the component.
 */
public Object getComponent() {
    InvocationManager invmgr = ConnectorRuntime.getRuntime().getInvocationManager();
    ComponentInvocation inv = invmgr.getCurrentInvocation();
    if (inv == null) {
        return null;
    }
    return inv.getInstance();
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager)

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