package eu.dnetlib.uoaadmintools;

import eu.dnetlib.uoaadmintools.handlers.AuthorizationHandler;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by argirok on 23/2/2018.
 */

@Configuration
public class UoaAdminToolsConfiguration extends WebMvcConfigurerAdapter {
    private final Logger log = Logger.getLogger(this.getClass());

@Value( "${admintool.userInfoUrl}" )
private String userInfoUrl = null;

    @Value( "${admintool.originServer}" )
    private String originServer= null;

    @Bean
    public static PropertySourcesPlaceholderConfigurer  propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AuthorizationHandler(userInfoUrl,originServer))
                .addPathPatterns("/**");

    }

}
