From dffd6cc87d1f27c80da5fc361ed736098c4cd9e1 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sun, 16 Sep 2018 14:56:21 +0300 Subject: [PATCH] find registered security filters --- .../org/baeldung/ip/config/SecurityConfig.java | 2 +- .../java/org/baeldung/ip/web/MainController.java | 16 ++++++++++++++++ .../src/main/resources/application.properties | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/spring-security-mvc-boot/src/main/java/org/baeldung/ip/config/SecurityConfig.java b/spring-security-mvc-boot/src/main/java/org/baeldung/ip/config/SecurityConfig.java index b4ed8277d6..3a8032a734 100644 --- a/spring-security-mvc-boot/src/main/java/org/baeldung/ip/config/SecurityConfig.java +++ b/spring-security-mvc-boot/src/main/java/org/baeldung/ip/config/SecurityConfig.java @@ -8,7 +8,7 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration -@EnableWebSecurity +@EnableWebSecurity//(debug = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired diff --git a/spring-security-mvc-boot/src/main/java/org/baeldung/ip/web/MainController.java b/spring-security-mvc-boot/src/main/java/org/baeldung/ip/web/MainController.java index da5db5e825..8996a698d6 100644 --- a/spring-security-mvc-boot/src/main/java/org/baeldung/ip/web/MainController.java +++ b/spring-security-mvc-boot/src/main/java/org/baeldung/ip/web/MainController.java @@ -1,8 +1,15 @@ package org.baeldung.ip.web; +import java.util.List; + +import javax.servlet.Filter; import javax.servlet.http.HttpServletRequest; import org.baeldung.custom.persistence.model.Foo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.security.web.FilterChainProxy; +import org.springframework.security.web.SecurityFilterChain; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -12,9 +19,18 @@ import org.springframework.web.bind.annotation.ResponseBody; @Controller public class MainController { + @Autowired + @Qualifier("springSecurityFilterChain") + private Filter springSecurityFilterChain; + @RequestMapping(method = RequestMethod.GET, value = "/foos/{id}") @ResponseBody public Foo findById(@PathVariable final long id, HttpServletRequest request) { + FilterChainProxy filterChainProxy = (FilterChainProxy) springSecurityFilterChain; + List list = filterChainProxy.getFilterChains(); + list.forEach(chain -> chain.getFilters() + .forEach(filter -> System.out.println(filter.getClass()))); + return new Foo("Sample"); } diff --git a/spring-security-mvc-boot/src/main/resources/application.properties b/spring-security-mvc-boot/src/main/resources/application.properties index f015086a4f..25eac743d1 100644 --- a/spring-security-mvc-boot/src/main/resources/application.properties +++ b/spring-security-mvc-boot/src/main/resources/application.properties @@ -6,4 +6,7 @@ spring.datasource.password= spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.database=H2 spring.jpa.show-sql=false -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect \ No newline at end of file +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect + + +#logging.level.org.springframework.security.web.FilterChainProxy=DEBUG \ No newline at end of file