Search in sources :

Example 1 with RunAs

use of javax.annotation.security.RunAs in project Payara by payara.

the class RunAsHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    RunAs runAsAn = (RunAs) ainfo.getAnnotation();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = ejbContext.getDescriptor();
        // override by xml
        if (ejbDesc.getUsesCallerIdentity() != null) {
            continue;
        }
        String roleName = runAsAn.value();
        Role role = new Role(roleName);
        // add Role if not exists
        ejbDesc.getEjbBundleDescriptor().addRole(role);
        RunAsIdentityDescriptor runAsDesc = new RunAsIdentityDescriptor();
        runAsDesc.setRoleName(roleName);
        ejbDesc.setUsesCallerIdentity(false);
        if (ejbDesc.getRunAsIdentity() == null) {
            ejbDesc.setRunAsIdentity(runAsDesc);
        }
    }
    return getDefaultProcessedResult();
}
Also used : Role(org.glassfish.security.common.Role) RunAsIdentityDescriptor(com.sun.enterprise.deployment.RunAsIdentityDescriptor) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) RunAs(javax.annotation.security.RunAs) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Example 2 with RunAs

use of javax.annotation.security.RunAs in project wildfly by wildfly.

the class RunAsMergingProcessor method handleAnnotations.

@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
    final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
    // we only care about annotations on the bean class itself
    if (clazz == null) {
        return;
    }
    final ClassAnnotationInformation<RunAs, String> runAs = clazz.getAnnotationInformation(RunAs.class);
    final ClassAnnotationInformation<RunAsPrincipal, String> runAsPrincipal = clazz.getAnnotationInformation(RunAsPrincipal.class);
    if (runAs == null) {
        if (runAsPrincipal != null) {
            EjbLogger.DEPLOYMENT_LOGGER.missingRunAsAnnotation(componentClass.getName());
        }
        return;
    }
    if (!runAs.getClassLevelAnnotations().isEmpty()) {
        componentConfiguration.setRunAs(runAs.getClassLevelAnnotations().get(0));
    }
    String principal = DEFAULT_RUN_AS_PRINCIPAL;
    if (runAsPrincipal != null && !runAsPrincipal.getClassLevelAnnotations().isEmpty()) {
        principal = runAsPrincipal.getClassLevelAnnotations().get(0);
    }
    componentConfiguration.setRunAsPrincipal(principal);
}
Also used : RunAsPrincipal(org.jboss.ejb3.annotation.RunAsPrincipal) RunAs(javax.annotation.security.RunAs) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription)

Example 3 with RunAs

use of javax.annotation.security.RunAs in project Payara by payara.

the class DynamicWebServletRegistrationImpl method postProcessAnnotations.

void postProcessAnnotations() {
    Class<? extends Servlet> clazz = wrapper.getServletClass();
    if (clazz == null) {
        return;
    }
    // Process RunAs
    if (wcd.getRunAsIdentity() == null) {
        String roleName = runAsRoleName;
        if (roleName == null && clazz.isAnnotationPresent(RunAs.class)) {
            RunAs runAs = clazz.getAnnotation(RunAs.class);
            roleName = runAs.value();
        }
        if (roleName != null) {
            super.setRunAsRole(roleName);
            wbd.addRole(new Role(roleName));
            RunAsIdentityDescriptor runAsDesc = new RunAsIdentityDescriptor();
            runAsDesc.setRoleName(roleName);
            wcd.setRunAsIdentity(runAsDesc);
        }
    }
    // Process ServletSecurity
    ServletSecurityElement ssElement = servletSecurityElement;
    if (servletSecurityElement == null && clazz.isAnnotationPresent(ServletSecurity.class)) {
        ServletSecurity servletSecurity = clazz.getAnnotation(ServletSecurity.class);
        ssElement = new ServletSecurityElement(servletSecurity);
    }
    if (ssElement != null) {
        webModule.processServletSecurityElement(ssElement, wbd, wcd);
    }
}
Also used : Role(org.glassfish.security.common.Role) RunAsIdentityDescriptor(com.sun.enterprise.deployment.RunAsIdentityDescriptor) ServletSecurity(javax.servlet.annotation.ServletSecurity) RunAs(javax.annotation.security.RunAs) ServletSecurityElement(javax.servlet.ServletSecurityElement)

Example 4 with RunAs

use of javax.annotation.security.RunAs in project Payara by payara.

the class RunAsHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, WebComponentContext[] webCompContexts) throws AnnotationProcessorException {
    RunAs runAsAn = (RunAs) ainfo.getAnnotation();
    for (WebComponentContext webCompContext : webCompContexts) {
        WebComponentDescriptor webDesc = webCompContext.getDescriptor();
        // override by xml
        if (webDesc.getRunAsIdentity() != null) {
            continue;
        }
        String roleName = runAsAn.value();
        Role role = new Role(roleName);
        // add Role if not exists
        webDesc.getWebBundleDescriptor().addRole(role);
        RunAsIdentityDescriptor runAsDesc = new RunAsIdentityDescriptor();
        runAsDesc.setRoleName(roleName);
        webDesc.setRunAsIdentity(runAsDesc);
    }
    return getDefaultProcessedResult();
}
Also used : Role(org.glassfish.security.common.Role) WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) WebComponentContext(com.sun.enterprise.deployment.annotation.context.WebComponentContext) RunAsIdentityDescriptor(com.sun.enterprise.deployment.RunAsIdentityDescriptor) RunAs(javax.annotation.security.RunAs)

Example 5 with RunAs

use of javax.annotation.security.RunAs in project Payara by payara.

the class RunAsHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    RunAs runAsAn = (RunAs) ainfo.getAnnotation();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = ejbContext.getDescriptor();
        // override by xml
        if (ejbDesc.getUsesCallerIdentity() != null) {
            continue;
        }
        String roleName = runAsAn.value();
        Role role = new Role(roleName);
        // add Role if not exists
        ejbDesc.getEjbBundleDescriptor().addRole(role);
        RunAsIdentityDescriptor runAsDesc = new RunAsIdentityDescriptor();
        runAsDesc.setRoleName(roleName);
        ejbDesc.setUsesCallerIdentity(false);
        if (ejbDesc.getRunAsIdentity() == null) {
            ejbDesc.setRunAsIdentity(runAsDesc);
        }
    }
    return getDefaultProcessedResult();
}
Also used : Role(org.glassfish.security.common.Role) RunAsIdentityDescriptor(com.sun.enterprise.deployment.RunAsIdentityDescriptor) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) RunAs(javax.annotation.security.RunAs) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Aggregations

RunAs (javax.annotation.security.RunAs)8 RunAsIdentityDescriptor (com.sun.enterprise.deployment.RunAsIdentityDescriptor)5 Role (org.glassfish.security.common.Role)5 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)2 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)2 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)2 WebComponentContext (com.sun.enterprise.deployment.annotation.context.WebComponentContext)2 ServletSecurityElement (javax.servlet.ServletSecurityElement)2 ServletSecurity (javax.servlet.annotation.ServletSecurity)2 Container (org.apache.catalina.Container)1 Wrapper (org.apache.catalina.Wrapper)1 ApplicationServletRegistration (org.apache.catalina.core.ApplicationServletRegistration)1 BeanContext (org.apache.openejb.BeanContext)1 ThreadContext (org.apache.openejb.core.ThreadContext)1 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)1 RunAsPrincipal (org.jboss.ejb3.annotation.RunAsPrincipal)1 Statement (org.junit.runners.model.Statement)1