Search in sources :

Example 1 with ProcessSessionBean

use of javax.enterprise.inject.spi.ProcessSessionBean in project Payara by payara.

the class CdiExtension method findRoles.

/**
 * Find all the roles used by the <code>@RolesAllowed</code> annotation, so these can be programmatically
 * declared later on.
 */
public <T> void findRoles(@Observes ProcessManagedBean<T> eventIn, BeanManager beanManager) {
    // JDK8 u60 workaround
    ProcessManagedBean<T> event = eventIn;
    if (event instanceof ProcessSessionBean) {
        // @RolesAllowed on session beans is already handled
        return;
    }
    List<Annotated> annotatedElements = new ArrayList<>(event.getAnnotatedBeanClass().getMethods());
    annotatedElements.add(event.getAnnotatedBeanClass());
    for (Annotated annotated : annotatedElements) {
        RolesAllowed rolesAllowed = annotated.getAnnotation(RolesAllowed.class);
        if (rolesAllowed != null) {
            roles.addAll(Arrays.asList(rolesAllowed.value()));
        }
    }
}
Also used : Annotated(javax.enterprise.inject.spi.Annotated) RolesAllowed(javax.annotation.security.RolesAllowed) ArrayList(java.util.ArrayList) ProcessSessionBean(javax.enterprise.inject.spi.ProcessSessionBean)

Example 2 with ProcessSessionBean

use of javax.enterprise.inject.spi.ProcessSessionBean in project Payara by payara.

the class JwtAuthCdiExtension method findRoles.

/**
 * Find all the roles used by the <code>@RolesAllowed</code> annotation, so these can be programmatically
 * declared later on.
 */
public <T> void findRoles(@Observes ProcessManagedBean<T> eventIn, BeanManager beanManager) {
    // JDK8 u60 workaround
    ProcessManagedBean<T> event = eventIn;
    if (event instanceof ProcessSessionBean) {
        // @RolesAllowed on session beans is already handled
        return;
    }
    List<Annotated> annotatedElements = new ArrayList<>(event.getAnnotatedBeanClass().getMethods());
    annotatedElements.add(event.getAnnotatedBeanClass());
    for (Annotated annotated : annotatedElements) {
        RolesAllowed rolesAllowed = annotated.getAnnotation(RolesAllowed.class);
        if (rolesAllowed != null) {
            roles.addAll(Arrays.asList(rolesAllowed.value()));
        }
    }
}
Also used : Annotated(javax.enterprise.inject.spi.Annotated) RolesAllowed(javax.annotation.security.RolesAllowed) ArrayList(java.util.ArrayList) ProcessSessionBean(javax.enterprise.inject.spi.ProcessSessionBean)

Aggregations

ArrayList (java.util.ArrayList)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 Annotated (javax.enterprise.inject.spi.Annotated)2 ProcessSessionBean (javax.enterprise.inject.spi.ProcessSessionBean)2