use of eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityFeaturesEnum in project UVMS-ActivityModule-APP by UnionVMS.
the class UserRoleInterceptor method interceptRequest.
@AroundInvoke
public Object interceptRequest(final InvocationContext ic) throws Exception {
IUserRoleInterceptor iUserRoleInterceptor = ic.getMethod().getAnnotation(IUserRoleInterceptor.class);
// Get User role defined in the Rest service
ActivityFeaturesEnum[] features = iUserRoleInterceptor.requiredUserRole();
// Request parameters
Object[] parameters = ic.getParameters();
HttpServletRequest req = getHttpServletRequest(parameters);
boolean isUserAuthorized = false;
for (ActivityFeaturesEnum activityFeaturesEnum : features) {
isUserAuthorized = req.isUserInRole(activityFeaturesEnum.value());
}
if (!isUserAuthorized) {
throw new ServiceException(ErrorCodes.NOT_AUTHORIZED);
}
return ic.proceed();
}
Aggregations