Skip to content

Commit dffd6cc

Browse files
committed
find registered security filters
1 parent 308b742 commit dffd6cc

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

spring-security-mvc-boot/src/main/java/org/baeldung/ip/config/SecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
99

1010
@Configuration
11-
@EnableWebSecurity
11+
@EnableWebSecurity//(debug = true)
1212
public class SecurityConfig extends WebSecurityConfigurerAdapter {
1313

1414
@Autowired

spring-security-mvc-boot/src/main/java/org/baeldung/ip/web/MainController.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package org.baeldung.ip.web;
22

3+
import java.util.List;
4+
5+
import javax.servlet.Filter;
36
import javax.servlet.http.HttpServletRequest;
47

58
import org.baeldung.custom.persistence.model.Foo;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.beans.factory.annotation.Qualifier;
11+
import org.springframework.security.web.FilterChainProxy;
12+
import org.springframework.security.web.SecurityFilterChain;
613
import org.springframework.stereotype.Controller;
714
import org.springframework.web.bind.annotation.PathVariable;
815
import org.springframework.web.bind.annotation.RequestMapping;
@@ -12,9 +19,18 @@
1219
@Controller
1320
public class MainController {
1421

22+
@Autowired
23+
@Qualifier("springSecurityFilterChain")
24+
private Filter springSecurityFilterChain;
25+
1526
@RequestMapping(method = RequestMethod.GET, value = "/foos/{id}")
1627
@ResponseBody
1728
public Foo findById(@PathVariable final long id, HttpServletRequest request) {
29+
FilterChainProxy filterChainProxy = (FilterChainProxy) springSecurityFilterChain;
30+
List<SecurityFilterChain> list = filterChainProxy.getFilterChains();
31+
list.forEach(chain -> chain.getFilters()
32+
.forEach(filter -> System.out.println(filter.getClass())));
33+
1834
return new Foo("Sample");
1935
}
2036

spring-security-mvc-boot/src/main/resources/application.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ spring.datasource.password=
66
spring.jpa.hibernate.ddl-auto=create-drop
77
spring.jpa.database=H2
88
spring.jpa.show-sql=false
9-
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
9+
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
10+
11+
12+
#logging.level.org.springframework.security.web.FilterChainProxy=DEBUG

0 commit comments

Comments
 (0)