Search in sources :

Example 1 with PoolManager

use of com.sun.enterprise.resource.pool.PoolManager in project Payara by payara.

the class ConnectionManagerImpl method allocateConnection.

public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo cxRequestInfo, String jndiNameToUse, Object conn) throws ResourceException {
    validateResourceAndPool();
    PoolManager poolmgr = ConnectorRuntime.getRuntime().getPoolManager();
    boolean resourceShareable = true;
    ResourceReferenceDescriptor ref = poolmgr.getResourceReference(jndiNameToUse, logicalName);
    if (ref != null) {
        String shareableStr = ref.getSharingScope();
        if (shareableStr.equals(ref.RESOURCE_UNSHAREABLE)) {
            resourceShareable = false;
        }
    }
    // TODO V3 refactor all the 3 cases viz, no res-ref, app-auth, cont-auth.
    if (ref == null) {
        if (getLogger().isLoggable(Level.FINE)) {
            getLogger().log(Level.FINE, "poolmgr.no_resource_reference", jndiNameToUse);
        }
        return internalGetConnection(mcf, defaultPrin, cxRequestInfo, resourceShareable, jndiNameToUse, conn, true);
    }
    String auth = ref.getAuthorization();
    if (auth.equals(ResourceReferenceDescriptor.APPLICATION_AUTHORIZATION)) {
        if (cxRequestInfo == null) {
            String msg = getLocalStrings().getString("con_mgr.null_userpass");
            throw new ResourceException(msg);
        }
        ConnectorRuntime.getRuntime().switchOnMatching(rarName, poolInfo);
        return internalGetConnection(mcf, null, cxRequestInfo, resourceShareable, jndiNameToUse, conn, false);
    } else {
        ResourcePrincipal prin = null;
        Set principalSet = null;
        Principal callerPrincipal = null;
        SecurityContext securityContext = null;
        ConnectorRuntime connectorRuntime = ConnectorRuntime.getRuntime();
        // TODO V3 is SecurityContext.getCurrent() the right way ? Does it need to be injected ?
        if (connectorRuntime.isServer() && (securityContext = SecurityContext.getCurrent()) != null && (callerPrincipal = securityContext.getCallerPrincipal()) != null && (principalSet = securityContext.getPrincipalSet()) != null) {
            AuthenticationService authService = connectorRuntime.getAuthenticationService(rarName, poolInfo);
            if (authService != null) {
                prin = (ResourcePrincipal) authService.mapPrincipal(callerPrincipal, principalSet);
            }
        }
        if (prin == null) {
            prin = ref.getResourcePrincipal();
            if (prin == null) {
                if (getLogger().isLoggable(Level.FINE)) {
                    getLogger().log(Level.FINE, "default-resource-principal not" + "specified for " + jndiNameToUse + ". Defaulting to" + " user/password specified in the pool");
                }
                prin = defaultPrin;
            } else if (!prin.equals(defaultPrin)) {
                ConnectorRuntime.getRuntime().switchOnMatching(rarName, poolInfo);
            }
        }
        return internalGetConnection(mcf, prin, cxRequestInfo, resourceShareable, jndiNameToUse, conn, false);
    }
}
Also used : Set(java.util.Set) SecurityContext(com.sun.enterprise.security.SecurityContext) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) ResourceException(javax.resource.ResourceException) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) PoolManager(com.sun.enterprise.resource.pool.PoolManager) AuthenticationService(com.sun.enterprise.connectors.authentication.AuthenticationService) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) Principal(java.security.Principal)

Example 2 with PoolManager

use of com.sun.enterprise.resource.pool.PoolManager in project Payara by payara.

the class ConnectorConnectionPoolAdminServiceImpl method updateMCFAndPoolAttributes.

