Search in sources :

Example 1 with AroundInvoke

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());
    }
}
Also used : CompleteTask(org.activiti.cdi.annotation.CompleteTask) ActivitiCdiException(org.activiti.cdi.ActivitiCdiException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AroundInvoke(javax.interceptor.AroundInvoke)

Example 2 with AroundInvoke

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);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) StartProcess(org.activiti.cdi.annotation.StartProcess) InvocationTargetException(java.lang.reflect.InvocationTargetException) ActivitiException(org.activiti.engine.ActivitiException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AroundInvoke(javax.interceptor.AroundInvoke)

Example 3 with AroundInvoke

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);
        }
    }
}
Also used : IllegalStateException(javax.resource.spi.IllegalStateException) ContextStateCache(org.jboss.as.security.api.ContextStateCache) CurrentUserCredential(org.jboss.as.test.integration.ejb.container.interceptor.security.CurrentUserCredential) UserPrincipal(org.jboss.as.core.security.api.UserPrincipal) Principal(java.security.Principal) SimplePrincipal(org.jboss.security.SimplePrincipal) UserPrincipal(org.jboss.as.core.security.api.UserPrincipal) SimplePrincipal(org.jboss.security.SimplePrincipal) EJBAccessException(javax.ejb.EJBAccessException) IllegalStateException(javax.resource.spi.IllegalStateException) EJBAccessException(javax.ejb.EJBAccessException) AroundInvoke(javax.interceptor.AroundInvoke)

Example 4 with AroundInvoke

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();
        });
    }
}
Also used : Logger(org.slf4j.Logger) InvocationContext(javax.interceptor.InvocationContext) IndyMetrics(org.commonjava.indy.measure.annotation.IndyMetrics) IndyMetricsConfig(org.commonjava.indy.metrics.conf.IndyMetricsConfig) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) IndyMetricsManager(org.commonjava.indy.IndyMetricsManager) Inject(javax.inject.Inject) Interceptor(javax.interceptor.Interceptor) Meter(com.codahale.metrics.Meter) List(java.util.List) Measure(org.commonjava.indy.measure.annotation.Measure) Stream(java.util.stream.Stream) IndyMetricsNamed(org.commonjava.indy.metrics.conf.annotation.IndyMetricsNamed) Timer(com.codahale.metrics.Timer) AroundInvoke(javax.interceptor.AroundInvoke) InvocationContext(javax.interceptor.InvocationContext) Meter(com.codahale.metrics.Meter) Measure(org.commonjava.indy.measure.annotation.Measure) IndyMetrics(org.commonjava.indy.measure.annotation.IndyMetrics) AroundInvoke(javax.interceptor.AroundInvoke)

Example 5 with AroundInvoke

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;
    }
}
Also used : InterceptSecure(org.xdi.service.security.InterceptSecure) InterceptSecure(org.xdi.service.security.InterceptSecure) Secure(org.xdi.service.security.Secure) HttpServletResponse(javax.servlet.http.HttpServletResponse) SecurityEvaluationException(org.xdi.service.security.SecurityEvaluationException) SecurityEvaluationException(org.xdi.service.security.SecurityEvaluationException) AroundInvoke(javax.interceptor.AroundInvoke)

Aggregations

AroundInvoke (javax.interceptor.AroundInvoke)52 Method (java.lang.reflect.Method)10 InvocationManager (org.glassfish.api.invocation.InvocationManager)6 FaultToleranceService (fish.payara.microprofile.faulttolerance.FaultToleranceService)5 FallbackPolicy (fish.payara.microprofile.faulttolerance.interceptors.fallback.FallbackPolicy)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 TransactionalException (javax.transaction.TransactionalException)5 Config (org.eclipse.microprofile.config.Config)5 Fallback (org.eclipse.microprofile.faulttolerance.Fallback)5 PayaraCacheKeyInvocationContext (fish.payara.cdi.jsr107.implementation.PayaraCacheKeyInvocationContext)4 Meter (com.codahale.metrics.Meter)2 Timer (com.codahale.metrics.Timer)2 TransactionManagerHelper (com.sun.enterprise.transaction.TransactionManagerHelper)2 CallerAccessException (fish.payara.cdi.auth.roles.CallerAccessException)2 RolesPermitted (fish.payara.cdi.auth.roles.RolesPermitted)2 Parameter (java.lang.reflect.Parameter)2 Principal (java.security.Principal)2 ArrayList (java.util.ArrayList)2 NoSuchElementException (java.util.NoSuchElementException)2 Message (javax.jms.Message)2