spring cloud : e-commerce(gateway) - spring cloud config(actuator refresh)
This commit is contained in:
@@ -23,8 +23,12 @@ ext {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||
|
||||
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-config'
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
|
||||
|
||||
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
|
||||
implementation group: 'javax.xml.bind', name: 'jaxb-api'
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.example.apigatewayservice;
|
||||
|
||||
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.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ApigatewayServiceApplication {
|
||||
@@ -10,4 +13,8 @@ public class ApigatewayServiceApplication {
|
||||
SpringApplication.run(ApigatewayServiceApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HttpTraceRepository httpTraceRepository() {
|
||||
return new InMemoryHttpTraceRepository();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.example.apigatewayservice.filter;
|
||||
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
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 jwt = authorizationHeader.replace("Bearer ", "");
|
||||
|
||||
System.out.println("jwt = " + jwt);
|
||||
System.out.println(env.getProperty("token.secret"));
|
||||
|
||||
if (!isJwtValid(jwt)) {
|
||||
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()) {
|
||||
returnValue = false;
|
||||
}
|
||||
|
||||
System.out.println(subject);
|
||||
System.out.println(returnValue);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,14 @@ spring:
|
||||
- RemoveRequestHeader=Cookie
|
||||
- RewritePath=/user-service/(?<segment>.*), /$\{segment}
|
||||
- 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
|
||||
uri: lb://MY-FIRST-SERVICE
|
||||
@@ -80,5 +88,11 @@ spring:
|
||||
preLogger: true
|
||||
postLogger: true
|
||||
|
||||
token:
|
||||
secret: user_token
|
||||
#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 {
|
||||
http.csrf().disable().headers().frameOptions().disable();
|
||||
|
||||
// http.authorizeRequests().antMatchers("/users/**").permitAll();
|
||||
http.authorizeRequests().antMatchers("/users/**").permitAll();
|
||||
http.authorizeRequests().antMatchers("/actuator/**").permitAll();
|
||||
http.authorizeRequests().antMatchers("/**")
|
||||
.hasIpAddress("127.0.0.1")
|
||||
.hasIpAddress("192.168.219.178")
|
||||
.and()
|
||||
.addFilter(getAuthenticationFilter());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user