Skip to content

Commit

Permalink
Fix #465: Update Spring Security configuration in the documentation (#…
Browse files Browse the repository at this point in the history
…466)

* Fix #465: Update Spring Security configuration in the documentation
  • Loading branch information
banterCZ committed Nov 27, 2023
1 parent 39790d9 commit 69a6cd5
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions docs/RESTful-API-for-Spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public class ApplicationConfiguration implements PowerAuthApplicationConfigurati

_(optional)_

Create a security configuration class `SecurityConfig` extending `WebSecurityConfigurerAdapter`. The configuration we will use:
Create a security configuration class `SecurityConfig` configuring a bean `SecurityFilterChain`. The configuration we will use:

- disable default Basic HTTP authentication
- disables CSRF (we don't need it for REST)
Expand All @@ -205,17 +205,18 @@ Create a security configuration class `SecurityConfig` extending `WebSecurityCon
```java
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
public class SecurityConfig {

@Autowired
private PowerAuthApiAuthenticationEntryPoint apiAuthenticationEntryPoint;

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/secured/**").fullyAuthenticated();
http.httpBasic().disable();
http.csrf().disable();
http.exceptionHandling().authenticationEntryPoint(apiAuthenticationEntryPoint);
@Bean
public SecurityFilterChain filterChain(final HttpSecurity http, final PowerAuthApiAuthenticationEntryPoint apiAuthenticationEntryPoint) throws Exception {
return http
.authorizeHttpRequests(authorize -> authorize
.requestMatchers("/secured/**").fullyAuthenticated())
.exceptionHandling(exceptionHandling ->
exceptionHandling.authenticationEntryPoint(apiAuthenticationEntryPoint))
.httpBasic(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable)
.build();
}

}
Expand Down

0 comments on commit 69a6cd5

Please sign in to comment.