AllInOneApplication.kt 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package gaf3.demo.allinone
  2. import gaf3.core.cloud.GafCloudConfiguration
  3. import gaf3.core.gateway.GatewayController
  4. import gaf3.core.gateway.filter.factory.JwtParserGatewayFilterFactory
  5. import gaf3.core.jpa.GafJpaConfiguration
  6. import gaf3.core.services.GafCoreServicesConfiguration
  7. import gaf3.demo.services.AllServicesConfiguration
  8. import org.slf4j.LoggerFactory
  9. import org.springframework.boot.autoconfigure.SpringBootApplication
  10. import org.springframework.boot.runApplication
  11. import org.springframework.cloud.gateway.support.ServerWebExchangeUtils
  12. import org.springframework.cloud.openfeign.EnableFeignClients
  13. import org.springframework.context.annotation.Bean
  14. import org.springframework.context.annotation.Configuration
  15. import org.springframework.context.annotation.Import
  16. import org.springframework.core.annotation.Order
  17. import org.springframework.http.HttpStatus
  18. import org.springframework.stereotype.Controller
  19. import org.springframework.web.server.WebFilter
  20. @SpringBootApplication
  21. @Configuration
  22. @Controller
  23. @Import(GafCloudConfiguration::class, GafJpaConfiguration::class, AllServicesConfiguration::class)
  24. @EnableFeignClients
  25. class AllInOneApplication {
  26. @Bean
  27. fun statusControllerAdvice(): StatusControllerAdvice {
  28. return StatusControllerAdvice()
  29. }
  30. @Bean
  31. fun gatewayController(): GatewayController {
  32. return GatewayController()
  33. }
  34. @Bean
  35. @Order(-1)
  36. fun apiAccessFilter(): WebFilter {
  37. return WebFilter { exchange, chain ->
  38. log.debug("[ApiAccess] start...")
  39. val path = exchange.request.path.value()
  40. log.debug("[ApiAccess] path : {}", path)
  41. if(path.startsWith("/xms")
  42. || path.startsWith("/gaf")) {
  43. ServerWebExchangeUtils.setResponseStatus(exchange, HttpStatus.FORBIDDEN)
  44. exchange.response.setComplete()
  45. } else {
  46. chain.filter(exchange.mutate().build())
  47. }
  48. }
  49. }
  50. companion object {
  51. internal val log = LoggerFactory.getLogger(AllInOneApplication::class.java)
  52. }
  53. }
  54. fun main(args: Array<String>) {
  55. runApplication<AllInOneApplication>(*args)
  56. JwtParserGatewayFilterFactory.doInit()
  57. }