Modify formatting.
This commit is contained in:
parent
66b618d99d
commit
bad9a35061
|
@ -7,7 +7,7 @@ import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
|
|||
@SpringBootApplication
|
||||
@EnableEurekaServer
|
||||
public class DiscoveryApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DiscoveryApplication.class, args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DiscoveryApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,52 +15,30 @@ import org.springframework.security.config.http.SessionCreationPolicy;
|
|||
@Order(1)
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
|
||||
auth.inMemoryAuthentication().withUser("discUser").password("discPassword").roles("SYSTEM");
|
||||
}
|
||||
|
||||
@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()
|
||||
.csrf()
|
||||
.disable();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
//no order tag means this is the last security filter to be evaluated
|
||||
public static class AdminSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.inMemoryAuthentication();
|
||||
@Autowired
|
||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.inMemoryAuthentication().withUser("discUser").password("discPassword").roles("SYSTEM");
|
||||
}
|
||||
|
||||
@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();
|
||||
@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()
|
||||
.csrf().disable();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
//no order tag means this is the last security filter to be evaluated
|
||||
public static class AdminSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.inMemoryAuthentication();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,23 +18,23 @@ import java.util.List;
|
|||
@EnableZuulProxy
|
||||
@EnableEurekaClient
|
||||
public class GatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GatewayApplication.class, args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GatewayApplication.class, args);
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
private List<RibbonClientSpecification> configurations = new ArrayList<>();
|
||||
@Autowired(required = false)
|
||||
private List<RibbonClientSpecification> configurations = new ArrayList<>();
|
||||
|
||||
@Bean
|
||||
@LoadBalanced RestTemplate restTemplate(){
|
||||
return new RestTemplate();
|
||||
}
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public SpringClientFactory springClientFactory() {
|
||||
SpringClientFactory factory = new SpringClientFactory();
|
||||
factory.setConfigurations(this.configurations);
|
||||
return factory;
|
||||
}
|
||||
@Bean
|
||||
public SpringClientFactory springClientFactory() {
|
||||
SpringClientFactory factory = new SpringClientFactory();
|
||||
factory.setConfigurations(this.configurations);
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,28 +11,14 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
|
|||
@Configuration
|
||||
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");
|
||||
}
|
||||
@Autowired
|
||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||
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();
|
||||
}
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,31 +11,31 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@EnableEurekaClient
|
||||
@RestController
|
||||
public class ResourceApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ResourceApplication.class, args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ResourceApplication.class, args);
|
||||
}
|
||||
|
||||
@Value("${resource.returnString}")
|
||||
private String returnString;
|
||||
@Value("${resource.returnString}")
|
||||
private String returnString;
|
||||
|
||||
@Value("${resource.user.returnString}")
|
||||
private String userReturnString;
|
||||
@Value("${resource.user.returnString}")
|
||||
private String userReturnString;
|
||||
|
||||
@Value("${resource.admin.returnString}")
|
||||
private String adminReturnString;
|
||||
@Value("${resource.admin.returnString}")
|
||||
private String adminReturnString;
|
||||
|
||||
@RequestMapping("/hello/cloud")
|
||||
public String getString() {
|
||||
return returnString;
|
||||
}
|
||||
@RequestMapping("/hello/cloud")
|
||||
public String getString() {
|
||||
return returnString;
|
||||
}
|
||||
|
||||
@RequestMapping("/hello/user")
|
||||
public String getUserString() {
|
||||
return userReturnString;
|
||||
}
|
||||
@RequestMapping("/hello/user")
|
||||
public String getUserString() {
|
||||
return userReturnString;
|
||||
}
|
||||
|
||||
@RequestMapping("/hello/admin")
|
||||
public String getAdminString() {
|
||||
return adminReturnString;
|
||||
}
|
||||
@RequestMapping("/hello/admin")
|
||||
public String getAdminString() {
|
||||
return adminReturnString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package com.baeldung.spring.cloud.bootstrap.resource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
|
@ -11,24 +9,8 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
|
|||
@Configuration
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
public void configureGlobal1(AuthenticationManagerBuilder auth) throws Exception {
|
||||
//try in memory auth with no users to support the case that this will allow for users that are logged in to go anywhere
|
||||
auth.inMemoryAuthentication();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue