Spring Security + Sleuth
This commit is contained in:
parent
63897863b3
commit
c2eced0d66
@ -61,6 +61,10 @@
|
|||||||
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
|
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-sleuth</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package com.clientui;
|
package com.clientui;
|
||||||
|
|
||||||
|
import brave.sampler.Sampler;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
import org.springframework.cloud.netflix.ribbon.RibbonClient;
|
import org.springframework.cloud.netflix.ribbon.RibbonClient;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableFeignClients("com.clientui")
|
@EnableFeignClients("com.clientui")
|
||||||
@ -14,4 +16,9 @@ public class ClientUiApplication {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ClientUiApplication.class, args);
|
SpringApplication.run(ClientUiApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Sampler defaultSampler(){
|
||||||
|
return Sampler.ALWAYS_SAMPLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,8 @@ import com.clientui.beans.ProductBean;
|
|||||||
import com.clientui.proxies.MicroserviceCommandeProxy;
|
import com.clientui.proxies.MicroserviceCommandeProxy;
|
||||||
import com.clientui.proxies.MicroservicePaiementProxy;
|
import com.clientui.proxies.MicroservicePaiementProxy;
|
||||||
import com.clientui.proxies.MicroserviceProduitsProxy;
|
import com.clientui.proxies.MicroserviceProduitsProxy;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -33,6 +35,8 @@ public class ClientController {
|
|||||||
private MicroservicePaiementProxy paiementProxy;
|
private MicroservicePaiementProxy paiementProxy;
|
||||||
|
|
||||||
|
|
||||||
|
Logger log = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Étape (1)
|
* Étape (1)
|
||||||
* Opération qui récupère la liste des produits et on les affichent dans la page d'accueil.
|
* 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("/")
|
@RequestMapping("/")
|
||||||
public String accueil(Model model){
|
public String accueil(Model model){
|
||||||
|
|
||||||
|
|
||||||
|
log.info("Envoi requête vers microservice-produits");
|
||||||
|
|
||||||
List<ProductBean> produits = ProduitsProxy.listeDesProduits();
|
List<ProductBean> produits = ProduitsProxy.listeDesProduits();
|
||||||
|
|
||||||
model.addAttribute("produits", produits);
|
model.addAttribute("produits", produits);
|
||||||
|
|
||||||
|
|
||||||
return "Accueil";
|
return "Accueil";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
server.port 8080
|
server.port: 8080
|
||||||
|
|
||||||
#Eureka
|
#Eureka
|
||||||
eureka.client.serviceUrl.defaultZone: http://localhost:9102/eureka/
|
eureka.client.serviceUrl.defaultZone: http://localhost:9102/eureka/
|
||||||
|
@ -2,4 +2,8 @@
|
|||||||
server.port 9004
|
server.port 9004
|
||||||
|
|
||||||
#Eureka
|
#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
|
@ -31,6 +31,11 @@
|
|||||||
<artifactId>spring-cloud-config-server</artifactId>
|
<artifactId>spring-cloud-config-server</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-sleuth</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
@ -35,6 +35,16 @@
|
|||||||
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
|
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
@ -59,6 +59,15 @@
|
|||||||
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
|
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package com.mproduits;
|
package com.mproduits;
|
||||||
|
|
||||||
|
import brave.sampler.Sampler;
|
||||||
import com.mproduits.configurations.ApplicationPropertiesConfiguration;
|
import com.mproduits.configurations.ApplicationPropertiesConfiguration;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableConfigurationProperties
|
@EnableConfigurationProperties
|
||||||
@ -14,4 +16,9 @@ public class MproduitsApplication {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(MproduitsApplication.class, args);
|
SpringApplication.run(MproduitsApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Sampler defaultSampler(){
|
||||||
|
return Sampler.ALWAYS_SAMPLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,8 @@ import com.mproduits.configurations.ApplicationPropertiesConfiguration;
|
|||||||
import com.mproduits.dao.ProductDao;
|
import com.mproduits.dao.ProductDao;
|
||||||
import com.mproduits.model.Product;
|
import com.mproduits.model.Product;
|
||||||
import com.mproduits.web.exceptions.ProductNotFoundException;
|
import com.mproduits.web.exceptions.ProductNotFoundException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -19,6 +21,9 @@ public class ProductController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
ProductDao productDao;
|
ProductDao productDao;
|
||||||
|
|
||||||
|
|
||||||
|
Logger log = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ApplicationPropertiesConfiguration appProperties;
|
ApplicationPropertiesConfiguration appProperties;
|
||||||
|
|
||||||
@ -32,6 +37,9 @@ public class ProductController {
|
|||||||
|
|
||||||
List<Product> listeLimitee = products.subList(0, appProperties.getLimitDeProduits());
|
List<Product> listeLimitee = products.subList(0, appProperties.getLimitDeProduits());
|
||||||
|
|
||||||
|
|
||||||
|
log.info("Récupération de la liste des produits");
|
||||||
|
|
||||||
return listeLimitee;
|
return listeLimitee;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,21 @@
|
|||||||
<artifactId>spring-cloud-starter-config</artifactId>
|
<artifactId>spring-cloud-starter-config</artifactId>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package com.mcommerce.zuulserver;
|
package com.mcommerce.zuulserver;
|
||||||
|
|
||||||
|
import brave.sampler.Sampler;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
|
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableZuulProxy
|
@EnableZuulProxy
|
||||||
@ -13,4 +15,6 @@ public class ZuulServerApplication {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ZuulServerApplication.class, args);
|
SpringApplication.run(ZuulServerApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user