Search in sources :

Example 26 with ConnectorDescriptor

use of com.sun.enterprise.deployment.ConnectorDescriptor 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 27 with ConnectorDescriptor

use of com.sun.enterprise.deployment.ConnectorDescriptor in project Payara by payara.

the class ConnectionManagerImpl method validateResourceAndPool.

private void validateResourceAndPool() throws ResourceException {
    ResourceInfo resourceInfo = this.resourceInfo;
    ResourcesUtil resourcesUtil = ResourcesUtil.createInstance();
    ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
    ConnectorRegistry registry = ConnectorRegistry.getInstance();
    // are disabled.
    if (!registry.isResourceDeployed(resourceInfo)) {
        if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST, "resourceInfo not found in connector-registry : " + resourceInfo);
        }
        boolean isDefaultResource = false;
        boolean isSunRAResource = false;
        ConnectorDescriptor descriptor = registry.getDescriptor(rarName);
        if (descriptor != null) {
            isDefaultResource = descriptor.getDefaultResourcesNames().contains(resourceInfo.getName());
            if (descriptor.getSunDescriptor() != null) {
                com.sun.enterprise.deployment.runtime.connector.ResourceAdapter rar = descriptor.getSunDescriptor().getResourceAdapter();
                if (rar != null) {
                    String sunRAJndiName = (String) rar.getValue(com.sun.enterprise.deployment.runtime.connector.ResourceAdapter.JNDI_NAME);
                    isSunRAResource = resourceInfo.getName().equals(sunRAJndiName);
                }
            }
        }
        if ((runtime.isServer() || runtime.isEmbedded()) && (!resourceInfo.getName().contains(ConnectorConstants.DATASOURCE_DEFINITION_JNDINAME_PREFIX) && (!isDefaultResource) && (!isSunRAResource))) {
            // resources config bean each time.
            if (resourceConfiguration == null) {
                resourceConfiguration = (BindableResource) resourcesUtil.getResource(resourceInfo, BindableResource.class);
                if (resourceConfiguration == null) {
                    String suffix = ConnectorsUtil.getValidSuffix(resourceInfo.getName());
                    // check for the enabled status and existence using non-prefixed resource-name
                    if (suffix != null) {
                        String nonPrefixedName = resourceInfo.getName().substring(0, resourceInfo.getName().lastIndexOf(suffix));
                        resourceInfo = new ResourceInfo(nonPrefixedName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
                        resourceConfiguration = (BindableResource) resourcesUtil.getResource(resourceInfo, BindableResource.class);
                    }
                }
            } else {
                // we cache the resourceConfiguration for performance optimization.
                // make sure that appropriate (actual) resourceInfo is used for validation.
                String suffix = ConnectorsUtil.getValidSuffix(resourceInfo.getName());
                // check for the enabled status and existence using non-prefixed resource-name
                if (suffix != null) {
                    String nonPrefixedName = resourceInfo.getName().substring(0, resourceInfo.getName().lastIndexOf(suffix));
                    resourceInfo = new ResourceInfo(nonPrefixedName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
                }
            }
            if (resourceConfiguration == null) {
                throw new ResourceException("No such resource : " + resourceInfo);
            }
            if (!resourcesUtil.isEnabled(resourceConfiguration, resourceInfo)) {
                throw new ResourceException(resourceInfo + " is not enabled");
            }
        }
    }
    if (registry.getPoolMetaData(poolInfo) == null) {
        String msg = getLocalStrings().getString("con_mgr.no_pool_meta_data", poolInfo);
        throw new ResourceException(poolInfo + ": " + msg);
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) ResourcesUtil(com.sun.enterprise.connectors.util.ResourcesUtil) ResourceException(javax.resource.ResourceException)

Example 28 with ConnectorDescriptor

use of com.sun.enterprise.deployment.ConnectorDescriptor in project Payara by payara.

the class ConnectorConfigurationParserServiceImpl method getSecurityPermissionSpec.

/**
 * Obtains the Permission string that needs to be added to the
 * to the security policy files. These are the security permissions needed
 * by the resource adapter implementation classes.
 * These strings are obtained by parsing the ra.xml
 *
 * @param moduleName rar module Name
 * @return Required policy permissions in server.policy file
 * @throws ConnectorRuntimeException If rar.xml parsing fails.
 */
public String getSecurityPermissionSpec(String moduleName) throws ConnectorRuntimeException {
    if (moduleName == null) {
        return null;
    }
    String policyString = null;
    // check whether the policy file already has required permissions.
    String fileName = System.getProperty("java.security.policy");
    if (fileName != null) {
        File policyFile = new File(fileName);
        String policyContent = getFileContent(policyFile);
        ConnectorDescriptor connectorDescriptor = getConnectorDescriptor(moduleName);
        Set securityPermissions = connectorDescriptor.getSecurityPermissions();
        Iterator it = securityPermissions.iterator();
        SecurityPermission secPerm = null;
        String permissionString = null;
        while (it.hasNext()) {
            secPerm = (SecurityPermission) it.next();
            permissionString = secPerm.getPermission();
            int intIndex = policyContent.indexOf(permissionString);
            if (intIndex == -1) {
                if (permissionString != null) {
                    if (policyString != null) {
                        policyString = policyString + "\n \n" + permissionString;
                    } else {
                        policyString = "\n\n" + permissionString;
                    }
                }
            }
        }
        // print the missing permissions
        if (policyString != null) {
            policyString = CAUTION_MESSAGE + policyString;
        }
    }
    return policyString;
}
Also used : ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) Set(java.util.Set) Iterator(java.util.Iterator) File(java.io.File) SecurityPermission(com.sun.enterprise.deployment.SecurityPermission)

