From 3e7760f047761dd1f433a4f96fb8a8ac2a35b951 Mon Sep 17 00:00:00 2001 From: tschiman Date: Mon, 24 Oct 2016 20:49:43 -0600 Subject: [PATCH] Modify formatting. --- .../bootstrap/discovery/SecurityConfig.java | 18 +++++++++++++++--- .../bootstrap/gateway/SecurityConfig.java | 15 ++++++++++++--- .../bootstrap/resource/SecurityConfig.java | 9 ++++++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/spring-cloud/spring-cloud-bootstrap/discovery/src/main/java/com/baeldung/spring/cloud/bootstrap/discovery/SecurityConfig.java b/spring-cloud/spring-cloud-bootstrap/discovery/src/main/java/com/baeldung/spring/cloud/bootstrap/discovery/SecurityConfig.java index 0d03d159a0..a55508b1e7 100644 --- a/spring-cloud/spring-cloud-bootstrap/discovery/src/main/java/com/baeldung/spring/cloud/bootstrap/discovery/SecurityConfig.java +++ b/spring-cloud/spring-cloud-bootstrap/discovery/src/main/java/com/baeldung/spring/cloud/bootstrap/discovery/SecurityConfig.java @@ -22,7 +22,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { - http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.ALWAYS).and().requestMatchers().antMatchers("/eureka/**").and().authorizeRequests().antMatchers("/eureka/**").hasRole("SYSTEM").anyRequest().denyAll().and().httpBasic().and() + http + .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.ALWAYS).and() + .requestMatchers().antMatchers("/eureka/**").and() + .authorizeRequests() + .antMatchers("/eureka/**").hasRole("SYSTEM") + .anyRequest().denyAll().and() + .httpBasic().and() .csrf().disable(); } @@ -37,8 +43,14 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { - http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER).and().httpBasic().disable().authorizeRequests().antMatchers(HttpMethod.GET, "/").hasRole("ADMIN").antMatchers("/info", "/health").authenticated().anyRequest() - .denyAll().and().csrf().disable(); + http + .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER).and() + .httpBasic().disable() + .authorizeRequests() + .antMatchers(HttpMethod.GET, "/").hasRole("ADMIN") + .antMatchers("/info", "/health").authenticated() + .anyRequest().denyAll().and() + .csrf().disable(); } } } diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/SecurityConfig.java b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/SecurityConfig.java index e83933feb0..417b61d238 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/SecurityConfig.java +++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/SecurityConfig.java @@ -13,12 +13,21 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication().withUser("user").password("password").roles("USER").and().withUser("admin").password("admin").roles("ADMIN"); + auth.inMemoryAuthentication() + .withUser("user").password("password").roles("USER").and() + .withUser("admin").password("admin").roles("ADMIN"); } @Override protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests().antMatchers("/resource/hello/cloud").permitAll().antMatchers("/eureka/**").hasRole("ADMIN").anyRequest().authenticated().and().formLogin().and().logout().permitAll().logoutSuccessUrl("/resource/hello/cloud").permitAll() - .and().csrf().disable(); + http + .authorizeRequests() + .antMatchers("/resource/hello/cloud").permitAll() + .antMatchers("/eureka/**").hasRole("ADMIN") + .anyRequest().authenticated().and() + .formLogin().and() + .logout().permitAll() + .logoutSuccessUrl("/resource/hello/cloud").permitAll().and() + .csrf().disable(); } } diff --git a/spring-cloud/spring-cloud-bootstrap/resource/src/main/java/com/baeldung/spring/cloud/bootstrap/resource/SecurityConfig.java b/spring-cloud/spring-cloud-bootstrap/resource/src/main/java/com/baeldung/spring/cloud/bootstrap/resource/SecurityConfig.java index 8cea8cf080..813956676e 100644 --- a/spring-cloud/spring-cloud-bootstrap/resource/src/main/java/com/baeldung/spring/cloud/bootstrap/resource/SecurityConfig.java +++ b/spring-cloud/spring-cloud-bootstrap/resource/src/main/java/com/baeldung/spring/cloud/bootstrap/resource/SecurityConfig.java @@ -11,6 +11,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { - http.httpBasic().disable().authorizeRequests().antMatchers("/hello/cloud").permitAll().antMatchers("/hello/user").hasAnyRole("USER", "ADMIN").antMatchers("/hello/admin").hasRole("ADMIN").anyRequest().authenticated().and().csrf().disable(); + http + .httpBasic().disable() + .authorizeRequests() + .antMatchers("/hello/cloud").permitAll() + .antMatchers("/hello/user").hasAnyRole("USER", "ADMIN") + .antMatchers("/hello/admin").hasRole("ADMIN") + .anyRequest().authenticated().and() + .csrf().disable(); } }