use of org.hisp.dhis.user.CurrentUser in project dhis2-core by dhis2.
the class CurrentUserHandlerMethodArgumentResolver method resolveArgument.
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
Class<?> type = parameter.getParameterType();
if (type == String.class) {
return currentUserService.getCurrentUsername();
}
User user = currentUserService.getCurrentUser();
CurrentUser annotation = parameter.getParameterAnnotation(CurrentUser.class);
if (user == null && annotation != null && annotation.required()) {
throw new NotAuthenticatedException();
}
if (User.class.isAssignableFrom(type)) {
return user;
}
throw new UnsupportedOperationException("Not yet supported @CurrentUser type: " + type);
}
Aggregations