private void updateMCFAndPoolAttributes(ConnectorConnectionPool ccp) throws ConnectorRuntimeException {
    PoolInfo poolInfo = ccp.getPoolInfo();
    try {
        ConnectorConnectionPool origCcp = getOriginalConnectorConnectionPool(poolInfo);
        // update properties
        origCcp.setSteadyPoolSize(ccp.getSteadyPoolSize());
        origCcp.setMaxPoolSize(ccp.getMaxPoolSize());
        origCcp.setMaxWaitTimeInMillis(ccp.getMaxWaitTimeInMillis());
        origCcp.setPoolResizeQuantity(ccp.getPoolResizeQuantity());
        origCcp.setIdleTimeoutInSeconds(ccp.getIdleTimeoutInSeconds());
        origCcp.setFailAllConnections(ccp.isFailAllConnections());
        // lazyEnlist, lazyAssoc and assocWithThread not required since they result
        // in a pool restart anyways, so they wouldn't have changed if we
        // came here
        origCcp.setMatchConnections(ccp.matchConnections());
        origCcp.setMaxConnectionUsage(ccp.getMaxConnectionUsage());
        origCcp.setNonComponent(ccp.isNonComponent());
        origCcp.setNonTransactional(ccp.isNonTransactional());
        origCcp.setConCreationRetryAttempts(ccp.getConCreationRetryAttempts());
        origCcp.setConCreationRetryInterval(ccp.getConCreationRetryInterval());
        origCcp.setValidateAtmostOncePeriod(ccp.getValidateAtmostOncePeriod());
        origCcp.setConnectionLeakTracingTimeout(ccp.getConnectionLeakTracingTimeout());
        origCcp.setConnectionReclaim(ccp.isConnectionReclaim());
        // now rebind the object in jndi
        String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
        _runtime.getResourceNamingService().unpublishObject(poolInfo, jndiNameForPool);
        _runtime.getResourceNamingService().publishObject(poolInfo, jndiNameForPool, origCcp, true);
    } catch (NamingException ne) {
        throw new ConnectorRuntimeException(ne.getMessage());
    }
    // Check if this pool has been brought into memory
    // If its already in memory, just call reconfig on it
    PoolManager poolMgr = _runtime.getPoolManager();
    try {
        poolMgr.reconfigPoolProperties(ccp);
    } catch (PoolingException pe) {
        throw new ConnectorRuntimeException(pe.getMessage());
    }
    // Run setXXX methods on the copy of the MCF that we have
    // this is done to update the MCF to reflect changes in the
    // MCF properties for which we don't really need to recreate
    // the pool
    ConnectorRegistry registry = ConnectorRegistry.getInstance();
    ManagedConnectionFactory mcf = registry.getManagedConnectionFactory(poolInfo);
    SetMethodAction sma = new SetMethodAction(mcf, ccp.getConnectorDescriptorInfo().getMCFConfigProperties());
    try {
        sma.run();
    } catch (Exception e) {
        _logger.log(Level.WARNING, e.getMessage());
        ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
        cre.initCause(e);
        throw cre;
    }
    // update the properties "allow-non-component-callers" and
    // "non-transactional-connections" in the PoolMetaData
    PoolMetaData pmd = registry.getPoolMetaData(poolInfo);
    pmd.setIsPM(ccp.isNonComponent());
    pmd.setIsNonTx(ccp.isNonTransactional());
    pmd.setAuthCredentialsDefinedInPool(ccp.getAuthCredentialsDefinedInPool());
    logFine("Pool properties reconfiguration done");
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) NamingException(javax.naming.NamingException) PoolManager(com.sun.enterprise.resource.pool.PoolManager) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) SQLException(java.sql.SQLException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Example 3 with PoolManager

use of com.sun.enterprise.resource.pool.PoolManager in project Payara by payara.

the class ConnectionManagerImpl method internalGetConnection.

protected Object internalGetConnection(ManagedConnectionFactory mcf, final ResourcePrincipal prin, ConnectionRequestInfo cxRequestInfo, boolean shareable, String jndiNameToUse, Object conn, boolean isUnknownAuth) throws ResourceException {
    try {
        PoolManager poolmgr = ConnectorRuntime.getRuntime().getPoolManager();
        ConnectorRegistry registry = ConnectorRegistry.getInstance();
        PoolMetaData pmd = registry.getPoolMetaData(poolInfo);
        ResourceSpec spec = new ResourceSpec(jndiNameToUse, ResourceSpec.JNDI_NAME, pmd);
        spec.setPoolInfo(this.poolInfo);
        ManagedConnectionFactory freshMCF = pmd.getMCF();
        if (getLogger().isLoggable(Level.INFO)) {
            if (!freshMCF.equals(mcf)) {
                getLogger().info("conmgr.mcf_not_equal");
            }
        }
        ConnectorDescriptor desc = registry.getDescriptor(rarName);
        Subject subject = null;
        ClientSecurityInfo info = null;
        boolean subjectDefined = false;
        if (isUnknownAuth && rarName.equals(ConnectorConstants.DEFAULT_JMS_ADAPTER) && !(pmd.isAuthCredentialsDefinedInPool())) {
            // System.out.println("Unkown Auth - pobably nonACC client");
            // Unknown authorization. This is the case for standalone java clients,
            // where the authorization is neither container nor component
            // managed. In this case we associate an non-null Subject with no
            // credentials, so that the RA can either use its own custom logic
            // for figuring out the credentials. Relevant connector spec section
            // is 9.1.8.2.
            // create non-null Subject associated with no credentials
            // System.out.println("RAR name "+ rarName);
            subject = ConnectionPoolObjectsUtils.createSubject(mcf, null);
        } else {
            if (prin == null) {
                info = new ClientSecurityInfo(cxRequestInfo);
            } else {
                info = new ClientSecurityInfo(prin);
                if (prin.equals(defaultPrin)) {
                    subject = pmd.getSubject();
                } else {
                    subject = ConnectionPoolObjectsUtils.createSubject(mcf, prin);
                }
            }
        }
        int txLevel = pmd.getTransactionSupport();
        if (getLogger().isLoggable(Level.FINE)) {
            logFine("ConnectionMgr: poolName " + poolInfo + "  txLevel : " + txLevel);
        }
        if (conn != null) {
            spec.setConnectionToAssociate(conn);
        }
        return getResource(txLevel, poolmgr, mcf, spec, subject, cxRequestInfo, info, desc, shareable);
    } catch (PoolingException ex) {
        Object[] params = new Object[] { poolInfo, ex };
        getLogger().log(Level.WARNING, "poolmgr.get_connection_failure", params);
        // GLASSFISH-19609
        // we can't simply look for ResourceException and throw back since
        // Connector Container also throws ResourceException which might
        // hide the SecurityException thrown by RA.
        // So, we try to track SecurityException
        unwrapSecurityException(ex);
        String i18nMsg = getLocalStrings().getString("con_mgr.error_creating_connection", ex.getMessage());
        ResourceAllocationException rae = new ResourceAllocationException(i18nMsg);
        rae.initCause(ex);
        throw rae;
    }
}
Also used : ClientSecurityInfo(com.sun.enterprise.resource.ClientSecurityInfo) ResourceSpec(com.sun.enterprise.resource.ResourceSpec) PoolManager(com.sun.enterprise.resource.pool.PoolManager) Subject(javax.security.auth.Subject) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor)

