Search in sources :

Example 1 with ActivityFeaturesEnum

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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActivityFeaturesEnum(eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityFeaturesEnum) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) AroundInvoke(javax.interceptor.AroundInvoke)

Aggregations

ActivityFeaturesEnum (eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityFeaturesEnum)1 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)1 AroundInvoke (javax.interceptor.AroundInvoke)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1