spring cloud : e-commerce(gateway) - spring cloud config(actuator refresh)
This commit is contained in:
@@ -23,8 +23,12 @@ ext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||||
|
|
||||||
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
|
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
|
||||||
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
|
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
|
||||||
|
implementation 'org.springframework.cloud:spring-cloud-starter-config'
|
||||||
|
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
|
||||||
|
|
||||||
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
|
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
|
||||||
implementation group: 'javax.xml.bind', name: 'jaxb-api'
|
implementation group: 'javax.xml.bind', name: 'jaxb-api'
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package com.example.apigatewayservice;
|
package com.example.apigatewayservice;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
|
||||||
|
import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class ApigatewayServiceApplication {
|
public class ApigatewayServiceApplication {
|
||||||
@@ -10,4 +13,8 @@ public class ApigatewayServiceApplication {
|
|||||||
SpringApplication.run(ApigatewayServiceApplication.class, args);
|
SpringApplication.run(ApigatewayServiceApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public HttpTraceRepository httpTraceRepository() {
|
||||||
|
return new InMemoryHttpTraceRepository();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.example.apigatewayservice.filter;
|
package com.example.apigatewayservice.filter;
|
||||||
|
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||||
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
||||||
@@ -41,6 +40,9 @@ public class AuthorizationHeaderFilter extends AbstractGatewayFilterFactory<Auth
|
|||||||
String authorizationHeader = request.getHeaders().get(HttpHeaders.AUTHORIZATION).get(0);
|
String authorizationHeader = request.getHeaders().get(HttpHeaders.AUTHORIZATION).get(0);
|
||||||
String jwt = authorizationHeader.replace("Bearer ", "");
|
String jwt = authorizationHeader.replace("Bearer ", "");
|
||||||
|
|
||||||
|
System.out.println("jwt = " + jwt);
|
||||||
|
System.out.println(env.getProperty("token.secret"));
|
||||||
|
|
||||||
if (!isJwtValid(jwt)) {
|
if (!isJwtValid(jwt)) {
|
||||||
return onError(exchange, "JWT token is not vaild", HttpStatus.UNAUTHORIZED);
|
return onError(exchange, "JWT token is not vaild", HttpStatus.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
@@ -65,7 +67,8 @@ public class AuthorizationHeaderFilter extends AbstractGatewayFilterFactory<Auth
|
|||||||
if (subject == null || subject.isEmpty()) {
|
if (subject == null || subject.isEmpty()) {
|
||||||
returnValue = false;
|
returnValue = false;
|
||||||
}
|
}
|
||||||
|
System.out.println(subject);
|
||||||
|
System.out.println(returnValue);
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,14 @@ spring:
|
|||||||
- RemoveRequestHeader=Cookie
|
- RemoveRequestHeader=Cookie
|
||||||
- RewritePath=/user-service/(?<segment>.*), /$\{segment}
|
- RewritePath=/user-service/(?<segment>.*), /$\{segment}
|
||||||
- AuthorizationHeaderFilter
|
- AuthorizationHeaderFilter
|
||||||
|
- id: user-service
|
||||||
|
uri: lb://USER-SERVICE
|
||||||
|
predicates:
|
||||||
|
- Path=/user-service/actuator/**
|
||||||
|
- Method=GET, POST
|
||||||
|
filters:
|
||||||
|
- RemoveRequestHeader=Cookie
|
||||||
|
- RewritePath=/user-service/(?<segment>.*), /$\{segment}
|
||||||
|
|
||||||
- id: first-service
|
- id: first-service
|
||||||
uri: lb://MY-FIRST-SERVICE
|
uri: lb://MY-FIRST-SERVICE
|
||||||
@@ -80,5 +88,11 @@ spring:
|
|||||||
preLogger: true
|
preLogger: true
|
||||||
postLogger: true
|
postLogger: true
|
||||||
|
|
||||||
token:
|
#token:
|
||||||
secret: user_token
|
# secret: user_token
|
||||||
|
|
||||||
|
management:
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: refresh, health, beans, httptrace
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
spring:
|
||||||
|
cloud:
|
||||||
|
config:
|
||||||
|
uri: http://127.0.0.1:8888
|
||||||
|
name: ecommerce
|
||||||
@@ -30,10 +30,10 @@ public class WebSecurity extends WebSecurityConfigurerAdapter {
|
|||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
http.csrf().disable().headers().frameOptions().disable();
|
http.csrf().disable().headers().frameOptions().disable();
|
||||||
|
|
||||||
// http.authorizeRequests().antMatchers("/users/**").permitAll();
|
http.authorizeRequests().antMatchers("/users/**").permitAll();
|
||||||
http.authorizeRequests().antMatchers("/actuator/**").permitAll();
|
http.authorizeRequests().antMatchers("/actuator/**").permitAll();
|
||||||
http.authorizeRequests().antMatchers("/**")
|
http.authorizeRequests().antMatchers("/**")
|
||||||
.hasIpAddress("127.0.0.1")
|
.hasIpAddress("192.168.219.178")
|
||||||
.and()
|
.and()
|
||||||
.addFilter(getAuthenticationFilter());
|
.addFilter(getAuthenticationFilter());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user