package thyyxxk.webserver.config.auth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import thyyxxk.webserver.service.LoginService;
import thyyxxk.webserver.service.TokenService;

/**
 * @author dj
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    private final LoginService service;
    private final TokenService tokenService;

    @Autowired
    public InterceptorConfig(LoginService service, TokenService tokenService) {
        this.service = service;
        this.tokenService = tokenService;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AuthenticationInterceptor(service, tokenService))
                .addPathPatterns("/**");
    }
}
