perbaikan jika static token tidak ada

This commit is contained in:
Wanda 2024-11-19 07:28:16 +07:00
parent b925d10f57
commit e927687e59
3 changed files with 17 additions and 10 deletions

@ -51,7 +51,9 @@ public class HttpClientService {
String authorizationHeader = request.headers().header("Authorization").get(0); String authorizationHeader = request.headers().header("Authorization").get(0);
String token = authorizationHeader.substring(7); String token = authorizationHeader.substring(7);
String staticToken = jwtService.extractStaticToken(token); String staticToken = jwtService.extractStaticToken(token);
boundRequestBuilder.addHeader("token", staticToken); if (!staticToken.equals("admin")) {
boundRequestBuilder.addHeader("token", staticToken);
}
} }
Future<Response> whenResponse = boundRequestBuilder Future<Response> whenResponse = boundRequestBuilder
.execute(); .execute();

@ -50,11 +50,16 @@ public class JwtService {
String responseBody = response.getResponseBody(); String responseBody = response.getResponseBody();
Gson gson = new Gson(); Gson gson = new Gson();
StaticToken staticToken = gson.fromJson(responseBody, StaticToken.class); StaticToken staticToken = gson.fromJson(responseBody, StaticToken.class);
claims.put("token", staticToken.getToken()); if (staticToken != null) {
claims.put("token", staticToken.getToken());
} else {
claims.put("token", "admin");
}
} catch (IOException | ExecutionException | InterruptedException e) { } catch (IOException | ExecutionException | InterruptedException e) {
claims.put("token", "admin");
log.error("error get token", e); log.error("error get token", e);
} }
log.info("here");
return createToken(claims, user.getUsername()); return createToken(claims, user.getUsername());
} }

@ -4,12 +4,12 @@ server:
spring: spring:
datasource: datasource:
#url: jdbc:oracle:thin:@//10.216.100.100:1521/pdbsoadev url: jdbc:oracle:thin:@//10.216.100.100:1521/pdbsoadev
url: jdbc:oracle:thin:@localhost:1521:oracle #url: jdbc:oracle:thin:@localhost:1521:oracle
#username: gateway
username: gateway username: gateway
#password: welcome1 #username: gateway
password: gateway password: welcome1
#password: gateway
cloud: cloud:
gateway: gateway:
mvc: mvc:
@ -26,8 +26,8 @@ spring:
app: app:
gateway: gateway:
remote-servers: remote-servers:
#pan: http://10.216.99.101:8002 span: http://10.216.99.101:8002
span: https://672fbf9066e42ceaf15e9a9b.mockapi.io #span: https://672fbf9066e42ceaf15e9a9b.mockapi.io
users: http://localhost:8989 users: http://localhost:8989
#users: http://localhost:8779 #users: http://localhost:8779
token: http://localhost:8787 token: http://localhost:8787