WebMvcConfig.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.its.op.security;
  2. import com.its.op.interceptor.ApiHandlerInterceptor;
  3. import lombok.AllArgsConstructor;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.web.servlet.config.annotation.*;
  6. @AllArgsConstructor
  7. @Configuration
  8. public class WebMvcConfig implements WebMvcConfigurer {
  9. public static final String USER_UUID = "UUID";
  10. public static final String USER_TIME = "TIME";
  11. private final ApiHandlerInterceptor apiHandlerInterceptor;
  12. /**
  13. * Controller Handler 인터셉서 등록
  14. * @param registry
  15. */
  16. @Override
  17. public void addInterceptors(InterceptorRegistry registry) {
  18. registry.addInterceptor(this.apiHandlerInterceptor)
  19. .addPathPatterns("/api/**") // API Controller interceptors
  20. .excludePathPatterns("/facility/**", "/wall/**") // 해당 경로는 인터셉터가 가로채지 않는다.
  21. ;
  22. }
  23. @Override
  24. public void addCorsMappings(CorsRegistry registry) {
  25. registry.addMapping("/**")
  26. //.allowCredentials(true)
  27. //.allowedOriginPatterns("*")
  28. .allowedOrigins("*") // 허용할 Origin(요청 url) : "*" 의 경우 모두 허용
  29. .allowedMethods("GET", "POST", "PUT", "DELETE") // 허용할 request http METHOD : POST, GET, DELETE, PUT
  30. .maxAge(3600) // 브라우저 캐시 시간(단위: 초) : "3600" 이면 최소 1시간 안에는 서버로 재요청 되지 않음
  31. ;
  32. }
  33. // @Override
  34. // public void addViewControllers(ViewControllerRegistry registry) {
  35. // //registry.addRedirectViewController("/", "/api/auth/login.do");
  36. // }
  37. @Override
  38. public void addResourceHandlers(ResourceHandlerRegistry registry) {
  39. // registry.addResourceHandler("swagger-ui.html")
  40. // .addResourceLocations("classpath:/META-INF/resources/");
  41. // registry.addResourceHandler("/webjars/**")
  42. // .addResourceLocations("classpath:/META-INF/resources/webjars/");
  43. String separator = System.getProperty("file.separator");
  44. String mapDataDir = System.getProperty("user.dir")+separator+"MAPDATA/";
  45. String downloadDir = System.getProperty("user.dir")+separator+"download/";
  46. registry.addResourceHandler("/MAPDATA/**")
  47. .addResourceLocations("file:///" + mapDataDir)
  48. //.setCachePeriod(60) // seconds
  49. ;
  50. registry.addResourceHandler("/download/**")
  51. .addResourceLocations("file:///" + downloadDir)
  52. //.setCachePeriod(60) // seconds
  53. ;
  54. }
  55. public static String encUserId(String userId) {
  56. return userId;
  57. }
  58. public static String decUserId(Object encUserId) {
  59. String decUserId = (String)encUserId;
  60. return decUserId;
  61. }
  62. }