BAEL-315 Clean up some code formatting on the security configurations
This commit is contained in:
parent
2777df61a9
commit
c7551758d8
@ -13,10 +13,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
|
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
|
||||||
auth.inMemoryAuthentication()
|
auth.inMemoryAuthentication().withUser("configUser").password("configPassword").roles("SYSTEM");
|
||||||
.withUser("configUser")
|
|
||||||
.password("configPassword")
|
|
||||||
.roles("SYSTEM");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -24,9 +21,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
http
|
http
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.anyRequest().hasRole("SYSTEM")
|
.anyRequest().hasRole("SYSTEM")
|
||||||
.and()
|
.and()
|
||||||
.httpBasic()
|
.httpBasic()
|
||||||
.and()
|
.and()
|
||||||
.csrf().disable();
|
.csrf()
|
||||||
|
.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
|
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
|
||||||
auth.inMemoryAuthentication()
|
auth.inMemoryAuthentication().withUser("discUser").password("discPassword").roles("SYSTEM");
|
||||||
.withUser("discUser")
|
|
||||||
.password("discPassword")
|
|
||||||
.roles("SYSTEM");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -38,7 +35,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.and()
|
.and()
|
||||||
.httpBasic()
|
.httpBasic()
|
||||||
.and()
|
.and()
|
||||||
.csrf().disable();
|
.csrf()
|
||||||
|
.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ -59,10 +57,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers(HttpMethod.GET, "/").hasRole("ADMIN")
|
.antMatchers(HttpMethod.GET, "/").hasRole("ADMIN")
|
||||||
.antMatchers("/info","/health").authenticated()
|
.antMatchers("/info","/health").authenticated()
|
||||||
.antMatchers("/eureka/js/**", "/eureka/css/**", "/eureka/images/**", "/eureka/fonts/**").authenticated()
|
|
||||||
.anyRequest().denyAll()
|
.anyRequest().denyAll()
|
||||||
.and()
|
.and()
|
||||||
.csrf().disable();
|
.csrf()
|
||||||
|
.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
auth.inMemoryAuthentication()
|
auth.inMemoryAuthentication()
|
||||||
.withUser("user").password("password").roles("USER")
|
.withUser("user").password("password").roles("USER")
|
||||||
.and()
|
.and()
|
||||||
.withUser("admin").password("admin").roles("ADMIN");
|
.withUser("admin").password("admin").roles("ADMIN");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
http
|
http
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers("/resource/hello/cloud").permitAll()
|
.antMatchers("/resource/hello/cloud").permitAll()
|
||||||
.antMatchers("/static/eureka/**").hasRole("ADMIN")
|
.antMatchers("/eureka/**").hasRole("ADMIN")
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
.and()
|
.and()
|
||||||
.formLogin()
|
.formLogin()
|
||||||
@ -33,6 +33,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.logout().permitAll()
|
.logout().permitAll()
|
||||||
.logoutSuccessUrl("/resource/hello/cloud").permitAll()
|
.logoutSuccessUrl("/resource/hello/cloud").permitAll()
|
||||||
.and()
|
.and()
|
||||||
.csrf().disable();
|
.csrf()
|
||||||
|
.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package com.baeldung.spring.cloud.bootstrap.resource;
|
package com.baeldung.spring.cloud.bootstrap.resource;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||||
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.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@Configuration
|
@Configuration
|
||||||
@ -27,14 +25,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers("/hello/cloud").permitAll()
|
.antMatchers("/hello/cloud").permitAll()
|
||||||
.antMatchers("/hello/user").hasAnyRole("USER", "ADMIN")
|
.antMatchers("/hello/user").hasAnyRole("USER", "ADMIN")
|
||||||
.antMatchers("/hello/admin").hasAnyRole("ADMIN")
|
.antMatchers("/hello/admin").hasRole("ADMIN")
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
.and()
|
.and()
|
||||||
.csrf().disable();
|
.csrf()
|
||||||
}
|
.disable();
|
||||||
|
|
||||||
@Bean
|
|
||||||
public BCryptPasswordEncoder encoder() {
|
|
||||||
return new BCryptPasswordEncoder(11);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user