Skip to content

Commit a66aeb1

Browse files
committed
BAEL-315 Change some security settings to allow discovery server operations. Copy static files from the eureka project to the zuul filter to display the discovery dashboard through the proxy.
1 parent 2a7b598 commit a66aeb1

1 file changed

Lines changed: 37 additions & 5 deletions

File tree

  • spring-cloud/spring-cloud-bootstrap/discovery/src/main/java/com/baeldung/spring/cloud/bootstrap/discovery

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

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
import org.springframework.beans.factory.annotation.Autowired;
44
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.core.annotation.Order;
56
import org.springframework.http.HttpMethod;
67
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
78
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
89
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
910
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
11+
import org.springframework.security.config.http.SessionCreationPolicy;
1012

1113
@Configuration
1214
@EnableWebSecurity
15+
@Order(1)
1316
public class SecurityConfig extends WebSecurityConfigurerAdapter {
1417

1518
@Autowired
@@ -23,14 +26,43 @@ public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
2326
@Override
2427
protected void configure(HttpSecurity http) throws Exception {
2528
http
29+
.sessionManagement()
30+
.sessionCreationPolicy(SessionCreationPolicy.ALWAYS)
31+
.and()
32+
.requestMatchers()
33+
.antMatchers("/eureka/**")
34+
.and()
2635
.authorizeRequests()
27-
.antMatchers("/eureka/js/**","/eureka/css/**","/eureka/images/**","/eureka/fonts/**").authenticated()
2836
.antMatchers("/eureka/**").hasRole("SYSTEM")
29-
.antMatchers(HttpMethod.GET, "/").hasRole("ADMIN")
30-
.anyRequest().authenticated()
31-
.and()
37+
.anyRequest().denyAll()
38+
.and()
39+
.httpBasic()
40+
.and()
41+
.csrf().disable();
42+
}
43+
44+
@Configuration
45+
//no order tag means this is the last security filter to be evaluated
46+
public static class AdminSecurityConfig extends WebSecurityConfigurerAdapter {
47+
48+
@Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
49+
auth.inMemoryAuthentication();
50+
}
51+
52+
@Override protected void configure(HttpSecurity http) throws Exception {
53+
http
54+
.sessionManagement()
55+
.sessionCreationPolicy(SessionCreationPolicy.NEVER)
56+
.and()
3257
.httpBasic()
33-
.and()
58+
.disable()
59+
.authorizeRequests()
60+
.antMatchers(HttpMethod.GET, "/").hasRole("ADMIN")
61+
.antMatchers("/info","/health").authenticated()
62+
.antMatchers("/eureka/js/**", "/eureka/css/**", "/eureka/images/**", "/eureka/fonts/**").authenticated()
63+
.anyRequest().denyAll()
64+
.and()
3465
.csrf().disable();
66+
}
3567
}
3668
}

0 commit comments

Comments
 (0)