Example 4 with PoolManager

use of com.sun.enterprise.resource.pool.PoolManager in project Payara by payara.

the class ConnectorService method switchOnMatching.

/**
 * Matching will be switched off in the pool, by default. This will be
 * switched on if the connections with different resource principals reach the pool.
 *
 * @param poolInfo Name of the pool to switchOn matching.
 * @param rarName  Name of the resource adater.
 */
public void switchOnMatching(String rarName, PoolInfo poolInfo) {
    // Later other resource adapters also become applicable.
    if (rarName.equals(ConnectorConstants.JDBCDATASOURCE_RA_NAME) || rarName.equals(ConnectorConstants.JDBCCONNECTIONPOOLDATASOURCE_RA_NAME) || rarName.equals(ConnectorConstants.JDBCXA_RA_NAME)) {
        PoolManager poolMgr = _runtime.getPoolManager();
        boolean result = poolMgr.switchOnMatching(poolInfo);
        if (!result) {
            try {
                _runtime.switchOnMatchingInJndi(poolInfo);
            } catch (ConnectorRuntimeException cre) {
            // This will never happen.
            }
        }
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) PoolManager(com.sun.enterprise.resource.pool.PoolManager)

Example 5 with PoolManager

use of com.sun.enterprise.resource.pool.PoolManager in project Payara by payara.

the class LazyEnlistableResourceManagerImpl method lazyEnlist.

/**
 * This is called by the PoolManager (in turn by the LazyEnlistableConnectionManager)
 * when a lazy enlistment is sought.
 * @param mc ManagedConnection
 * @throws ResourceException
 */
public void lazyEnlist(ManagedConnection mc) throws ResourceException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("Entering lazyEnlist");
    }
    // J2EETransactionManager tm = Switch.getSwitch().getTransactionManager();
    JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
    Transaction tran = null;
    try {
        tran = tm.getTransaction();
        if (tran == null) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine(" Transaction null - not enlisting ");
            }
            return;
        }
    } catch (SystemException se) {
        ResourceException re = new ResourceException(se.getMessage());
        re.initCause(se);
        throw re;
    }
    // List invList = Switch.getSwitch().getInvocationManager().getAllInvocations();
    List invList = ConnectorRuntime.getRuntime().getInvocationManager().getAllInvocations();
    ResourceHandle h = null;
    for (int j = invList.size(); j > 0; j--) {
        ComponentInvocation inv = (ComponentInvocation) invList.get(j - 1);
        Object comp = inv.getInstance();
        List l = tm.getResourceList(comp, inv);
        ListIterator it = l.listIterator();
        while (it.hasNext()) {
            ResourceHandle hand = (ResourceHandle) it.next();
            ManagedConnection toEnlist = (ManagedConnection) hand.getResource();
            if (mc.equals(toEnlist)) {
                h = hand;
                break;
            }
        }
    }
    // The other case might or might not work
    if (h != null && h.getResourceState().isUnenlisted()) {
        try {
            // Enable the suspended lazyenlistment so as to enlist the resource.
            h.setEnlistmentSuspended(false);
            tm.enlistResource(tran, h);
            // Suspend it back
            h.setEnlistmentSuspended(true);
        } catch (Exception e) {
            // In the rare cases where enlistResource throws exception, we
            // should report the resource to the pool as bad
            PoolManager mgr = ConnectorRuntime.getRuntime().getPoolManager();
            mgr.putbackBadResourceToPool(h);
            _logger.log(Level.WARNING, "poolmgr.err_enlisting_res_in_getconn", h.getResourceSpec().getPoolInfo());
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("rm.enlistResource threw Exception. Evicting resource from pool");
            }
            // and rethrow the exception
            throw new ResourceException(e);
        }
    }
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) ListIterator(java.util.ListIterator) PoolManager(com.sun.enterprise.resource.pool.PoolManager) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ResourceException(javax.resource.ResourceException) List(java.util.List) ManagedConnection(javax.resource.spi.ManagedConnection)

Aggregations

PoolManager (com.sun.enterprise.resource.pool.PoolManager)5 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)3 ResourceException (javax.resource.ResourceException)3 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)2 AuthenticationService (com.sun.enterprise.connectors.authentication.AuthenticationService)1 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)1 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)1 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)1 ClientSecurityInfo (com.sun.enterprise.resource.ClientSecurityInfo)1 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)1 ResourceSpec (com.sun.enterprise.resource.ResourceSpec)1 SecurityContext (com.sun.enterprise.security.SecurityContext)1 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)1 Principal (java.security.Principal)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Set (java.util.Set)1 NamingException (javax.naming.NamingException)1 ManagedConnection (javax.resource.spi.ManagedConnection)1