use of javax.interceptor.AroundInvoke in project ART-TIME by Artezio.
the class FacesMessageInterceptor method aroundInvoke.
@AroundInvoke
public Object aroundInvoke(InvocationContext ic) throws Exception {
FacesContext facesContext = FacesContext.getCurrentInstance();
Object result = ic.proceed();
if (facesContext == null) {
return result;
}
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.getFlash().setKeepMessages(true);
FacesMessage annotation = ic.getMethod().getAnnotation(FacesMessage.class);
String onCompleteMessageKey = annotation.onCompleteMessageKey();
Locale locale = externalContext.getRequestLocale();
String messageBundleName = facesContext.getApplication().getMessageBundle();
ResourceBundle messageBundle = ResourceBundle.getBundle(messageBundleName, locale);
facesContext.addMessage(null, new javax.faces.application.FacesMessage(messageBundle.getString(onCompleteMessageKey)));
return result;
}
use of javax.interceptor.AroundInvoke in project ART-TIME by Artezio.
the class DomainSecuredInterceptor method aroundInvoke.
@AroundInvoke
public Object aroundInvoke(InvocationContext ic) throws Exception {
Object[] paramValues = ic.getParameters();
Parameter[] parameters = ic.getMethod().getParameters();
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
if (parameter.isAnnotationPresent(CallerCanManage.class)) {
checkParameter(parameter, paramValues[i]);
}
}
return ic.proceed();
}
use of javax.interceptor.AroundInvoke in project ART-TIME by Artezio.
the class WebCachedInterceptor method process.
@AroundInvoke
public Object process(InvocationContext invocationContext) throws Exception {
Method method = invocationContext.getMethod();
Object targetInstance = invocationContext.getTarget();
Class<?> targetClass = targetInstance.getClass();
WebCached annotation = method.getAnnotation(WebCached.class) != null ? method.getAnnotation(WebCached.class) : targetClass.getAnnotation(WebCached.class);
Map<String, Object> contextProperties = getContextProperties(annotation.scope());
if (contextProperties == null)
return invocationContext.proceed();
String cacheId = "_webCache:" + targetClass.getName();
CacheKey cacheKey = new CacheKey(targetClass, method, invocationContext.getParameters());
if (!annotation.resetCache()) {
Map<String, Object> cache = getCache(contextProperties, cacheId);
Object value = cache.get(cacheKey.toString());
if (value == null) {
value = invocationContext.proceed();
cache.put(cacheKey.toString(), value);
}
return value;
} else {
contextProperties.remove(cacheId);
return invocationContext.proceed();
}
}
use of javax.interceptor.AroundInvoke in project ART-TIME by Artezio.
the class LogInterceptor method process.
@AroundInvoke
public Object process(InvocationContext invocationContext) throws Exception {
Method method = invocationContext.getMethod();
Log annotation = method.getAnnotation(Log.class);
Level level = Level.parse(annotation.level().name());
Logger logger = getLogger(invocationContext);
if (!logger.isLoggable(level)) {
return invocationContext.proceed();
}
Object result;
String principalName = getPrincipalName();
if (principalName == null && annotation.principalsOnly()) {
return invocationContext.proceed();
}
String prefix = MessageFormat.format("({0}) {1}", new Object[] { principalName, method.getName() });
if (!annotation.beforeExecuteMessage().isEmpty()) {
logger.log(level, MessageFormat.format("{0} - {1}", new Object[] { prefix, annotation.beforeExecuteMessage() }));
}
if (annotation.logParams()) {
Parameter[] metaParams = method.getParameters();
Object[] parameters = invocationContext.getParameters();
List<String> paramsAsStr = new ArrayList<>();
for (int i = 0; i < parameters.length; i++) {
String paramAsStr = showDetails(metaParams[i]) ? getDetailedString(parameters[i]) : String.valueOf(parameters[i]);
paramsAsStr.add(paramAsStr);
}
logger.log(level, MessageFormat.format("{0}({1})", new Object[] { prefix, String.join(", ", paramsAsStr) }));
}
try {
result = invocationContext.proceed();
} catch (Exception e) {
logger.log(Level.SEVERE, MessageFormat.format("Thrown exception {0}: {1}. Details in server stack trace.", e.getClass(), e.getMessage()));
throw e;
}
if (annotation.logResult()) {
logger.log(level, MessageFormat.format("{0} - Result is {1}", new Object[] { prefix, String.valueOf(result) }));
}
if (!annotation.afterExecuteMessage().isEmpty()) {
logger.log(level, MessageFormat.format("{0} - {1}", new Object[] { prefix, annotation.afterExecuteMessage() }));
}
return result;
}
use of javax.interceptor.AroundInvoke in project oxCore by GluuFederation.
the class UmaSecureInterceptor method invoke.
@AroundInvoke
public Object invoke(InvocationContext ctx) throws Exception {
HttpServletResponse response = null;
Object[] parameters = ctx.getParameters();
log.trace("REST method call security check. " + ctx.getMethod().getName() + "()");
for (Object parameter : parameters) {
if (parameter instanceof HttpServletResponse)
response = (HttpServletResponse) parameter;
}
InterceptSecure is = securityExtension.getInterceptSecure(ctx.getMethod());
// SecurityChecking restrictions
Secure[] constraints = (is == null) ? new Secure[0] : is.value();
// Getting the parameter values
Map<String, Object> secureVars = computeParameterValues(ctx);
for (Secure constraint : constraints) {
Boolean expressionValue = expressionEvaluator.evaluateValueExpression(constraint.value(), Boolean.class, secureVars);
if ((expressionValue == null) || !expressionValue) {
log.debug("Method: '{}' constrain '{}' evaluation is null or false!", ctx.getMethod(), constraint);
throw new SecurityEvaluationException();
}
}
try {
// the method call
return ctx.proceed();
} catch (Exception e) {
log.error("Error calling ctx.proceed in UmaSecureInterceptor");
// REST call error report
if (response != null) {
try {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "INTERNAL SERVER ERROR");
} catch (Exception ex) {
}
} else if (Response.class.isAssignableFrom(ctx.getMethod().getReturnType())) {
return Response.serverError().entity("INTERNAL SERVER ERROR").build();
}
return null;
}
}
Aggregations