Search in sources :

Example 21 with CurrentUser

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);
}
Also used : User(org.hisp.dhis.user.User) CurrentUser(org.hisp.dhis.user.CurrentUser) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) CurrentUser(org.hisp.dhis.user.CurrentUser)

Aggregations

CurrentUser (org.hisp.dhis.user.CurrentUser)21 User (org.hisp.dhis.user.User)21 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)8 CollectionNode (org.hisp.dhis.node.types.CollectionNode)8 RootNode (org.hisp.dhis.node.types.RootNode)8 SimpleNode (org.hisp.dhis.node.types.SimpleNode)8 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)7 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)2 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)2 Enums (com.google.common.base.Enums)2 Joiner (com.google.common.base.Joiner)2 Optional (com.google.common.base.Optional)2 Lists (com.google.common.collect.Lists)2 IOException (java.io.IOException)2