Skip to content

Commit c755175

Browse files
committed
BAEL-315 Clean up some code formatting on the security configurations
1 parent 2777df6 commit c755175

4 files changed

Lines changed: 18 additions & 27 deletions

File tree

‎spring-cloud/spring-cloud-bootstrap/config/src/main/java/com/baeldung/spring/cloud/bootstrap/config/SecurityConfig.java‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,18 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
1313

1414
@Autowired
1515
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
16-
auth.inMemoryAuthentication()
17-
.withUser("configUser")
18-
.password("configPassword")
19-
.roles("SYSTEM");
16+
auth.inMemoryAuthentication().withUser("configUser").password("configPassword").roles("SYSTEM");
2017
}
2118

2219
@Override
2320
protected void configure(HttpSecurity http) throws Exception {
2421
http
2522
.authorizeRequests()
2623
.anyRequest().hasRole("SYSTEM")
27-
.and()
28-
.httpBasic()
29-
.and()
30-
.csrf().disable();
24+
.and()
25+
.httpBasic()
26+
.and()
27+
.csrf()
28+
.disable();
3129
}
3230
}

‎spring-cloud/spring-cloud-bootstrap/discovery/src/main/java/com/baeldung/spring/cloud/bootstrap/discovery/SecurityConfig.java‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
1717

1818
@Autowired
1919
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
20-
auth.inMemoryAuthentication()
21-
.withUser("discUser")
22-
.password("discPassword")
23-
.roles("SYSTEM");
20+
auth.inMemoryAuthentication().withUser("discUser").password("discPassword").roles("SYSTEM");
2421
}
2522

2623
@Override
@@ -38,7 +35,8 @@ protected void configure(HttpSecurity http) throws Exception {
3835
.and()
3936
.httpBasic()
4037
.and()
41-
.csrf().disable();
38+
.csrf()
39+
.disable();
4240
}
4341

4442
@Configuration
@@ -59,10 +57,10 @@ public static class AdminSecurityConfig extends WebSecurityConfigurerAdapter {
5957
.authorizeRequests()
6058
.antMatchers(HttpMethod.GET, "/").hasRole("ADMIN")
6159
.antMatchers("/info","/health").authenticated()
62-
.antMatchers("/eureka/js/**", "/eureka/css/**", "/eureka/images/**", "/eureka/fonts/**").authenticated()
6360
.anyRequest().denyAll()
6461
.and()
65-
.csrf().disable();
62+
.csrf()
63+
.disable();
6664
}
6765
}
6866
}

‎spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/SecurityConfig.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
1515
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
1616
auth.inMemoryAuthentication()
1717
.withUser("user").password("password").roles("USER")
18-
.and()
18+
.and()
1919
.withUser("admin").password("admin").roles("ADMIN");
2020
}
2121

@@ -24,7 +24,7 @@ protected void configure(HttpSecurity http) throws Exception {
2424
http
2525
.authorizeRequests()
2626
.antMatchers("/resource/hello/cloud").permitAll()
27-
.antMatchers("/static/eureka/**").hasRole("ADMIN")
27+
.antMatchers("/eureka/**").hasRole("ADMIN")
2828
.anyRequest().authenticated()
2929
.and()
3030
.formLogin()
@@ -33,6 +33,7 @@ protected void configure(HttpSecurity http) throws Exception {
3333
.logout().permitAll()
3434
.logoutSuccessUrl("/resource/hello/cloud").permitAll()
3535
.and()
36-
.csrf().disable();
36+
.csrf()
37+
.disable();
3738
}
3839
}

‎spring-cloud/spring-cloud-bootstrap/resource/src/main/java/com/baeldung/spring/cloud/bootstrap/resource/SecurityConfig.java‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package com.baeldung.spring.cloud.bootstrap.resource;
22

33
import org.springframework.beans.factory.annotation.Autowired;
4-
import org.springframework.context.annotation.Bean;
54
import org.springframework.context.annotation.Configuration;
65
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
76
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
87
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
98
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
10-
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
119

1210
@EnableWebSecurity
1311
@Configuration
@@ -27,14 +25,10 @@ protected void configure(HttpSecurity http) throws Exception {
2725
.authorizeRequests()
2826
.antMatchers("/hello/cloud").permitAll()
2927
.antMatchers("/hello/user").hasAnyRole("USER", "ADMIN")
30-
.antMatchers("/hello/admin").hasAnyRole("ADMIN")
28+
.antMatchers("/hello/admin").hasRole("ADMIN")
3129
.anyRequest().authenticated()
3230
.and()
33-
.csrf().disable();
34-
}
35-
36-
@Bean
37-
public BCryptPasswordEncoder encoder() {
38-
return new BCryptPasswordEncoder(11);
31+
.csrf()
32+
.disable();
3933
}
4034
}

0 commit comments

Comments
 (0)