com.jslsolucoes.auth.ee.strategy.impl.AbstractAuthStrategy Maven / Gradle / Ivy
package com.jslsolucoes.auth.ee.strategy.impl;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import javax.enterprise.inject.Vetoed;
import javax.interceptor.InvocationContext;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jslsolucoes.auth.ee.model.response.AuthFailedResponse;
import com.jslsolucoes.auth.ee.strategy.AuthStrategy;
@Vetoed
public abstract class AbstractAuthStrategy implements AuthStrategy {
private static final Logger logger = LoggerFactory.getLogger(AbstractAuthStrategy.class);
protected T annotation(InvocationContext invocationContext, Class annotationClass) {
Method method = invocationContext.getMethod();
logger.debug("Annotation {} exists of method {}.{} => {}", annotationClass,method.getDeclaringClass(),method.getName(),
method.isAnnotationPresent(annotationClass));
return method.getAnnotation(annotationClass);
}
protected Object forbidden(InvocationContext invocationContext, String message) {
Response response = Response.status(Status.FORBIDDEN).entity(new AuthFailedResponse(message)).build();
AsyncResponse asyncResponse = asyncResponse(invocationContext);
if (asyncResponse != null) {
asyncResponse.resume(response);
}
return response;
}
protected AsyncResponse asyncResponse(InvocationContext invocationContext) {
for (Object object : invocationContext.getParameters()) {
if (AsyncResponse.class.isInstance(object)) {
return (AsyncResponse) object;
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy