Java-82 Correctly configure Netty server and security (#10034)

* Java-82 Correctly configure netty server and security

* Java-82 Align WebSecurity with article

* Java-82 Change port

Co-authored-by: mikr <michael.krimgen@ximedes.com>
This commit is contained in:
Maiklins 2020-10-10 09:17:35 +02:00 committed by GitHub
parent ab7e2477d8
commit 4cd2feed94
4 changed files with 11 additions and 16 deletions

View File

@ -7,7 +7,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Component
@Endpoint(id = "features", enableByDefault = true)
@Endpoint(id = "features")
public class FeaturesEndpoint {
private Map<String, Feature> features = new ConcurrentHashMap<>();

View File

@ -4,7 +4,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Spring5ReactiveApplication{
public class Spring5ReactiveApplication {
public static void main(String[] args) {
SpringApplication.run(Spring5ReactiveApplication.class, args);

View File

@ -1,10 +1,7 @@
package com.baeldung.reactive.actuator;
import org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest;
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.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;
@ -12,17 +9,15 @@ import org.springframework.security.web.server.SecurityWebFilterChain;
@Configuration
@EnableWebFluxSecurity
public class WebSecurityConfig {
@Bean
public SecurityWebFilterChain securitygWebFilterChain(
ServerHttpSecurity http) {
return http
.authorizeExchange()
.matchers(EndpointRequest.to(
FeaturesEndpoint.class
)).permitAll().anyExchange().permitAll().and().csrf().disable().build();
return http.authorizeExchange()
.pathMatchers("/actuator/**").permitAll()
.anyExchange().authenticated()
.and().build();
}
}

View File

@ -21,12 +21,12 @@ public class SecurityConfig {
@Bean
public SecurityWebFilterChain securitygWebFilterChain(ServerHttpSecurity http) {
return http.authorizeExchange()
.pathMatchers("/", "/admin")
.pathMatchers("/admin")
.hasAuthority("ROLE_ADMIN")
.matchers(EndpointRequest.to(FeaturesEndpoint.class))
.permitAll()
.anyExchange()
.permitAll()
.authenticated()
.and()
.formLogin()
.and()