use of fish.payara.cdi.auth.roles.RolesPermitted 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();
}
use of fish.payara.cdi.auth.roles.RolesPermitted 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();
}
use of fish.payara.cdi.auth.roles.RolesPermitted in project Payara by payara.
the class RolesPermittedInterceptor method getRolesPermitted.
private RolesPermitted getRolesPermitted(InvocationContext invocationContext) {
Optional<RolesPermitted> optionalRolesPermitted;
// Try the Weld bindings first. This gives us the *exact* binding which caused this interceptor being called
@SuppressWarnings("unchecked") Set<Annotation> bindings = (Set<Annotation>) invocationContext.getContextData().get("org.jboss.weld.interceptor.bindings");
if (bindings != null) {
optionalRolesPermitted = bindings.stream().filter(annotation -> annotation.annotationType().equals(RolesPermitted.class)).findAny().map(RolesPermitted.class::cast);
if (optionalRolesPermitted.isPresent()) {
return optionalRolesPermitted.get();
}
}
final BeanManager beanManager = lazyProperties.getBeanManager();
// Failing the Weld binding, check the method first
optionalRolesPermitted = getAnnotationFromMethod(beanManager, invocationContext.getMethod(), RolesPermitted.class);
if (optionalRolesPermitted.isPresent()) {
return optionalRolesPermitted.get();
}
// If nothing found on the method, check the the bean class
optionalRolesPermitted = getAnnotation(beanManager, interceptedBean.getBeanClass(), RolesPermitted.class);
if (optionalRolesPermitted.isPresent()) {
return optionalRolesPermitted.get();
}
// find it signals a critical error.
throw new IllegalStateException("@RolesPermitted not found on " + interceptedBean.getBeanClass());
}
Aggregations