Search in sources :

Example 1 with Interceptor

use of javax.interceptor.Interceptor in project core by weld.

the class ProbeExtension method isMonitored.

private <T> boolean isMonitored(Annotated annotated, BeanAttributes<T> beanAttributes, WeldManager weldManager) {
    if (annotated.isAnnotationPresent(Interceptor.class) || annotated.isAnnotationPresent(Decorator.class)) {
        // Omit interceptors and decorators
        return false;
    }
    final Type type;
    if (annotated instanceof AnnotatedMember) {
        // AnnotatedField or AnnotatedMethod
        type = ((AnnotatedMember<?>) annotated).getDeclaringType().getBaseType();
    } else {
        type = annotated.getBaseType();
    }
    UnproxyableResolutionException unproxyableException = Proxies.getUnproxyableTypeException(type, weldManager.getServices());
    if (unproxyableException != null) {
        // A bean with an interceptor must be a proxyable
        ProbeLogger.LOG.invocationMonitorNotAssociatedNonProxyableType(type);
        ProbeLogger.LOG.catchingTrace(unproxyableException);
        return false;
    }
    if (type instanceof Class) {
        final Class<?> clazz = (Class<?>) type;
        if (invocationMonitorExcludePattern != null && invocationMonitorExcludePattern.matcher(clazz.getName()).matches()) {
            ProbeLogger.LOG.invocationMonitorNotAssociatedExcluded(clazz.getName());
            return false;
        }
    }
    return true;
}
Also used : Decorator(javax.decorator.Decorator) EventType(org.jboss.weld.probe.BootstrapStats.EventType) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) Type(java.lang.reflect.Type) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) VetoedSuppressedAnnotatedType(org.jboss.weld.util.annotated.VetoedSuppressedAnnotatedType) UnproxyableResolutionException(javax.enterprise.inject.UnproxyableResolutionException) AnnotatedMember(javax.enterprise.inject.spi.AnnotatedMember) Interceptor(javax.interceptor.Interceptor)

Example 2 with Interceptor

use of javax.interceptor.Interceptor in project Payara by payara.

the class RolesPermittedInterceptor method getRolesPermitted.

private RolesPermitted getRolesPermitted(InvocationContext invocationContext) {
    Optional<RolesPermitted> optionalRolesPermitted;
    // Try the Weld bindings first. This gives us the *exact* binding which caused this interceptor being called
    @SuppressWarnings("unchecked") Set<Annotation> bindings = (Set<Annotation>) invocationContext.getContextData().get("org.jboss.weld.interceptor.bindings");
    if (bindings != null) {
        optionalRolesPermitted = bindings.stream().filter(annotation -> annotation.annotationType().equals(RolesPermitted.class)).findAny().map(RolesPermitted.class::cast);
        if (optionalRolesPermitted.isPresent()) {
            return optionalRolesPermitted.get();
        }
    }
    final BeanManager beanManager = lazyProperties.getBeanManager();
    // Failing the Weld binding, check the method first
    optionalRolesPermitted = getAnnotationFromMethod(beanManager, invocationContext.getMethod(), RolesPermitted.class);
    if (optionalRolesPermitted.isPresent()) {
        return optionalRolesPermitted.get();
    }
    // If nothing found on the method, check the the bean class
    optionalRolesPermitted = getAnnotation(beanManager, interceptedBean.getBeanClass(), RolesPermitted.class);
    if (optionalRolesPermitted.isPresent()) {
        return optionalRolesPermitted.get();
    }
    // find it signals a critical error.
    throw new IllegalStateException("@RolesPermitted not found on " + interceptedBean.getBeanClass());
}
Also used : InvocationContext(javax.interceptor.InvocationContext) AND(fish.payara.cdi.auth.roles.LogicalOperator.AND) Intercepted(javax.enterprise.inject.Intercepted) Inject(javax.inject.Inject) Interceptor(javax.interceptor.Interceptor) SecurityContext(javax.security.enterprise.SecurityContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) OR(fish.payara.cdi.auth.roles.LogicalOperator.OR) NOT_DONE(javax.security.enterprise.AuthenticationStatus.NOT_DONE) Arrays.asList(java.util.Arrays.asList) Parameter(java.lang.reflect.Parameter) Named(javax.inject.Named) LinkedList(java.util.LinkedList) Method(java.lang.reflect.Method) AuthenticationParameters.withParams(javax.security.enterprise.authentication.mechanism.http.AuthenticationParameters.withParams) AuthenticationStatus(javax.security.enterprise.AuthenticationStatus) SEND_FAILURE(javax.security.enterprise.AuthenticationStatus.SEND_FAILURE) Context(javax.ws.rs.core.Context) AnnotationELPProcessor.evalELExpression(org.glassfish.soteria.cdi.AnnotationELPProcessor.evalELExpression) HttpServletResponse(javax.servlet.http.HttpServletResponse) AnnotationELPProcessor.hasAnyELExpression(org.glassfish.soteria.cdi.AnnotationELPProcessor.hasAnyELExpression) Set(java.util.Set) ELProcessor(javax.el.ELProcessor) Serializable(java.io.Serializable) CallerAccessException(fish.payara.cdi.auth.roles.CallerAccessException) Priority(javax.annotation.Priority) SUCCESS(javax.security.enterprise.AuthenticationStatus.SUCCESS) List(java.util.List) Response(javax.ws.rs.core.Response) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) AroundInvoke(javax.interceptor.AroundInvoke) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Queue(java.util.Queue) CdiUtils.getAnnotation(org.glassfish.soteria.cdi.CdiUtils.getAnnotation) RolesPermitted(fish.payara.cdi.auth.roles.RolesPermitted) Bean(javax.enterprise.inject.spi.Bean) BeanManager(javax.enterprise.inject.spi.BeanManager) Set(java.util.Set) RolesPermitted(fish.payara.cdi.auth.roles.RolesPermitted) BeanManager(javax.enterprise.inject.spi.BeanManager) Annotation(java.lang.annotation.Annotation) CdiUtils.getAnnotation(org.glassfish.soteria.cdi.CdiUtils.getAnnotation)

Aggregations

Interceptor (javax.interceptor.Interceptor)2 CallerAccessException (fish.payara.cdi.auth.roles.CallerAccessException)1 AND (fish.payara.cdi.auth.roles.LogicalOperator.AND)1 OR (fish.payara.cdi.auth.roles.LogicalOperator.OR)1 RolesPermitted (fish.payara.cdi.auth.roles.RolesPermitted)1 Serializable (java.io.Serializable)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 Type (java.lang.reflect.Type)1 Arrays.asList (java.util.Arrays.asList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Optional (java.util.Optional)1 Queue (java.util.Queue)1 Set (java.util.Set)1 Priority (javax.annotation.Priority)1 Decorator (javax.decorator.Decorator)1 ELProcessor (javax.el.ELProcessor)1 Intercepted (javax.enterprise.inject.Intercepted)1