Search in sources :

Example 1 with SecurityPermission

use of javax.resource.spi.SecurityPermission in project Payara by payara.

the class SecurityPermissionHandler method processAnnotation.

public HandlerProcessingResult processAnnotation(AnnotationInfo element) throws AnnotationProcessorException {
    AnnotatedElementHandler aeHandler = element.getProcessingContext().getHandler();
    SecurityPermission securityPermission = (SecurityPermission) element.getAnnotation();
    if (aeHandler instanceof RarBundleContext) {
        boolean isConnectionDefinition = hasConnectorAnnotation(element);
        if (isConnectionDefinition) {
            RarBundleContext rarContext = (RarBundleContext) aeHandler;
            ConnectorDescriptor desc = rarContext.getDescriptor();
            // XXX: Siva : For now use the first provided description
            String firstDesc = "";
            if (securityPermission.description().length > 0) {
                firstDesc = securityPermission.description()[0];
            }
            com.sun.enterprise.deployment.SecurityPermission permission = new com.sun.enterprise.deployment.SecurityPermission(firstDesc, securityPermission.permissionSpec());
            desc.addSecurityPermission(permission);
        } else {
            getFailureResult(element, "Not a @Connector annotation : @SecurityPermission must " + "be specified along with @Connector annotation", true);
        }
    } else {
        getFailureResult(element, "Not a rar bundle context", true);
    }
    return getDefaultProcessedResult();
}
Also used : ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) RarBundleContext(com.sun.enterprise.deployment.annotation.context.RarBundleContext) SecurityPermission(javax.resource.spi.SecurityPermission)

Example 2 with SecurityPermission

use of javax.resource.spi.SecurityPermission in project Payara by payara.

the class SecurityPermissionHandler method processAnnotation.

public HandlerProcessingResult processAnnotation(AnnotationInfo element) throws AnnotationProcessorException {
    AnnotatedElementHandler aeHandler = element.getProcessingContext().getHandler();
    SecurityPermission securityPermission = (SecurityPermission) element.getAnnotation();
    if (aeHandler instanceof RarBundleContext) {
        boolean isConnectionDefinition = hasConnectorAnnotation(element);
        if (isConnectionDefinition) {
            RarBundleContext rarContext = (RarBundleContext) aeHandler;
            ConnectorDescriptor desc = rarContext.getDescriptor();
            // XXX: Siva : For now use the first provided description
            String firstDesc = "";
            if (securityPermission.description().length > 0) {
                firstDesc = securityPermission.description()[0];
            }
            com.sun.enterprise.deployment.SecurityPermission permission = new com.sun.enterprise.deployment.SecurityPermission(firstDesc, securityPermission.permissionSpec());
            desc.addSecurityPermission(permission);
        } else {
            getFailureResult(element, "Not a @Connector annotation : @SecurityPermission must " + "be specified along with @Connector annotation", true);
        }
    } else {
        getFailureResult(element, "Not a rar bundle context", true);
    }
    return getDefaultProcessedResult();
}
Also used : ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) RarBundleContext(com.sun.enterprise.deployment.annotation.context.RarBundleContext) SecurityPermission(javax.resource.spi.SecurityPermission)

Example 3 with SecurityPermission

use of javax.resource.spi.SecurityPermission in project Payara by payara.

the class ConnectorAnnotationHandler method processDescriptor.

