Spring Security + Sleuth

This commit is contained in:
TestAccountsUser 2018-03-23 01:54:37 +01:00
parent 63897863b3
commit c2eced0d66
16 changed files with 140 additions and 2 deletions

View File

@ -61,6 +61,10 @@
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>

View File

@ -1,10 +1,12 @@
package com.clientui;
import brave.sampler.Sampler;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableFeignClients("com.clientui")
@ -14,4 +16,9 @@ public class ClientUiApplication {
public static void main(String[] args) {
SpringApplication.run(ClientUiApplication.class, args);
}
@Bean
public Sampler defaultSampler(){
return Sampler.ALWAYS_SAMPLE;
}
}

View File

@ -0,0 +1,15 @@
package com.clientui.configuration;
import feign.auth.BasicAuthRequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FeignConfig {
@Bean
public BasicAuthRequestInterceptor mBasicAuthRequestInterceptor(){
return new BasicAuthRequestInterceptor("utilisateur", "mdp");
}
}

View File

@ -0,0 +1,14 @@
package com.clientui.configuration;
import brave.sampler.Sampler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SleuthConfig {
public Sampler defaultSampler(){
return Sampler.ALWAYS_SAMPLE;
}
}

View File

@ -6,6 +6,8 @@ import com.clientui.beans.ProductBean;
import com.clientui.proxies.MicroserviceCommandeProxy;
import com.clientui.proxies.MicroservicePaiementProxy;
import com.clientui.proxies.MicroserviceProduitsProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -33,6 +35,8 @@ public class ClientController {
private MicroservicePaiementProxy paiementProxy;
Logger log = LoggerFactory.getLogger(this.getClass());
/*
* Étape (1)
* Opération qui récupère la liste des produits et on les affichent dans la page d'accueil.
@ -42,10 +46,14 @@ public class ClientController {
@RequestMapping("/")
public String accueil(Model model){
log.info("Envoi requête vers microservice-produits");
List<ProductBean> produits = ProduitsProxy.listeDesProduits();
model.addAttribute("produits", produits);
return "Accueil";
}

View File

@ -1,5 +1,5 @@
server.port 8080
server.port: 8080
#Eureka
eureka.client.serviceUrl.defaultZone: http://localhost:9102/eureka/

View File

@ -2,4 +2,8 @@
server.port 9004
#Eureka
eureka.client.serviceUrl.defaultZone: http://localhost:9102/eureka/
eureka.client.serviceUrl.defaultZone: http://localhost:9102/eureka/
#Spring Security
spring.security.user.name=utilisateur
spring.security.user.password=mdp

View File

@ -31,6 +31,11 @@
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@ -35,6 +35,16 @@
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@ -59,6 +59,15 @@
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>

View File

@ -1,10 +1,12 @@
package com.mproduits;
import brave.sampler.Sampler;
import com.mproduits.configurations.ApplicationPropertiesConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableConfigurationProperties
@ -14,4 +16,9 @@ public class MproduitsApplication {
public static void main(String[] args) {
SpringApplication.run(MproduitsApplication.class, args);
}
@Bean
public Sampler defaultSampler(){
return Sampler.ALWAYS_SAMPLE;
}
}

View File

@ -0,0 +1,14 @@
package com.mproduits.configurations;
import brave.sampler.Sampler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SleuthConfig {
public Sampler defaultSampler(){
return Sampler.ALWAYS_SAMPLE;
}
}

View File

@ -4,6 +4,8 @@ import com.mproduits.configurations.ApplicationPropertiesConfiguration;
import com.mproduits.dao.ProductDao;
import com.mproduits.model.Product;
import com.mproduits.web.exceptions.ProductNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
@ -19,6 +21,9 @@ public class ProductController {
@Autowired
ProductDao productDao;
Logger log = LoggerFactory.getLogger(this.getClass());
@Autowired
ApplicationPropertiesConfiguration appProperties;
@ -32,6 +37,9 @@ public class ProductController {
List<Product> listeLimitee = products.subList(0, appProperties.getLimitDeProduits());
log.info("Récupération de la liste des produits");
return listeLimitee;
}

View File

@ -40,6 +40,21 @@
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@ -1,9 +1,11 @@
package com.mcommerce.zuulserver;
import brave.sampler.Sampler;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableZuulProxy
@ -13,4 +15,6 @@ public class ZuulServerApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulServerApplication.class, args);
}
}

View File

@ -0,0 +1,14 @@
package com.mcommerce.zuulserver.configuration;
import brave.sampler.Sampler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SleuthConfig {
public Sampler defaultSampler(){
return Sampler.ALWAYS_SAMPLE;
}
}