BAEL-315 Clean up some code formatting on the security configurations

This commit is contained in:
Tim Schimandle 2016-10-18 21:22:04 -06:00
parent 2777df61a9
commit c7551758d8
4 changed files with 18 additions and 27 deletions

View File

@ -13,10 +13,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
auth.inMemoryAuthentication()
.withUser("configUser")
.password("configPassword")
.roles("SYSTEM");
auth.inMemoryAuthentication().withUser("configUser").password("configPassword").roles("SYSTEM");
}
@Override
@ -24,9 +21,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
http
.authorizeRequests()
.anyRequest().hasRole("SYSTEM")
.and()
.httpBasic()
.and()
.csrf().disable();
.and()
.httpBasic()
.and()
.csrf()
.disable();
}
}

View File

@ -17,10 +17,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
auth.inMemoryAuthentication()
.withUser("discUser")
.password("discPassword")
.roles("SYSTEM");
auth.inMemoryAuthentication().withUser("discUser").password("discPassword").roles("SYSTEM");
}
@Override
@ -38,7 +35,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.and()
.httpBasic()
.and()
.csrf().disable();
.csrf()
.disable();
}
@Configuration
@ -59,10 +57,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/").hasRole("ADMIN")
.antMatchers("/info","/health").authenticated()
.antMatchers("/eureka/js/**", "/eureka/css/**", "/eureka/images/**", "/eureka/fonts/**").authenticated()
.anyRequest().denyAll()
.and()
.csrf().disable();
.csrf()
.disable();
}
}
}

View File

@ -15,7 +15,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user").password("password").roles("USER")
.and()
.and()
.withUser("admin").password("admin").roles("ADMIN");
}
@ -24,7 +24,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
http
.authorizeRequests()
.antMatchers("/resource/hello/cloud").permitAll()
.antMatchers("/static/eureka/**").hasRole("ADMIN")
.antMatchers("/eureka/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin()
@ -33,6 +33,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.logout().permitAll()
.logoutSuccessUrl("/resource/hello/cloud").permitAll()
.and()
.csrf().disable();
.csrf()
.disable();
}
}

View File

@ -1,13 +1,11 @@
package com.baeldung.spring.cloud.bootstrap.resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@EnableWebSecurity
@Configuration
@ -27,14 +25,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.authorizeRequests()
.antMatchers("/hello/cloud").permitAll()
.antMatchers("/hello/user").hasAnyRole("USER", "ADMIN")
.antMatchers("/hello/admin").hasAnyRole("ADMIN")
.antMatchers("/hello/admin").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.csrf().disable();
}
@Bean
public BCryptPasswordEncoder encoder() {
return new BCryptPasswordEncoder(11);
.csrf()
.disable();
}
}