Example 29 with ConnectorDescriptor

use of com.sun.enterprise.deployment.ConnectorDescriptor in project Payara by payara.

the class ConnectorService method getConnectorDescriptor.

/**
 * Obtains the connector Descriptor pertaining to rar.
 * If ConnectorDescriptor is present in registry, it is obtained from
 * registry and returned. Else it is explicitly read from directory
 * where rar is exploded.
 *
 * @param rarName Name of the rar
 * @return ConnectorDescriptor pertaining to rar.
 * @throws ConnectorRuntimeException when unable to get descriptor
 */
public ConnectorDescriptor getConnectorDescriptor(String rarName) throws ConnectorRuntimeException {
    if (rarName == null) {
        return null;
    }
    ConnectorDescriptor desc = null;
    desc = _registry.getDescriptor(rarName);
    if (desc != null) {
        return desc;
    }
    String moduleDir;
    // using the applicationarchivist
    if (rarName.indexOf(ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER) != -1) {
        try {
            desc = loadConnectorDescriptorForEmbeddedRAR(rarName);
            if (desc != null)
                return desc;
        } catch (ConnectorRuntimeException e) {
            throw e;
        }
    }
    if (ConnectorsUtil.belongsToSystemRA(rarName)) {
        moduleDir = ConnectorsUtil.getSystemModuleLocation(rarName);
    } else {
        moduleDir = ConnectorsUtil.getLocation(rarName);
    }
    if (moduleDir != null) {
        desc = ConnectorDDTransformUtils.getConnectorDescriptor(moduleDir, rarName);
    } else {
        _logger.log(Level.SEVERE, "rardeployment.no_module_deployed", rarName);
    }
    return desc;
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor)

Example 30 with ConnectorDescriptor

use of com.sun.enterprise.deployment.ConnectorDescriptor in project Payara by payara.

the class AdministeredObjectHandler method processAnnotation.

public HandlerProcessingResult processAnnotation(AnnotationInfo element) throws AnnotationProcessorException {
    AnnotatedElementHandler aeHandler = element.getProcessingContext().getHandler();
    AdministeredObject adminObject = (AdministeredObject) element.getAnnotation();
    if (aeHandler instanceof RarBundleContext) {
        RarBundleContext rarContext = (RarBundleContext) aeHandler;
        ConnectorDescriptor desc = rarContext.getDescriptor();
        Class c = (Class) element.getAnnotatedElement();
        String adminObjectClassName = c.getName();
        Class[] adminObjectInterfaceClasses = adminObject.adminObjectInterfaces();
        // When "adminObjectInterfaces()" is specified, add one admin-object entry per interface
        if (adminObjectInterfaceClasses != null && adminObjectInterfaceClasses.length > 0) {
            for (Class adminObjectInterface : adminObjectInterfaceClasses) {
                processAdminObjectInterface(adminObjectClassName, adminObjectInterface.getName(), desc);
            }
        } else {
            List<Class> interfacesList = deriveAdminObjectInterfacesFromHierarchy(c);
            if (interfacesList.size() == 1) {
                Class intf = interfacesList.get(0);
                String intfName = intf.getName();
                processAdminObjectInterface(adminObjectClassName, intfName, desc);
            } else {
            // TODO V3 this case is, multiple interfaces implemented, no "adminObjectInterfaces()" attribute defined,
            // should we check the DD whether this Impl class is already specified in any of "admin-object" elements ?
            // If present, return. If not present, throw exception ?
            }
        }
    } else {
        getFailureResult(element, "not a rar bundle context", true);
    }
    return getDefaultProcessedResult();
}
Also used : AdministeredObject(javax.resource.spi.AdministeredObject) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) RarBundleContext(com.sun.enterprise.deployment.annotation.context.RarBundleContext)

Aggregations

ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)40 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)11 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)9 RarBundleContext (com.sun.enterprise.deployment.annotation.context.RarBundleContext)8 OutboundResourceAdapter (com.sun.enterprise.deployment.OutboundResourceAdapter)5 Iterator (java.util.Iterator)5 AuthMechanism (com.sun.enterprise.deployment.AuthMechanism)4 URISyntaxException (java.net.URISyntaxException)4 ConnectionDefDescriptor (com.sun.enterprise.deployment.ConnectionDefDescriptor)3 DeploymentDescriptorNode (com.sun.enterprise.deployment.node.DeploymentDescriptorNode)3 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)2 ActiveResourceAdapter (com.sun.enterprise.connectors.ActiveResourceAdapter)2 ConnectorDescriptorInfo (com.sun.enterprise.connectors.ConnectorDescriptorInfo)2 ConnectorRegistry (com.sun.enterprise.connectors.ConnectorRegistry)2 ConnectorRuntime (com.sun.enterprise.connectors.ConnectorRuntime)2 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)2 JmsRaUtil (com.sun.enterprise.connectors.jms.util.JmsRaUtil)2 MessageListener (com.sun.enterprise.deployment.MessageListener)2 AdministeredObjectResource (com.sun.enterprise.resource.beans.AdministeredObjectResource)2 URI (java.net.URI)2