Register SecurityFilterChain in sample
Issue gh-163
This commit is contained in:
parent
d97235d0bb
commit
43fbd9d345
@ -15,37 +15,38 @@
|
|||||||
*/
|
*/
|
||||||
package sample.config;
|
package sample.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
|
import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Joe Grandja
|
* @author Joe Grandja
|
||||||
* @since 0.0.1
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
public class SecurityConfig {
|
||||||
|
|
||||||
// @formatter:off
|
@Bean
|
||||||
@Override
|
WebSecurityCustomizer webSecurityCustomizer() {
|
||||||
public void configure(WebSecurity web) {
|
return (web) -> web.ignoring().antMatchers("/webjars/**");
|
||||||
web
|
|
||||||
.ignoring()
|
|
||||||
.antMatchers("/webjars/**");
|
|
||||||
}
|
}
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
// @formatter:off
|
// formatter:off
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
http
|
http
|
||||||
.authorizeRequests()
|
.authorizeRequests(authorizeRequests ->
|
||||||
.anyRequest().permitAll()
|
authorizeRequests.anyRequest().permitAll()
|
||||||
.and()
|
)
|
||||||
.logout()
|
.logout()
|
||||||
.disable()
|
.disable()
|
||||||
.oauth2Client();
|
.oauth2Client(withDefaults());
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
// @formatter:on
|
// formatter:on
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,27 +15,30 @@
|
|||||||
*/
|
*/
|
||||||
package sample.config;
|
package sample.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
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.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Joe Grandja
|
* @author Joe Grandja
|
||||||
* @since 0.0.1
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class ResourceServerConfig extends WebSecurityConfigurerAdapter {
|
public class ResourceServerConfig {
|
||||||
|
|
||||||
// @formatter:off
|
// formatter:off
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
http
|
http
|
||||||
.mvcMatcher("/messages/**")
|
.mvcMatcher("/messages/**")
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.mvcMatchers("/messages/**").access("hasAuthority('SCOPE_message.read')")
|
.mvcMatchers("/messages/**").access("hasAuthority('SCOPE_message.read')")
|
||||||
.and()
|
.and()
|
||||||
.oauth2ResourceServer()
|
.oauth2ResourceServer()
|
||||||
.jwt();
|
.jwt();
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
// @formatter:on
|
// formatter:on
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user