BAEL-315 adding configuration for security on the config and discovery servers.

This commit is contained in:
Tim Schimandle 2016-10-03 13:01:01 -06:00
parent 66dfb6fd37
commit 798e72a121
11 changed files with 72 additions and 5 deletions

View File

@ -3,6 +3,6 @@ server.port=8082
eureka.instance.hostname=localhost
eureka.client.serviceUrl.defaultZone=http://localhost:8082/eureka/
eureka.client.serviceUrl.defaultZone=http://disc_discUser:discPassword@localhost:8082/eureka/
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

View File

@ -3,7 +3,7 @@ server.port=8080
eureka.client.region = default
eureka.client.registryFetchIntervalSeconds = 5
eureka.client.serviceUrl.defaultZone=http://localhost:8082/eureka/
eureka.client.serviceUrl.defaultZone=http://disc_gatewayUser:gatewayPassword@localhost:8082/eureka/
zuul.routes.resource.path=/resource/**
hystrix.command.resource.execution.isolation.thread.timeoutInMilliseconds: 5000

View File

@ -5,4 +5,4 @@ resource.returnString=hello cloud
eureka.client.region = default
eureka.client.registryFetchIntervalSeconds = 5
eureka.client.serviceUrl.defaultZone=http://localhost:8082/eureka/
eureka.client.serviceUrl.defaultZone=http://disc_resourceUser:resourcePassword@localhost:8082/eureka/

View File

@ -28,6 +28,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<dependencyManagement>

View File

@ -0,0 +1,25 @@
package com.baeldung.spring.cloud.integration.config;
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.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
auth.inMemoryAuthentication()
.withUser("config_discUser")
.password("discPassword")
.and()
.withUser("config_gatewayUser")
.password("gatewayPassword")
.and()
.withUser("config_resourceUser")
.password("resourcePassword");
}
}

View File

@ -5,4 +5,4 @@ spring.cloud.config.server.git.uri=file:///${user.home}/application-config
eureka.client.region = default
eureka.client.registryFetchIntervalSeconds = 5
eureka.client.serviceUrl.defaultZone=http://localhost:8082/eureka
eureka.client.serviceUrl.defaultZone=disc_configUser:configPassword@http://localhost:8082/eureka/

View File

@ -28,6 +28,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<dependencyManagement>

View File

@ -0,0 +1,28 @@
package com.baeldung.spring.cloud.integration.discovery;
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.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
auth.inMemoryAuthentication()
.withUser("disc_configUser")
.password("configPassword")
.and()
.withUser("disc_discUser")
.password("discPassword")
.and()
.withUser("disc_gatewayUser")
.password("gatewayPassword")
.and()
.withUser("disc_resourceUser")
.password("resourcePassword");
}
}

View File

@ -1,2 +1,4 @@
spring.cloud.config.name=discovery
spring.cloud.config.uri=http://localhost:8081
spring.cloud.config.uri=http://localhost:8081
spring.cloud.config.username=config_discUser
spring.cloud.config.password=discPassword

View File

@ -1,5 +1,7 @@
spring.cloud.config.name=gateway
spring.cloud.config.discovery.service-id=config
spring.cloud.config.discovery.enabled=true
spring.cloud.config.username=config_gatewayUser
spring.cloud.config.password=gatewayPassword
eureka.client.serviceUrl.defaultZone=http://localhost:8082/eureka/

View File

@ -1,5 +1,7 @@
spring.cloud.config.name=resource
spring.cloud.config.discovery.service-id=config
spring.cloud.config.discovery.enabled=true
spring.cloud.config.username=config_resourceUser
spring.cloud.config.password=resourcePassword
eureka.client.serviceUrl.defaultZone=http://localhost:8082/eureka/