-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SecurityFilterChain instead of deprecated WebSecurityConfigurerAd…
…apter
- Loading branch information
Showing
3 changed files
with
19 additions
and
20 deletions.
There are no files selected for viewing
10 changes: 6 additions & 4 deletions
10
...ain/java/de/qaware/openapigeneratorforspring/demo/webmvc/SpringSecurityConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
package de.qaware.openapigeneratorforspring.demo.webmvc; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.security.web.csrf.CookieCsrfTokenRepository; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
public class SpringSecurityConfiguration extends WebSecurityConfigurerAdapter { | ||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
public class SpringSecurityConfiguration { | ||
@Bean | ||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
// do nothing else then configuring CSRF | ||
http | ||
.csrf() | ||
// it doesn't really matter which CSRF token repository is used | ||
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()); | ||
return http.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
...java/de/qaware/openapigeneratorforspring/test/app39/App39SpringSecurityConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
package de.qaware.openapigeneratorforspring.test.app39; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
@Configuration | ||
@Order(Ordered.HIGHEST_PRECEDENCE) | ||
class App39SpringSecurityConfiguration extends WebSecurityConfigurerAdapter { | ||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http.csrf().disable(); | ||
class App39SpringSecurityConfiguration { | ||
@Bean | ||
public SecurityFilterChain noWebMvcSecurityFilterChain(HttpSecurity http) throws Exception { | ||
return http.csrf().disable().build(); | ||
} | ||
} |