public static void processDescriptor(Class annotatedClass, Connector connector, ConnectorDescriptor desc) {
    if (desc.getDescription().equals("") && connector.description().length > 0) {
        desc.setDescription(convertStringArrayToStringBuilder(connector.description()));
    }
    if (desc.getDisplayName().equals("") && connector.displayName().length > 0) {
        desc.setDisplayName(convertStringArrayToStringBuilder(connector.displayName()));
    }
    if ((desc.getSmallIconUri() == null || desc.getSmallIconUri().equals("")) && connector.smallIcon().length > 0) {
        desc.setSmallIconUri(convertStringArrayToStringBuilder(connector.smallIcon()));
    }
    if ((desc.getLargeIconUri() == null || desc.getLargeIconUri().equals("")) && connector.largeIcon().length > 0) {
        desc.setLargeIconUri(convertStringArrayToStringBuilder(connector.largeIcon()));
    }
    if (desc.getVendorName().equals("") && !connector.vendorName().equals("")) {
        desc.setVendorName(connector.vendorName());
    }
    if (desc.getEisType().equals("") && !connector.eisType().equals("")) {
        desc.setEisType(connector.eisType());
    }
    if (desc.getVersion().equals("") && !connector.version().equals("")) {
        desc.setVersion(connector.version());
    }
    if (desc.getLicenseDescriptor() == null) {
        // We will be able to detect whether license description is specified in annotation
        // or not, but "license required" can't be detected. Hence taking the annotated values *always*
        // if DD does not have an equivalent
        String[] licenseDescriptor = connector.licenseDescription();
        boolean licenseRequired = connector.licenseRequired();
        LicenseDescriptor ld = new LicenseDescriptor();
        ld.setDescription(convertStringArrayToStringBuilder(licenseDescriptor));
        ld.setLicenseRequired(licenseRequired);
        desc.setLicenseDescriptor(ld);
    }
    AuthenticationMechanism[] auths = connector.authMechanisms();
    if (auths != null && auths.length > 0) {
        for (AuthenticationMechanism auth : auths) {
            String authMechString = auth.authMechanism();
            int authMechInt = AuthMechanism.getAuthMechInt(authMechString);
            // check whether the same auth-mechanism is defined in DD also,
            // possible change could be with auth-mechanism's credential-interface for a particular
            // auth-mechanism-type
            boolean ignore = false;
            OutboundResourceAdapter ora = getOutbound(desc);
            Set ddAuthMechanisms = ora.getAuthMechanisms();
            for (Object o : ddAuthMechanisms) {
                AuthMechanism ddAuthMechanism = (AuthMechanism) o;
                if (ddAuthMechanism.getAuthMechType().equals(auth.authMechanism())) {
                    ignore = true;
                    break;
                }
            }
            // if it was not specified in DD, add it to connector-descriptor
            if (!ignore) {
                String credentialInterfaceName = ora.getCredentialInterfaceName(auth.credentialInterface());
                // XXX: Siva: For now use the first provided description
                String description = "";
                if (auth.description().length > 0) {
                    description = auth.description()[0];
                }
                AuthMechanism authM = new AuthMechanism(description, authMechInt, credentialInterfaceName);
                ora.addAuthMechanism(authM);
            }
        }
    }
    // merge DD and annotation entries of security-permission
    SecurityPermission[] perms = connector.securityPermissions();
    if (perms != null && perms.length > 0) {
        for (SecurityPermission perm : perms) {
            boolean ignore = false;
            // check whether the same permission is defined in DD also,
            // though it does not make any functionality difference except possible
            // "Description" change
            Set ddSecurityPermissions = desc.getSecurityPermissions();
            for (Object o : ddSecurityPermissions) {
                com.sun.enterprise.deployment.SecurityPermission ddSecurityPermission = (com.sun.enterprise.deployment.SecurityPermission) o;
                if (ddSecurityPermission.getPermission().equals(perm.permissionSpec())) {
                    ignore = true;
                    break;
                }
            }
            // if it was not specified in DD, add it to connector-descriptor
            if (!ignore) {
                com.sun.enterprise.deployment.SecurityPermission sp = new com.sun.enterprise.deployment.SecurityPermission();
                sp.setPermission(perm.permissionSpec());
                // XXX: Siva for now use the first provided Description
                String firstDesc = "";
                if (perm.description().length > 0)
                    firstDesc = perm.description()[0];
                sp.setDescription(firstDesc);
                desc.addSecurityPermission(sp);
            }
        }
    }
    // if reauth is false, we can ignore it as default value in dol is also false.
    if (connector.reauthenticationSupport()) {
        OutboundResourceAdapter ora = getOutbound(desc);
        if (!ora.isReauthenticationSupportSet()) {
            ora.setReauthenticationSupport(connector.reauthenticationSupport());
        }
    }
    // if transaction-support is no-transaction, we can ignore it as default value in dol is also no-transaction.
    if (!connector.transactionSupport().equals(TransactionSupport.TransactionSupportLevel.NoTransaction)) {
        OutboundResourceAdapter ora = getOutbound(desc);
        if (!ora.isTransactionSupportSet()) {
            ora.setTransactionSupport(connector.transactionSupport().toString());
        }
    }
    // merge the DD & annotation specified values of required-inflow-contexts
    // merge involves simple union of class-names of inflow-contexts of DD and annotation
    // due to the above approach, its not possible to switch off one of the required-inflow-contexts ?
    // TODO need to check support and throw exception ?
    Class<? extends WorkContext>[] requiredInflowContexts = connector.requiredWorkContexts();
    if (requiredInflowContexts != null) {
        for (Class<? extends WorkContext> ic : requiredInflowContexts) {
            desc.addRequiredWorkContext(ic.getName());
        }
    }
    if (desc.getResourceAdapterClass().equals("")) {
        if (isResourceAdapterClass(annotatedClass)) {
            desc.setResourceAdapterClass(annotatedClass.getName());
        }
    }
}
Also used : Set(java.util.Set) AuthenticationMechanism(javax.resource.spi.AuthenticationMechanism) WorkContext(javax.resource.spi.work.WorkContext) AuthMechanism(com.sun.enterprise.deployment.AuthMechanism) LicenseDescriptor(com.sun.enterprise.deployment.LicenseDescriptor) OutboundResourceAdapter(com.sun.enterprise.deployment.OutboundResourceAdapter) SecurityPermission(javax.resource.spi.SecurityPermission)

Example 4 with SecurityPermission

use of javax.resource.spi.SecurityPermission in project tomee by apache.

