use of javax.interceptor.AroundInvoke in project Activiti by Activiti.
the class CompleteTaskInterceptor method invoke.
@AroundInvoke
public Object invoke(InvocationContext ctx) throws Exception {
try {
Object result = ctx.proceed();
CompleteTask completeTaskAnnotation = ctx.getMethod().getAnnotation(CompleteTask.class);
boolean endConversation = completeTaskAnnotation.endConversation();
businessProcess.completeTask(endConversation);
return result;
} catch (InvocationTargetException e) {
throw new ActivitiCdiException("Error while completing task: " + e.getCause().getMessage(), e.getCause());
}
}
use of javax.interceptor.AroundInvoke in project Activiti by Activiti.
the class StartProcessInterceptor method invoke.
@AroundInvoke
public Object invoke(InvocationContext ctx) throws Exception {
try {
Object result = ctx.proceed();
StartProcess startProcessAnnotation = ctx.getMethod().getAnnotation(StartProcess.class);
String name = startProcessAnnotation.name();
String key = startProcessAnnotation.value();
Map<String, Object> variables = extractVariables(startProcessAnnotation, ctx);
if (name.length() > 0) {
businessProcess.startProcessByName(name, variables);
} else {
businessProcess.startProcessByKey(key, variables);
}
return result;
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof Exception) {
throw (Exception) cause;
} else {
throw e;
}
} catch (Exception e) {
throw new ActivitiException("Error while starting process using @StartProcess on method '" + ctx.getMethod() + "': " + e.getMessage(), e);
}
}
use of javax.interceptor.AroundInvoke in project wildfly by wildfly.
the class ServerSecurityInterceptor method aroundInvoke.
@AroundInvoke
public Object aroundInvoke(final InvocationContext invocationContext) throws Exception {
Principal desiredUser = null;
UserPrincipal connectionUser = null;
Map<String, Object> contextData = invocationContext.getContextData();
if (contextData.containsKey(DELEGATED_USER_KEY)) {
desiredUser = new SimplePrincipal((String) contextData.get(DELEGATED_USER_KEY));
Collection<Principal> principals = ConnectionSecurityContext.getConnectionPrincipals();
if (principals != null) {
for (Principal current : principals) {
if (current instanceof UserPrincipal) {
connectionUser = (UserPrincipal) current;
break;
}
}
} else {
throw new IllegalStateException("Delegation user requested but no user on connection found.");
}
}
ContextStateCache stateCache = null;
try {
if (desiredUser != null && connectionUser != null && (desiredUser.getName().equals(connectionUser.getName()) == false)) {
try {
// The final part of this check is to verify that the change does actually indicate a change in user.
// We have been requested to switch user and have successfully identified the user from the connection
// so now we attempt the switch.
stateCache = ConnectionSecurityContext.pushIdentity(desiredUser, new CurrentUserCredential(connectionUser.getName()));
} catch (Exception e) {
LOGGER.error("Failed to switch security context for user", e);
// Don't propagate the exception stacktrace back to the client for security reasons
throw new EJBAccessException("Unable to attempt switching of user.");
}
}
return invocationContext.proceed();
} finally {
// switch back to original security context
if (stateCache != null) {
ConnectionSecurityContext.popIdentity(stateCache);
}
}
}
use of javax.interceptor.AroundInvoke in project indy by Commonjava.
the class MetricsInterceptor method operation.
@AroundInvoke
public Object operation(InvocationContext context) throws Exception {
if (!config.isMetricsEnabled())
return context.proceed();
IndyMetrics metrics = context.getMethod().getAnnotation(IndyMetrics.class);
if (metrics == null) {
return context.proceed();
}
logger.debug("Gathering metrics for: {}", context.getContextData());
Measure measures = metrics.measure();
List<Timer.Context> timers = Stream.of(measures.timers()).map(named -> util.getTimer(named).time()).collect(Collectors.toList());
try {
return context.proceed();
} catch (Exception e) {
Measure me = metrics.exceptions();
Stream.of(me.meters()).forEach((named) -> {
Meter requests = util.getMeter(named);
requests.mark();
});
throw e;
} finally {
if (timers != null) {
timers.forEach(Timer.Context::stop);
}
Stream.of(measures.meters()).forEach((named) -> {
Meter requests = util.getMeter(named);
requests.mark();
});
}
}
use of javax.interceptor.AroundInvoke in project oxTrust 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