Merged in feature/sarvendev (pull request #28)
Browse files- src/main/java/com/artandscience/gateway/gateway/api/GatewayRootController.java +22 -8
- src/main/java/com/artandscience/gateway/gateway/common/helper/SecurityHelper.java +4 -12
- src/main/java/com/artandscience/gateway/gateway/constant/HeaderConstant.java +4 -1
- src/main/java/com/artandscience/gateway/gateway/filter/AuthFilter.java +11 -7
- src/main/java/com/artandscience/gateway/gateway/model/GetUserResponse.java +2 -1
- src/main/resources/url-config/url-config.yml +4 -0
src/main/java/com/artandscience/gateway/gateway/api/GatewayRootController.java
CHANGED
|
@@ -1,21 +1,35 @@
|
|
| 1 |
package com.artandscience.gateway.gateway.api;
|
| 2 |
|
|
|
|
| 3 |
import org.springframework.http.ResponseEntity;
|
| 4 |
import org.springframework.web.bind.annotation.GetMapping;
|
| 5 |
import org.springframework.web.bind.annotation.RestController;
|
| 6 |
import reactor.core.publisher.Mono;
|
| 7 |
|
| 8 |
-
import java.util.Map;
|
| 9 |
-
|
| 10 |
@RestController
|
| 11 |
public class GatewayRootController {
|
| 12 |
|
| 13 |
-
@GetMapping("/")
|
| 14 |
-
public Mono<ResponseEntity<
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
@GetMapping("/favicon.ico")
|
|
|
|
| 1 |
package com.artandscience.gateway.gateway.api;
|
| 2 |
|
| 3 |
+
import org.springframework.http.MediaType;
|
| 4 |
import org.springframework.http.ResponseEntity;
|
| 5 |
import org.springframework.web.bind.annotation.GetMapping;
|
| 6 |
import org.springframework.web.bind.annotation.RestController;
|
| 7 |
import reactor.core.publisher.Mono;
|
| 8 |
|
|
|
|
|
|
|
| 9 |
@RestController
|
| 10 |
public class GatewayRootController {
|
| 11 |
|
| 12 |
+
@GetMapping(value = "/", produces = MediaType.TEXT_HTML_VALUE)
|
| 13 |
+
public Mono<ResponseEntity<String>> root() {
|
| 14 |
+
String html = """
|
| 15 |
+
<html>
|
| 16 |
+
<body>
|
| 17 |
+
<h3>Artandscience Gateway is running</h3>
|
| 18 |
+
<p>Status: UP</p>
|
| 19 |
+
</body>
|
| 20 |
+
</html>
|
| 21 |
+
""";
|
| 22 |
+
|
| 23 |
+
return Mono.just(ResponseEntity.ok()
|
| 24 |
+
.contentType(MediaType.TEXT_HTML)
|
| 25 |
+
.body(html));
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
@GetMapping(value = "/ping", produces = MediaType.TEXT_PLAIN_VALUE)
|
| 29 |
+
public Mono<ResponseEntity<String>> ping() {
|
| 30 |
+
return Mono.just(ResponseEntity.ok()
|
| 31 |
+
.contentType(MediaType.TEXT_PLAIN)
|
| 32 |
+
.body("gateway is running"));
|
| 33 |
}
|
| 34 |
|
| 35 |
@GetMapping("/favicon.ico")
|
src/main/java/com/artandscience/gateway/gateway/common/helper/SecurityHelper.java
CHANGED
|
@@ -3,30 +3,19 @@ package com.artandscience.gateway.gateway.common.helper;
|
|
| 3 |
import com.artandscience.gateway.gateway.constant.HeaderConstant;
|
| 4 |
import com.artandscience.gateway.gateway.model.GetUserResponse;
|
| 5 |
import lombok.extern.slf4j.Slf4j;
|
| 6 |
-
import org.springframework.http.HttpCookie;
|
| 7 |
import org.springframework.http.server.reactive.ServerHttpRequest;
|
| 8 |
import org.springframework.stereotype.Component;
|
| 9 |
import org.springframework.web.server.ServerWebExchange;
|
| 10 |
|
| 11 |
import java.util.Objects;
|
| 12 |
-
import java.util.Optional;
|
| 13 |
import java.util.stream.Collectors;
|
| 14 |
|
| 15 |
-
import static com.artandscience.gateway.gateway.constant.Constants.ART_SCIENCE_SESSION_ID;
|
| 16 |
import static com.artandscience.gateway.gateway.constant.Constants.BEARER;
|
| 17 |
|
| 18 |
@Component
|
| 19 |
@Slf4j
|
| 20 |
public class SecurityHelper {
|
| 21 |
|
| 22 |
-
public static String getSessionId(ServerWebExchange exchange) {
|
| 23 |
-
return Optional.ofNullable(exchange.getRequest()
|
| 24 |
-
.getCookies()
|
| 25 |
-
.getFirst(ART_SCIENCE_SESSION_ID))
|
| 26 |
-
.map(HttpCookie::getValue)
|
| 27 |
-
.orElse(null);
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
public static ServerHttpRequest getMutatedRequest(ServerWebExchange exchange,
|
| 31 |
String token,
|
| 32 |
String role,
|
|
@@ -37,15 +26,18 @@ public class SecurityHelper {
|
|
| 37 |
.header(HeaderConstant.HEADER_AUTHORIZATION, BEARER + token)
|
| 38 |
.header(HeaderConstant.HEADER_USER_ROLE, role != null ? role : "")
|
| 39 |
.header(HeaderConstant.HEADER_SESSION_ID, sessionId)
|
| 40 |
-
.header(HeaderConstant.HEADER_CUSTOMER_NAME, getUserResponse.
|
| 41 |
.header(HeaderConstant.HEADER_CUSTOMER_SURNAME, getUserResponse.getSurname())
|
| 42 |
.header(HeaderConstant.HEADER_CUSTOMER_NUMBER, getUserResponse.getCustomerNumber())
|
| 43 |
.header(HeaderConstant.HEADER_PHONE_NUMBER, getUserResponse.getPhoneNumber())
|
| 44 |
.header(HeaderConstant.HEADER_EMAIL, getUserResponse.getEmail())
|
|
|
|
|
|
|
| 45 |
.header(HeaderConstant.HEADER_PERMISSIONS, !Objects.isNull(getUserResponse.getPermissions()) ?
|
| 46 |
getUserResponse.getPermissions().stream()
|
| 47 |
.collect(Collectors.joining(",", "[", "]")) : "[]")
|
| 48 |
.header(HeaderConstant.HEADER_REQUEST_FLOW_ID, requestFlowId)
|
|
|
|
| 49 |
.build();
|
| 50 |
}
|
| 51 |
|
|
|
|
| 3 |
import com.artandscience.gateway.gateway.constant.HeaderConstant;
|
| 4 |
import com.artandscience.gateway.gateway.model.GetUserResponse;
|
| 5 |
import lombok.extern.slf4j.Slf4j;
|
|
|
|
| 6 |
import org.springframework.http.server.reactive.ServerHttpRequest;
|
| 7 |
import org.springframework.stereotype.Component;
|
| 8 |
import org.springframework.web.server.ServerWebExchange;
|
| 9 |
|
| 10 |
import java.util.Objects;
|
|
|
|
| 11 |
import java.util.stream.Collectors;
|
| 12 |
|
|
|
|
| 13 |
import static com.artandscience.gateway.gateway.constant.Constants.BEARER;
|
| 14 |
|
| 15 |
@Component
|
| 16 |
@Slf4j
|
| 17 |
public class SecurityHelper {
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
public static ServerHttpRequest getMutatedRequest(ServerWebExchange exchange,
|
| 20 |
String token,
|
| 21 |
String role,
|
|
|
|
| 26 |
.header(HeaderConstant.HEADER_AUTHORIZATION, BEARER + token)
|
| 27 |
.header(HeaderConstant.HEADER_USER_ROLE, role != null ? role : "")
|
| 28 |
.header(HeaderConstant.HEADER_SESSION_ID, sessionId)
|
| 29 |
+
.header(HeaderConstant.HEADER_CUSTOMER_NAME, getUserResponse.getName())
|
| 30 |
.header(HeaderConstant.HEADER_CUSTOMER_SURNAME, getUserResponse.getSurname())
|
| 31 |
.header(HeaderConstant.HEADER_CUSTOMER_NUMBER, getUserResponse.getCustomerNumber())
|
| 32 |
.header(HeaderConstant.HEADER_PHONE_NUMBER, getUserResponse.getPhoneNumber())
|
| 33 |
.header(HeaderConstant.HEADER_EMAIL, getUserResponse.getEmail())
|
| 34 |
+
.header(HeaderConstant.HEADER_BIRTHDATE, getUserResponse.getBirthday())
|
| 35 |
+
.header(HeaderConstant.HEADER_FIRST_LOGIN, getUserResponse.getIsFirstLogin())
|
| 36 |
.header(HeaderConstant.HEADER_PERMISSIONS, !Objects.isNull(getUserResponse.getPermissions()) ?
|
| 37 |
getUserResponse.getPermissions().stream()
|
| 38 |
.collect(Collectors.joining(",", "[", "]")) : "[]")
|
| 39 |
.header(HeaderConstant.HEADER_REQUEST_FLOW_ID, requestFlowId)
|
| 40 |
+
.header(HeaderConstant.HEADER_IS_ONLINE, "1")
|
| 41 |
.build();
|
| 42 |
}
|
| 43 |
|
src/main/java/com/artandscience/gateway/gateway/constant/HeaderConstant.java
CHANGED
|
@@ -7,7 +7,7 @@ public class HeaderConstant {
|
|
| 7 |
public static String HEADER_LANGUAGE = "x-language";
|
| 8 |
public static String HEADER_DEVICE_APP_NAME = "x-device-app-name";
|
| 9 |
public static String HEADER_DEVICE_APP_VERSION = "x-device-app-version";
|
| 10 |
-
public static String
|
| 11 |
public static String HEADER_SESSION_ID = "x-b3-session-id";
|
| 12 |
public static String HEADER_USER_ROLE = "x-user-role";
|
| 13 |
public static String HEADER_CORRELATION_ID = "x-correlation-id";
|
|
@@ -19,5 +19,8 @@ public class HeaderConstant {
|
|
| 19 |
public static String HEADER_AUTHORIZATION = "Authorization";
|
| 20 |
public static String HEADER_PERMISSIONS = "x-customer-permissions";
|
| 21 |
public static String HEADER_REQUEST_FLOW_ID = "x-request-flow-id";
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
}
|
|
|
|
| 7 |
public static String HEADER_LANGUAGE = "x-language";
|
| 8 |
public static String HEADER_DEVICE_APP_NAME = "x-device-app-name";
|
| 9 |
public static String HEADER_DEVICE_APP_VERSION = "x-device-app-version";
|
| 10 |
+
public static String HEADER_DEVICE_ID = "x-device-id";
|
| 11 |
public static String HEADER_SESSION_ID = "x-b3-session-id";
|
| 12 |
public static String HEADER_USER_ROLE = "x-user-role";
|
| 13 |
public static String HEADER_CORRELATION_ID = "x-correlation-id";
|
|
|
|
| 19 |
public static String HEADER_AUTHORIZATION = "Authorization";
|
| 20 |
public static String HEADER_PERMISSIONS = "x-customer-permissions";
|
| 21 |
public static String HEADER_REQUEST_FLOW_ID = "x-request-flow-id";
|
| 22 |
+
public static String HEADER_BIRTHDATE = "x-customer-birthdate";
|
| 23 |
+
public static String HEADER_FIRST_LOGIN = "x-customer-first-login";
|
| 24 |
+
public static String HEADER_IS_ONLINE = "x-customer-is-online";
|
| 25 |
|
| 26 |
}
|
src/main/java/com/artandscience/gateway/gateway/filter/AuthFilter.java
CHANGED
|
@@ -13,11 +13,15 @@ import lombok.RequiredArgsConstructor;
|
|
| 13 |
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
| 14 |
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
| 15 |
import org.springframework.core.Ordered;
|
|
|
|
| 16 |
import org.springframework.http.HttpStatus;
|
| 17 |
import org.springframework.http.server.reactive.ServerHttpRequest;
|
| 18 |
import org.springframework.stereotype.Component;
|
| 19 |
import org.springframework.web.server.ServerWebExchange;
|
| 20 |
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
|
|
| 21 |
import static com.artandscience.gateway.gateway.constant.Constants.URL_ATTR;
|
| 22 |
|
| 23 |
@Component
|
|
@@ -30,17 +34,21 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|
| 30 |
@Override
|
| 31 |
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
| 32 |
UrlMapping url = exchange.getAttribute(URL_ATTR);
|
|
|
|
| 33 |
|
| 34 |
if (!url.isTokenRequired()) {
|
|
|
|
|
|
|
| 35 |
String requestFlowId = providerFilter.filter(url, sessionService);
|
| 36 |
ServerHttpRequest mutatedRequest = exchange.getRequest()
|
| 37 |
.mutate()
|
|
|
|
| 38 |
.header(HeaderConstant.HEADER_REQUEST_FLOW_ID, requestFlowId)
|
| 39 |
.build();
|
| 40 |
return chain.filter(exchange.mutate().request(mutatedRequest).build());
|
| 41 |
}
|
| 42 |
|
| 43 |
-
String sessionId =
|
| 44 |
|
| 45 |
String jsonSession = sessionService.getSession(sessionId, String.class,true);
|
| 46 |
|
|
@@ -58,9 +66,9 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|
| 58 |
String role = (String) decodedToken.getClaims().get("role");
|
| 59 |
|
| 60 |
var user = loginSession.getGetUserResponse();
|
| 61 |
-
String requestFlowId = providerFilter.filter(url, sessionService);
|
| 62 |
|
| 63 |
-
ServerHttpRequest mutatedRequest = SecurityHelper.getMutatedRequest(exchange,token,role,sessionId, user,
|
| 64 |
return chain.filter(exchange.mutate().request(mutatedRequest).build());
|
| 65 |
} catch (FirebaseAuthException e) {
|
| 66 |
exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
|
|
@@ -69,10 +77,6 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|
| 69 |
|
| 70 |
}
|
| 71 |
|
| 72 |
-
private String getHeader(ServerHttpRequest request, String key) {
|
| 73 |
-
return request.getHeaders().getFirst(key);
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
@Override
|
| 77 |
public int getOrder() {
|
| 78 |
return -1;
|
|
|
|
| 13 |
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
| 14 |
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
| 15 |
import org.springframework.core.Ordered;
|
| 16 |
+
import org.springframework.http.HttpMethod;
|
| 17 |
import org.springframework.http.HttpStatus;
|
| 18 |
import org.springframework.http.server.reactive.ServerHttpRequest;
|
| 19 |
import org.springframework.stereotype.Component;
|
| 20 |
import org.springframework.web.server.ServerWebExchange;
|
| 21 |
import reactor.core.publisher.Mono;
|
| 22 |
+
|
| 23 |
+
import java.util.Objects;
|
| 24 |
+
|
| 25 |
import static com.artandscience.gateway.gateway.constant.Constants.URL_ATTR;
|
| 26 |
|
| 27 |
@Component
|
|
|
|
| 34 |
@Override
|
| 35 |
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
| 36 |
UrlMapping url = exchange.getAttribute(URL_ATTR);
|
| 37 |
+
String deviceId = exchange.getRequest().getHeaders().getFirst(HeaderConstant.HEADER_DEVICE_ID);
|
| 38 |
|
| 39 |
if (!url.isTokenRequired()) {
|
| 40 |
+
|
| 41 |
+
String sessionId = sessionService.getSession(deviceId,String.class,true);
|
| 42 |
String requestFlowId = providerFilter.filter(url, sessionService);
|
| 43 |
ServerHttpRequest mutatedRequest = exchange.getRequest()
|
| 44 |
.mutate()
|
| 45 |
+
.header(HeaderConstant.HEADER_IS_ONLINE, Objects.isNull(sessionId) ? "0" : "1")
|
| 46 |
.header(HeaderConstant.HEADER_REQUEST_FLOW_ID, requestFlowId)
|
| 47 |
.build();
|
| 48 |
return chain.filter(exchange.mutate().request(mutatedRequest).build());
|
| 49 |
}
|
| 50 |
|
| 51 |
+
String sessionId = sessionService.getSession(deviceId,String.class,true);
|
| 52 |
|
| 53 |
String jsonSession = sessionService.getSession(sessionId, String.class,true);
|
| 54 |
|
|
|
|
| 66 |
String role = (String) decodedToken.getClaims().get("role");
|
| 67 |
|
| 68 |
var user = loginSession.getGetUserResponse();
|
| 69 |
+
//String requestFlowId = providerFilter.filter(url, sessionService);
|
| 70 |
|
| 71 |
+
ServerHttpRequest mutatedRequest = SecurityHelper.getMutatedRequest(exchange,token,role,sessionId, user, "");
|
| 72 |
return chain.filter(exchange.mutate().request(mutatedRequest).build());
|
| 73 |
} catch (FirebaseAuthException e) {
|
| 74 |
exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
|
|
|
|
| 77 |
|
| 78 |
}
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
@Override
|
| 81 |
public int getOrder() {
|
| 82 |
return -1;
|
src/main/java/com/artandscience/gateway/gateway/model/GetUserResponse.java
CHANGED
|
@@ -24,5 +24,6 @@ public class GetUserResponse implements Serializable {
|
|
| 24 |
private String email;
|
| 25 |
private String customerNumber;
|
| 26 |
private List<String> permissions;
|
| 27 |
-
|
|
|
|
| 28 |
}
|
|
|
|
| 24 |
private String email;
|
| 25 |
private String customerNumber;
|
| 26 |
private List<String> permissions;
|
| 27 |
+
private String birthday;
|
| 28 |
+
private String isFirstLogin;
|
| 29 |
}
|
src/main/resources/url-config/url-config.yml
CHANGED
|
@@ -33,6 +33,10 @@ services:
|
|
| 33 |
tokenRequired: true
|
| 34 |
scopes: diamond
|
| 35 |
utility-service:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
- path: /utility-service/api/v1/menu/getMenuByRole
|
| 37 |
method: POST
|
| 38 |
tokenRequired: true
|
|
|
|
| 33 |
tokenRequired: true
|
| 34 |
scopes: diamond
|
| 35 |
utility-service:
|
| 36 |
+
- path: /utility-service/api/v1/main/lead-message-campaign
|
| 37 |
+
method: POST
|
| 38 |
+
tokenRequired: true
|
| 39 |
+
scopes: user,admin
|
| 40 |
- path: /utility-service/api/v1/menu/getMenuByRole
|
| 41 |
method: POST
|
| 42 |
tokenRequired: true
|