the class AnnotationDeployerTest method testResourceAdapter.

@Test
public void testResourceAdapter() throws Exception {
    final ConnectorModule connectorModule = testConnectorModule();
    final AnnotationDeployer.DiscoverAnnotatedBeans discvrAnnBeans = new AnnotationDeployer.DiscoverAnnotatedBeans();
    discvrAnnBeans.deploy(connectorModule);
    final Connector connector = connectorModule.getConnector();
    Assert.assertEquals("displayName", connector.getDisplayName());
    Assert.assertEquals("description", connector.getDescription());
    Assert.assertEquals("eisType", connector.getEisType());
    Assert.assertEquals("vendorName", connector.getVendorName());
    Assert.assertEquals("version", connector.getResourceAdapterVersion());
    Assert.assertEquals("smallIcon", connector.getIcon().getSmallIcon());
    Assert.assertEquals("largeIcon", connector.getIcon().getLargeIcon());
    Assert.assertEquals("licenseDescription", connector.getLicense().getDescription());
    Assert.assertEquals(true, connector.getLicense().isLicenseRequired());
    final List<org.apache.openejb.jee.SecurityPermission> securityPermission = connector.getResourceAdapter().getSecurityPermission();
    Assert.assertEquals("description", securityPermission.get(0).getDescription());
    Assert.assertEquals("permissionSpec", securityPermission.get(0).getSecurityPermissionSpec());
    final List<String> requiredWorkContext = connector.getRequiredWorkContext();
    Assert.assertEquals(TestWorkContext.class.getName(), requiredWorkContext.get(0));
    final List<org.apache.openejb.jee.AuthenticationMechanism> authenticationMechanism = connector.getResourceAdapter().getOutboundResourceAdapter().getAuthenticationMechanism();
    Assert.assertEquals("authMechanism", authenticationMechanism.get(0).getAuthenticationMechanismType());
    Assert.assertEquals(CredentialInterface.GenericCredential.toString(), authenticationMechanism.get(0).getCredentialInterface());
    Assert.assertEquals("description", authenticationMechanism.get(0).getDescription());
    Assert.assertEquals(TransactionSupportType.NO_TRANSACTION, connector.getResourceAdapter().getOutboundResourceAdapter().getTransactionSupport());
    Assert.assertEquals(true, connector.getResourceAdapter().getOutboundResourceAdapter().isReauthenticationSupport());
    Assert.assertEquals(Connection.class.getName(), connector.getResourceAdapter().getOutboundResourceAdapter().getConnectionDefinition().get(0).getConnectionInterface());
    Assert.assertEquals(ConnectionImpl.class.getName(), connector.getResourceAdapter().getOutboundResourceAdapter().getConnectionDefinition().get(0).getConnectionImplClass());
    Assert.assertEquals(ConnectionFactory.class.getName(), connector.getResourceAdapter().getOutboundResourceAdapter().getConnectionDefinition().get(0).getConnectionFactoryInterface());
    Assert.assertEquals(ConnectionFactoryImpl.class.getName(), connector.getResourceAdapter().getOutboundResourceAdapter().getConnectionDefinition().get(0).getConnectionFactoryImplClass());
    Assert.assertEquals(TestActivation.class.getName(), connector.getResourceAdapter().getInboundResourceAdapter().getMessageAdapter().getMessageListener().get(0).getActivationSpec().getActivationSpecClass());
    Assert.assertEquals(TestMessageListener.class.getName(), connector.getResourceAdapter().getInboundResourceAdapter().getMessageAdapter().getMessageListener().get(0).getMessageListenerType());
    Assert.assertEquals(TestAdminObject.class.getName(), connector.getResourceAdapter().getAdminObject().get(0).getAdminObjectClass());
    Assert.assertEquals(TestAdminObjectInterface.class.getName(), connector.getResourceAdapter().getAdminObject().get(0).getAdminObjectInterface());
}
Also used : Connector(org.apache.openejb.jee.Connector) AuthenticationMechanism(javax.resource.spi.AuthenticationMechanism) ManagedConnection(javax.resource.spi.ManagedConnection) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) SecurityPermission(javax.resource.spi.SecurityPermission) Test(org.junit.Test)

Aggregations

SecurityPermission (javax.resource.spi.SecurityPermission)4 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)2 RarBundleContext (com.sun.enterprise.deployment.annotation.context.RarBundleContext)2 AuthenticationMechanism (javax.resource.spi.AuthenticationMechanism)2 AuthMechanism (com.sun.enterprise.deployment.AuthMechanism)1 LicenseDescriptor (com.sun.enterprise.deployment.LicenseDescriptor)1 OutboundResourceAdapter (com.sun.enterprise.deployment.OutboundResourceAdapter)1 Set (java.util.Set)1 ManagedConnection (javax.resource.spi.ManagedConnection)1 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)1 WorkContext (javax.resource.spi.work.WorkContext)1 Connector (org.apache.openejb.jee.Connector)1 Test (org.junit.Test)1