All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jslsolucoes.auth.ee.AuthInterceptor Maven / Gradle / Ivy

There is a newer version: 1.0.32
Show newest version
package com.jslsolucoes.auth.ee;

import java.lang.reflect.Method;

import javax.annotation.Priority;
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jslsolucoes.auth.ee.strategy.AuthStrategy;

@Interceptor
@Private
@Priority(Interceptor.Priority.APPLICATION + 100)
public class AuthInterceptor {

    
    private static final Logger logger = LoggerFactory.getLogger(AuthInterceptor.class);
    
    @Inject
    private AuthStrategy authorizationStrategy;

    @AroundInvoke
    public Object manageAuth(InvocationContext invocationContext) throws Exception {
	if (isPublic(invocationContext.getMethod())) {
	    logger.debug("method is public, proceeding ..");
	    return invocationContext.proceed();
	} else {
	    logger.debug("method is private checking for authentication ..");
	    return authorizationStrategy.handleAuth(invocationContext);
	}
    }

    private Boolean isPublic(Method method) {
	return method.getDeclaringClass().isAnnotationPresent(Public.class) || method.isAnnotationPresent(Public.class);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy