package eu.eudat.configurations; import eu.eudat.commons.scope.UserScope; import eu.eudat.interceptors.UserInterceptor; import eu.eudat.logic.handlers.PrincipalArgumentResolver; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.operations.authentication.AuthenticationService; import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.util.List; @EnableAsync @Configuration @EnableScheduling public class WebMVCConfiguration implements WebMvcConfigurer { private ApiContext apiContext; private AuthenticationService verifiedUserAuthenticationService; private AuthenticationService nonVerifiedUserAuthenticationService; private final UserInterceptor userInterceptor; private final UserScope userScope; private final CurrentPrincipalResolver currentPrincipalResolver; @Autowired public WebMVCConfiguration(ApiContext apiContext, AuthenticationService verifiedUserAuthenticationService, AuthenticationService nonVerifiedUserAuthenticationService, UserInterceptor userInterceptor, UserScope userScope, CurrentPrincipalResolver currentPrincipalResolver) { this.apiContext = apiContext; this.verifiedUserAuthenticationService = verifiedUserAuthenticationService; this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService; this.userInterceptor = userInterceptor; this.userScope = userScope; this.currentPrincipalResolver = currentPrincipalResolver; } @Autowired @Override public void addArgumentResolvers(List argumentResolvers) { argumentResolvers.add(new PrincipalArgumentResolver(verifiedUserAuthenticationService, nonVerifiedUserAuthenticationService, userScope, currentPrincipalResolver)); } @Override public void addInterceptors(InterceptorRegistry registry) { // registry.addInterceptor(new RequestInterceptor(this.apiContext.getHelpersService().getLoggerService())); registry.addWebRequestInterceptor(userInterceptor).order(1); } }