Search in sources :

Example 1 with CallerAccessException

use of fish.payara.cdi.auth.roles.CallerAccessException in project Payara by payara.

the class RolesPermittedInterceptor method method.

/**
 * Method invoked whenever a method annotated with @Roles, or a method
 * within a class annotated with @Roles is called.
 *
 * @param invocationContext Context provided by Weld.
 * @return Proceed to next interceptor in chain.
 * @throws java.lang.Exception
 * @throws fish.payara.cdi.auth.roles.CallerAccessException if access is not permitted
 */
@AroundInvoke
public Object method(InvocationContext invocationContext) throws Exception {
    RolesPermitted roles = getRolesPermitted(invocationContext);
    boolean isAccessPermitted = checkAccessPermitted(roles, invocationContext);
    if (!isAccessPermitted) {
        throw new CallerAccessException("Caller was not permitted access to a protected resource");
    }
    return invocationContext.proceed();
}
Also used : RolesPermitted(fish.payara.cdi.auth.roles.RolesPermitted) CallerAccessException(fish.payara.cdi.auth.roles.CallerAccessException) AroundInvoke(javax.interceptor.AroundInvoke)

Example 2 with CallerAccessException

use of fish.payara.cdi.auth.roles.CallerAccessException in project Payara by payara.

the class RolesCDIInterceptor method method.

/**
 * Method invoked whenever a method annotated with @Roles, or a method within a class annotated with @Roles is
 * called.
 *
 * @param invocationContext Context provided by Weld.
 * @return Proceed to next interceptor in chain.
 */
@AroundInvoke
public Object method(InvocationContext invocationContext) throws Exception {
    RolesPermitted roles = getRolesPermitted(invocationContext);
    boolean isAccessPermitted = checkAccessPermitted(roles);
    if (!isAccessPermitted) {
        throw new CallerAccessException("Caller was not permitted access to a protected resource");
    }
    return invocationContext.proceed();
}
Also used : RolesPermitted(fish.payara.cdi.auth.roles.RolesPermitted) CallerAccessException(fish.payara.cdi.auth.roles.CallerAccessException) AroundInvoke(javax.interceptor.AroundInvoke)

Aggregations

CallerAccessException (fish.payara.cdi.auth.roles.CallerAccessException)2 RolesPermitted (fish.payara.cdi.auth.roles.RolesPermitted)2 AroundInvoke (javax.interceptor.AroundInvoke)2