package cn.com.qmth.stmms.ms.accesscontrol.config;

import cn.com.qmth.stmms.ms.accesscontrol.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by zhengmin on 2017/3/2.
 */
@Configuration
//@Profile(value = "dev")
public class AccessConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("*").allowCredentials(false)
                .allowedMethods("PUT", "DELETE", "GET", "POST", "PATCH").allowedHeaders("Cache-Control", "Pragma",
                "Origin", "Authorization", "Content-Type", "X-Requested-With")
                .maxAge(9999999999999999L);
        // .exposedHeaders("header1", "header2")
    }

    @Bean
    public LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/api/**").excludePathPatterns("/api/admin/users/login","/api/login","/api/logout","/api/*/password",
                "/api/user/login", "/api/user/getClientUser", "/api/exam/students", "/api/upload/student/*", "/api/file/image/**", "/api/marklog/saveCollectLog",
                "/api/file/ms-slice/**", "/api/subject/collect-config", "/api/file/ms-sheet/**", "/api/oss/**", "/api/exam/listStudents/*", "/api/exam/getStudent/*","/api/level/*",
                "/api/file/image/getExportData","/api/file/image/exportScorePicturesFromCollect","/api/admin/works","/api/score/missing/*");
    }
}
