Merged in release/dev (pull request #49)
Browse files- src/main/java/com/artandscience/security/common/base/model/RequestHeader.java +1 -1
- src/main/java/com/artandscience/security/common/constants/HeaderConstant.java +1 -1
- src/main/java/com/artandscience/security/common/interceptor/TransactionFilter.java +2 -2
- src/main/java/com/artandscience/security/common/service/SessionService.java +4 -0
- src/main/java/com/artandscience/security/common/service/impl/SessionServiceImpl.java +18 -0
- src/main/java/com/artandscience/security/common/utils/DateUtil.java +27 -0
- src/main/java/com/artandscience/security/configuration/SecurityConfig.java +28 -2
- src/main/java/com/artandscience/security/controller/FcmTokenController.java +0 -10
- src/main/java/com/artandscience/security/controller/OnlineStatusController.java +28 -0
- src/main/java/com/artandscience/security/dao/entity/CustomerFcm.java +0 -1
- src/main/java/com/artandscience/security/dao/entity/CustomerOnlineStatus.java +22 -0
- src/main/java/com/artandscience/security/dao/entity/Users.java +4 -2
- src/main/java/com/artandscience/security/dao/repository/CustomerFcmRepository.java +2 -3
- src/main/java/com/artandscience/security/dao/repository/CustomerOnlineStatusRepository.java +17 -0
- src/main/java/com/artandscience/security/dao/repository/UserRepository.java +3 -0
- src/main/java/com/artandscience/security/domain/model/input/{GetOnlineStatusInput.java → OnlineStatusInput.java} +5 -1
- src/main/java/com/artandscience/security/domain/model/input/RegisterInput.java +2 -0
- src/main/java/com/artandscience/security/domain/model/input/{UpdateOnlineStatusInput.java → SaveOnlineStatusInput.java} +6 -2
- src/main/java/com/artandscience/security/domain/model/input/SetFcmTokenInput.java +0 -1
- src/main/java/com/artandscience/security/domain/model/input/UserInput.java +3 -0
- src/main/java/com/artandscience/security/domain/model/output/GetUserOutput.java +5 -0
- src/main/java/com/artandscience/security/domain/model/output/{GetOnlineStatusOutput.java → OnlineStatusOutput.java} +6 -7
- src/main/java/com/artandscience/security/domain/request/{GetOnlineStatusRequest.java → OnlineStatusRequest.java} +4 -4
- src/main/java/com/artandscience/security/domain/request/SaveOnlineStatusRequest.java +15 -0
- src/main/java/com/artandscience/security/domain/request/SetFcmTokenRequest.java +0 -2
- src/main/java/com/artandscience/security/domain/response/GetUserResponse.java +2 -0
- src/main/java/com/artandscience/security/domain/response/{GetOnlineStatusResponse.java → OnlineStatusResponse.java} +2 -4
- src/main/java/com/artandscience/security/domain/service/FcmTokenService.java +0 -4
- src/main/java/com/artandscience/security/domain/service/OnlineStatusService.java +13 -0
- src/main/java/com/artandscience/security/domain/service/base/UserService.java +3 -1
- src/main/java/com/artandscience/security/domain/service/impl/ArtAndScienceAuthServiceImpl.java +26 -8
- src/main/java/com/artandscience/security/domain/service/impl/ArtAndScienceUserServiceImpl.java +22 -2
- src/main/java/com/artandscience/security/domain/service/impl/BackOfficeUserServiceImpl.java +7 -1
- src/main/java/com/artandscience/security/domain/service/impl/FcmTokenServiceImpl.java +7 -21
- src/main/java/com/artandscience/security/domain/service/impl/OnlineStatusServiceImpl.java +58 -0
- src/main/java/com/artandscience/security/domain/util/CookieUtil.java +0 -41
src/main/java/com/artandscience/security/common/base/model/RequestHeader.java
CHANGED
|
@@ -21,7 +21,7 @@ public class RequestHeader {
|
|
| 21 |
private String customerNumber;
|
| 22 |
private String chanel;
|
| 23 |
private String email;
|
| 24 |
-
private String
|
| 25 |
private String flowRequestId;
|
| 26 |
|
| 27 |
}
|
|
|
|
| 21 |
private String customerNumber;
|
| 22 |
private String chanel;
|
| 23 |
private String email;
|
| 24 |
+
private String deviceId;
|
| 25 |
private String flowRequestId;
|
| 26 |
|
| 27 |
}
|
src/main/java/com/artandscience/security/common/constants/HeaderConstant.java
CHANGED
|
@@ -20,7 +20,7 @@ public class HeaderConstant {
|
|
| 20 |
public static String HEADER_CUSTOMER_NUMBER = "x-customer-number";
|
| 21 |
public static String HEADER_CHANEL = "x-customer-chanel";
|
| 22 |
public static String HEADER_EMAIL = "x-email";
|
| 23 |
-
public static String
|
| 24 |
public static String HEADER_REQUEST_FLOW_ID = "x-request-flow-id";
|
| 25 |
|
| 26 |
}
|
|
|
|
| 20 |
public static String HEADER_CUSTOMER_NUMBER = "x-customer-number";
|
| 21 |
public static String HEADER_CHANEL = "x-customer-chanel";
|
| 22 |
public static String HEADER_EMAIL = "x-email";
|
| 23 |
+
public static String HEADER_DEVICE_ID = "x-device-id";
|
| 24 |
public static String HEADER_REQUEST_FLOW_ID = "x-request-flow-id";
|
| 25 |
|
| 26 |
}
|
src/main/java/com/artandscience/security/common/interceptor/TransactionFilter.java
CHANGED
|
@@ -29,7 +29,7 @@ import static com.artandscience.security.common.constants.HeaderConstant.HEADER_
|
|
| 29 |
import static com.artandscience.security.common.constants.HeaderConstant.HEADER_CUSTOMER_NUMBER;
|
| 30 |
import static com.artandscience.security.common.constants.HeaderConstant.HEADER_CHANEL;
|
| 31 |
import static com.artandscience.security.common.constants.HeaderConstant.HEADER_EMAIL;
|
| 32 |
-
import static com.artandscience.security.common.constants.HeaderConstant.
|
| 33 |
import static com.artandscience.security.common.constants.HeaderConstant.HEADER_REQUEST_FLOW_ID;
|
| 34 |
|
| 35 |
|
|
@@ -72,7 +72,7 @@ public class TransactionFilter extends OncePerRequestFilter {
|
|
| 72 |
.customerNumber(request.getHeader(HEADER_CUSTOMER_NUMBER))
|
| 73 |
.chanel(request.getHeader(HEADER_CHANEL))
|
| 74 |
.email(request.getHeader(HEADER_EMAIL))
|
| 75 |
-
.
|
| 76 |
.flowRequestId(request.getHeader(HEADER_REQUEST_FLOW_ID))
|
| 77 |
.build();
|
| 78 |
}
|
|
|
|
| 29 |
import static com.artandscience.security.common.constants.HeaderConstant.HEADER_CUSTOMER_NUMBER;
|
| 30 |
import static com.artandscience.security.common.constants.HeaderConstant.HEADER_CHANEL;
|
| 31 |
import static com.artandscience.security.common.constants.HeaderConstant.HEADER_EMAIL;
|
| 32 |
+
import static com.artandscience.security.common.constants.HeaderConstant.HEADER_DEVICE_ID;
|
| 33 |
import static com.artandscience.security.common.constants.HeaderConstant.HEADER_REQUEST_FLOW_ID;
|
| 34 |
|
| 35 |
|
|
|
|
| 72 |
.customerNumber(request.getHeader(HEADER_CUSTOMER_NUMBER))
|
| 73 |
.chanel(request.getHeader(HEADER_CHANEL))
|
| 74 |
.email(request.getHeader(HEADER_EMAIL))
|
| 75 |
+
.deviceId(request.getHeader(HEADER_DEVICE_ID))
|
| 76 |
.flowRequestId(request.getHeader(HEADER_REQUEST_FLOW_ID))
|
| 77 |
.build();
|
| 78 |
}
|
src/main/java/com/artandscience/security/common/service/SessionService.java
CHANGED
|
@@ -4,6 +4,8 @@ import java.util.concurrent.TimeUnit;
|
|
| 4 |
|
| 5 |
public interface SessionService {
|
| 6 |
|
|
|
|
|
|
|
| 7 |
<T> void setSession(String sessionKey, String exTime, T object);
|
| 8 |
|
| 9 |
<T> void setSessionByKey(String key, T object, boolean withoutSession);
|
|
@@ -14,4 +16,6 @@ public interface SessionService {
|
|
| 14 |
|
| 15 |
void removeSession(String sessionKey, boolean isKey, boolean withoutSession );
|
| 16 |
|
|
|
|
|
|
|
| 17 |
}
|
|
|
|
| 4 |
|
| 5 |
public interface SessionService {
|
| 6 |
|
| 7 |
+
<T> void setSessionByDeviceId(T object);
|
| 8 |
+
|
| 9 |
<T> void setSession(String sessionKey, String exTime, T object);
|
| 10 |
|
| 11 |
<T> void setSessionByKey(String key, T object, boolean withoutSession);
|
|
|
|
| 16 |
|
| 17 |
void removeSession(String sessionKey, boolean isKey, boolean withoutSession );
|
| 18 |
|
| 19 |
+
void removeSessionByDeviceId();
|
| 20 |
+
|
| 21 |
}
|
src/main/java/com/artandscience/security/common/service/impl/SessionServiceImpl.java
CHANGED
|
@@ -26,6 +26,12 @@ public class SessionServiceImpl implements SessionService {
|
|
| 26 |
@Value("${spring.data.redis.session-expire-time}")
|
| 27 |
private String sessionExpireTime;
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
@Override
|
| 30 |
public <T> void setSession(String sessionKey, String exTime, T object) {
|
| 31 |
String key = !Objects.isNull(sessionKey) ? sessionKey : requestHeaderScope.getRequestHeader().getSessionId();
|
|
@@ -94,4 +100,16 @@ public class SessionServiceImpl implements SessionService {
|
|
| 94 |
throw new SessionException(SessionErrorType.SESSION_NOT_FOUND);
|
| 95 |
}
|
| 96 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}
|
|
|
|
| 26 |
@Value("${spring.data.redis.session-expire-time}")
|
| 27 |
private String sessionExpireTime;
|
| 28 |
|
| 29 |
+
@Override
|
| 30 |
+
public <T> void setSessionByDeviceId(T object) {
|
| 31 |
+
redisUtil.putValue(requestHeaderScope.getRequestHeader().getDeviceId(),
|
| 32 |
+
object,Integer.parseInt(sessionExpireTime), TimeUnit.MINUTES);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
@Override
|
| 36 |
public <T> void setSession(String sessionKey, String exTime, T object) {
|
| 37 |
String key = !Objects.isNull(sessionKey) ? sessionKey : requestHeaderScope.getRequestHeader().getSessionId();
|
|
|
|
| 100 |
throw new SessionException(SessionErrorType.SESSION_NOT_FOUND);
|
| 101 |
}
|
| 102 |
}
|
| 103 |
+
|
| 104 |
+
@Override
|
| 105 |
+
public void removeSessionByDeviceId() {
|
| 106 |
+
String deviceId = requestHeaderScope.getRequestHeader().getDeviceId();
|
| 107 |
+
|
| 108 |
+
try {
|
| 109 |
+
redisUtil.removeValue(deviceId);
|
| 110 |
+
} catch (Exception e) {
|
| 111 |
+
log.error("SessionService remove object is null for key: " + deviceId);
|
| 112 |
+
throw new SessionException(SessionErrorType.SESSION_NOT_FOUND);
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
}
|
src/main/java/com/artandscience/security/common/utils/DateUtil.java
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.security.common.utils;
|
| 2 |
+
|
| 3 |
+
import java.time.LocalDate;
|
| 4 |
+
import java.time.format.DateTimeFormatter;
|
| 5 |
+
|
| 6 |
+
public abstract class DateUtil {
|
| 7 |
+
|
| 8 |
+
private static final DateTimeFormatter FORMATTER = DateTimeFormatter
|
| 9 |
+
.ofPattern("dd.MM.yyyy");
|
| 10 |
+
|
| 11 |
+
public static String localDateToString(LocalDate date) {
|
| 12 |
+
if (date == null) {
|
| 13 |
+
return null;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
return date.format(FORMATTER);
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
public static LocalDate stringToLocalDate(String date) {
|
| 20 |
+
if (date == null || date.isBlank()) {
|
| 21 |
+
return null;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
return LocalDate.parse(date, FORMATTER);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
}
|
src/main/java/com/artandscience/security/configuration/SecurityConfig.java
CHANGED
|
@@ -2,6 +2,8 @@ package com.artandscience.security.configuration;
|
|
| 2 |
|
| 3 |
import org.springframework.context.annotation.Bean;
|
| 4 |
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
| 5 |
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
| 6 |
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
| 7 |
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
|
@@ -13,11 +15,35 @@ public class SecurityConfig {
|
|
| 13 |
|
| 14 |
@Bean
|
| 15 |
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
| 16 |
-
http
|
|
|
|
|
|
|
| 17 |
.authorizeHttpRequests(auth -> auth
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
.anyRequest().authenticated()
|
| 20 |
);
|
|
|
|
| 21 |
return http.build();
|
| 22 |
}
|
| 23 |
|
|
|
|
| 2 |
|
| 3 |
import org.springframework.context.annotation.Bean;
|
| 4 |
import org.springframework.context.annotation.Configuration;
|
| 5 |
+
import org.springframework.http.HttpMethod;
|
| 6 |
+
import org.springframework.security.config.Customizer;
|
| 7 |
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
| 8 |
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
| 9 |
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
|
|
|
| 15 |
|
| 16 |
@Bean
|
| 17 |
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
| 18 |
+
http
|
| 19 |
+
.cors(Customizer.withDefaults())
|
| 20 |
+
.csrf(AbstractHttpConfigurer::disable)
|
| 21 |
.authorizeHttpRequests(auth -> auth
|
| 22 |
+
|
| 23 |
+
// Tarayıcının CORS preflight istekleri
|
| 24 |
+
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
|
| 25 |
+
|
| 26 |
+
.requestMatchers(
|
| 27 |
+
"/api/v1/auth/register",
|
| 28 |
+
"/api/v1/auth/login",
|
| 29 |
+
"/api/v1/auth/validate",
|
| 30 |
+
"/api/v1/auth/logout",
|
| 31 |
+
"/api/v1/provider/validate-provider",
|
| 32 |
+
"/api/v1/users/details",
|
| 33 |
+
"/api/v1/otp/register/**",
|
| 34 |
+
"/api/v1/otp/validate/**",
|
| 35 |
+
"/api/v1/internal/page-auth/**",
|
| 36 |
+
"/api/v1/db-security/**",
|
| 37 |
+
"/api/v1/permission/**",
|
| 38 |
+
"/api/v1/fcm/**",
|
| 39 |
+
"/v3/api-docs/**",
|
| 40 |
+
"/swagger-ui/**",
|
| 41 |
+
"/swagger-ui/index.html"
|
| 42 |
+
).permitAll()
|
| 43 |
+
|
| 44 |
.anyRequest().authenticated()
|
| 45 |
);
|
| 46 |
+
|
| 47 |
return http.build();
|
| 48 |
}
|
| 49 |
|
src/main/java/com/artandscience/security/controller/FcmTokenController.java
CHANGED
|
@@ -3,9 +3,7 @@ package com.artandscience.security.controller;
|
|
| 3 |
import com.artandscience.security.common.base.controller.BaseController;
|
| 4 |
import com.artandscience.security.common.base.response.MessageResponse;
|
| 5 |
import com.artandscience.security.domain.request.SetFcmTokenRequest;
|
| 6 |
-
import com.artandscience.security.domain.request.GetOnlineStatusRequest;
|
| 7 |
import com.artandscience.security.domain.response.GetFcmTokenResponse;
|
| 8 |
-
import com.artandscience.security.domain.response.GetOnlineStatusResponse;
|
| 9 |
import com.artandscience.security.domain.service.FcmTokenService;
|
| 10 |
import lombok.RequiredArgsConstructor;
|
| 11 |
import org.springframework.web.bind.annotation.*;
|
|
@@ -28,12 +26,4 @@ public class FcmTokenController extends BaseController {
|
|
| 28 |
var output = fcmTokenService.getFcmToken();
|
| 29 |
return responseSuccess(output.toResponse());
|
| 30 |
}
|
| 31 |
-
|
| 32 |
-
@PostMapping("/get-online-status")
|
| 33 |
-
public MessageResponse<GetOnlineStatusResponse> getOnlineStatus(@RequestBody GetOnlineStatusRequest request) {
|
| 34 |
-
var output = fcmTokenService.getOnlineStatus(request.toInput());
|
| 35 |
-
return responseSuccess(output.toResponse());
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
|
| 39 |
}
|
|
|
|
| 3 |
import com.artandscience.security.common.base.controller.BaseController;
|
| 4 |
import com.artandscience.security.common.base.response.MessageResponse;
|
| 5 |
import com.artandscience.security.domain.request.SetFcmTokenRequest;
|
|
|
|
| 6 |
import com.artandscience.security.domain.response.GetFcmTokenResponse;
|
|
|
|
| 7 |
import com.artandscience.security.domain.service.FcmTokenService;
|
| 8 |
import lombok.RequiredArgsConstructor;
|
| 9 |
import org.springframework.web.bind.annotation.*;
|
|
|
|
| 26 |
var output = fcmTokenService.getFcmToken();
|
| 27 |
return responseSuccess(output.toResponse());
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
src/main/java/com/artandscience/security/controller/OnlineStatusController.java
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.security.controller;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.security.common.base.controller.BaseController;
|
| 4 |
+
import com.artandscience.security.common.base.response.MessageResponse;
|
| 5 |
+
import com.artandscience.security.domain.request.OnlineStatusRequest;
|
| 6 |
+
import com.artandscience.security.domain.response.OnlineStatusResponse;
|
| 7 |
+
import com.artandscience.security.domain.service.OnlineStatusService;
|
| 8 |
+
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
| 9 |
+
import lombok.RequiredArgsConstructor;
|
| 10 |
+
import org.springframework.web.bind.annotation.PostMapping;
|
| 11 |
+
import org.springframework.web.bind.annotation.RequestMapping;
|
| 12 |
+
import org.springframework.web.bind.annotation.RestController;
|
| 13 |
+
|
| 14 |
+
@RestController
|
| 15 |
+
@RequestMapping("/api/v1/online")
|
| 16 |
+
@RequiredArgsConstructor
|
| 17 |
+
public class OnlineStatusController extends BaseController {
|
| 18 |
+
|
| 19 |
+
private final OnlineStatusService onlineStatusService;
|
| 20 |
+
|
| 21 |
+
@PostMapping("/status")
|
| 22 |
+
public MessageResponse<OnlineStatusResponse> isOnline(@RequestBody OnlineStatusRequest request) {
|
| 23 |
+
var output = onlineStatusService.isOnline(request.toInput());
|
| 24 |
+
return responseSuccess(output.toResponse());
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
}
|
src/main/java/com/artandscience/security/dao/entity/CustomerFcm.java
CHANGED
|
@@ -20,5 +20,4 @@ public class CustomerFcm {
|
|
| 20 |
private String customerNo;
|
| 21 |
private String fcmToken;
|
| 22 |
private String chanel;
|
| 23 |
-
private Boolean isOnline;
|
| 24 |
}
|
|
|
|
| 20 |
private String customerNo;
|
| 21 |
private String fcmToken;
|
| 22 |
private String chanel;
|
|
|
|
| 23 |
}
|
src/main/java/com/artandscience/security/dao/entity/CustomerOnlineStatus.java
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.security.dao.entity;
|
| 2 |
+
|
| 3 |
+
import jakarta.persistence.Entity;
|
| 4 |
+
import jakarta.persistence.Id;
|
| 5 |
+
import lombok.AllArgsConstructor;
|
| 6 |
+
import lombok.Builder;
|
| 7 |
+
import lombok.Data;
|
| 8 |
+
import lombok.NoArgsConstructor;
|
| 9 |
+
|
| 10 |
+
@Entity
|
| 11 |
+
@AllArgsConstructor
|
| 12 |
+
@NoArgsConstructor
|
| 13 |
+
@Builder
|
| 14 |
+
@Data
|
| 15 |
+
public class CustomerOnlineStatus {
|
| 16 |
+
|
| 17 |
+
@Id
|
| 18 |
+
private String uid;
|
| 19 |
+
private String customerNumber;
|
| 20 |
+
private Boolean isOnline;
|
| 21 |
+
|
| 22 |
+
}
|
src/main/java/com/artandscience/security/dao/entity/Users.java
CHANGED
|
@@ -7,6 +7,7 @@ import lombok.AllArgsConstructor;
|
|
| 7 |
import lombok.Data;
|
| 8 |
import lombok.NoArgsConstructor;
|
| 9 |
|
|
|
|
| 10 |
import java.time.LocalDateTime;
|
| 11 |
|
| 12 |
@AllArgsConstructor
|
|
@@ -23,13 +24,14 @@ public class Users {
|
|
| 23 |
private String email;
|
| 24 |
private LocalDateTime registeredDate;
|
| 25 |
private String customerNo;
|
| 26 |
-
private
|
|
|
|
| 27 |
|
| 28 |
public Users toEntity(UserInput input,String customerNumber) {
|
| 29 |
return new Users(input.getLocalId(),input.getName(),
|
| 30 |
input.getSurname(),input.getPhoneNumber(),
|
| 31 |
input.getEmail(),
|
| 32 |
-
LocalDateTime.now(), customerNumber, Boolean.
|
| 33 |
}
|
| 34 |
|
| 35 |
}
|
|
|
|
| 7 |
import lombok.Data;
|
| 8 |
import lombok.NoArgsConstructor;
|
| 9 |
|
| 10 |
+
import java.time.LocalDate;
|
| 11 |
import java.time.LocalDateTime;
|
| 12 |
|
| 13 |
@AllArgsConstructor
|
|
|
|
| 24 |
private String email;
|
| 25 |
private LocalDateTime registeredDate;
|
| 26 |
private String customerNo;
|
| 27 |
+
private LocalDate birthday;
|
| 28 |
+
private Boolean isFirstLogin;
|
| 29 |
|
| 30 |
public Users toEntity(UserInput input,String customerNumber) {
|
| 31 |
return new Users(input.getLocalId(),input.getName(),
|
| 32 |
input.getSurname(),input.getPhoneNumber(),
|
| 33 |
input.getEmail(),
|
| 34 |
+
LocalDateTime.now(), customerNumber, birthday, Boolean.TRUE);
|
| 35 |
}
|
| 36 |
|
| 37 |
}
|
src/main/java/com/artandscience/security/dao/repository/CustomerFcmRepository.java
CHANGED
|
@@ -13,10 +13,9 @@ import java.util.Optional;
|
|
| 13 |
public interface CustomerFcmRepository extends JpaRepository<CustomerFcm,String> {
|
| 14 |
Optional<CustomerFcm> findByCustomerNoEqualsAndChanelEquals(String customerNo,String chanel);
|
| 15 |
|
| 16 |
-
boolean existsByCustomerNoAndIsOnlineTrue(String customerNo);
|
| 17 |
|
| 18 |
@Query("select c from CustomerFcm c where " +
|
| 19 |
-
"c.customerNo =:customerNo
|
| 20 |
-
List<CustomerFcm>
|
| 21 |
|
| 22 |
}
|
|
|
|
| 13 |
public interface CustomerFcmRepository extends JpaRepository<CustomerFcm,String> {
|
| 14 |
Optional<CustomerFcm> findByCustomerNoEqualsAndChanelEquals(String customerNo,String chanel);
|
| 15 |
|
|
|
|
| 16 |
|
| 17 |
@Query("select c from CustomerFcm c where " +
|
| 18 |
+
"c.customerNo =:customerNo")
|
| 19 |
+
List<CustomerFcm> getCustomerNo(@Param("customerNo")String customerNo);
|
| 20 |
|
| 21 |
}
|
src/main/java/com/artandscience/security/dao/repository/CustomerOnlineStatusRepository.java
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.security.dao.repository;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.security.dao.entity.CustomerOnlineStatus;
|
| 4 |
+
import org.springframework.data.jpa.repository.JpaRepository;
|
| 5 |
+
import org.springframework.data.jpa.repository.Query;
|
| 6 |
+
import org.springframework.data.repository.query.Param;
|
| 7 |
+
import org.springframework.stereotype.Repository;
|
| 8 |
+
|
| 9 |
+
import java.util.Optional;
|
| 10 |
+
|
| 11 |
+
@Repository
|
| 12 |
+
public interface CustomerOnlineStatusRepository extends JpaRepository<CustomerOnlineStatus,String> {
|
| 13 |
+
@Query("select c.isOnline from CustomerOnlineStatus c where c.customerNumber =:customerNo")
|
| 14 |
+
Boolean isOnlineForCustomerNo(@Param("customerNo") String customerNo);
|
| 15 |
+
|
| 16 |
+
Optional<CustomerOnlineStatus> findAllByCustomerNumberEquals(String customerNo);
|
| 17 |
+
}
|
src/main/java/com/artandscience/security/dao/repository/UserRepository.java
CHANGED
|
@@ -6,10 +6,13 @@ import org.springframework.data.jpa.repository.Query;
|
|
| 6 |
import org.springframework.data.repository.query.Param;
|
| 7 |
import org.springframework.stereotype.Repository;
|
| 8 |
|
|
|
|
|
|
|
| 9 |
@Repository
|
| 10 |
public interface UserRepository extends JpaRepository<Users,String> {
|
| 11 |
|
| 12 |
@Query("select u.customerNo from Users u where u.email =:mail")
|
| 13 |
String getCustomerNoByMail(@Param("mail")String mail);
|
| 14 |
|
|
|
|
| 15 |
}
|
|
|
|
| 6 |
import org.springframework.data.repository.query.Param;
|
| 7 |
import org.springframework.stereotype.Repository;
|
| 8 |
|
| 9 |
+
import java.util.Optional;
|
| 10 |
+
|
| 11 |
@Repository
|
| 12 |
public interface UserRepository extends JpaRepository<Users,String> {
|
| 13 |
|
| 14 |
@Query("select u.customerNo from Users u where u.email =:mail")
|
| 15 |
String getCustomerNoByMail(@Param("mail")String mail);
|
| 16 |
|
| 17 |
+
Optional<Users> findAllByCustomerNoEquals(String customerNo);
|
| 18 |
}
|
src/main/java/com/artandscience/security/domain/model/input/{GetOnlineStatusInput.java → OnlineStatusInput.java}
RENAMED
|
@@ -1,10 +1,14 @@
|
|
| 1 |
package com.artandscience.security.domain.model.input;
|
| 2 |
|
|
|
|
| 3 |
import lombok.Builder;
|
| 4 |
import lombok.Data;
|
|
|
|
| 5 |
|
| 6 |
@Data
|
|
|
|
|
|
|
| 7 |
@Builder
|
| 8 |
-
public class
|
| 9 |
private String customerNumber;
|
| 10 |
}
|
|
|
|
| 1 |
package com.artandscience.security.domain.model.input;
|
| 2 |
|
| 3 |
+
import lombok.AllArgsConstructor;
|
| 4 |
import lombok.Builder;
|
| 5 |
import lombok.Data;
|
| 6 |
+
import lombok.NoArgsConstructor;
|
| 7 |
|
| 8 |
@Data
|
| 9 |
+
@AllArgsConstructor
|
| 10 |
+
@NoArgsConstructor
|
| 11 |
@Builder
|
| 12 |
+
public class OnlineStatusInput {
|
| 13 |
private String customerNumber;
|
| 14 |
}
|
src/main/java/com/artandscience/security/domain/model/input/RegisterInput.java
CHANGED
|
@@ -5,6 +5,7 @@ import com.artandscience.security.integration.service.request.SignUpNewUserReque
|
|
| 5 |
import lombok.Builder;
|
| 6 |
import lombok.Data;
|
| 7 |
|
|
|
|
| 8 |
import java.util.List;
|
| 9 |
|
| 10 |
@Data
|
|
@@ -17,6 +18,7 @@ public class RegisterInput {
|
|
| 17 |
private String name;
|
| 18 |
private String surname;
|
| 19 |
private Role role;
|
|
|
|
| 20 |
private List<String> permissionUids;
|
| 21 |
|
| 22 |
public SignUpNewUserRequest toRequest() {
|
|
|
|
| 5 |
import lombok.Builder;
|
| 6 |
import lombok.Data;
|
| 7 |
|
| 8 |
+
import java.time.LocalDate;
|
| 9 |
import java.util.List;
|
| 10 |
|
| 11 |
@Data
|
|
|
|
| 18 |
private String name;
|
| 19 |
private String surname;
|
| 20 |
private Role role;
|
| 21 |
+
private LocalDate birthday;
|
| 22 |
private List<String> permissionUids;
|
| 23 |
|
| 24 |
public SignUpNewUserRequest toRequest() {
|
src/main/java/com/artandscience/security/domain/model/input/{UpdateOnlineStatusInput.java → SaveOnlineStatusInput.java}
RENAMED
|
@@ -1,11 +1,15 @@
|
|
| 1 |
package com.artandscience.security.domain.model.input;
|
| 2 |
|
|
|
|
| 3 |
import lombok.Builder;
|
| 4 |
import lombok.Data;
|
|
|
|
| 5 |
|
| 6 |
@Data
|
| 7 |
@Builder
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
private Boolean isOnline;
|
| 10 |
-
private String
|
| 11 |
}
|
|
|
|
| 1 |
package com.artandscience.security.domain.model.input;
|
| 2 |
|
| 3 |
+
import lombok.AllArgsConstructor;
|
| 4 |
import lombok.Builder;
|
| 5 |
import lombok.Data;
|
| 6 |
+
import lombok.NoArgsConstructor;
|
| 7 |
|
| 8 |
@Data
|
| 9 |
@Builder
|
| 10 |
+
@AllArgsConstructor
|
| 11 |
+
@NoArgsConstructor
|
| 12 |
+
public class SaveOnlineStatusInput {
|
| 13 |
private Boolean isOnline;
|
| 14 |
+
private String customerNumber;
|
| 15 |
}
|
src/main/java/com/artandscience/security/domain/model/input/SetFcmTokenInput.java
CHANGED
|
@@ -7,5 +7,4 @@ import lombok.Data;
|
|
| 7 |
@Builder
|
| 8 |
public class SetFcmTokenInput {
|
| 9 |
private String fcmToken;
|
| 10 |
-
private Boolean isOnline;
|
| 11 |
}
|
|
|
|
| 7 |
@Builder
|
| 8 |
public class SetFcmTokenInput {
|
| 9 |
private String fcmToken;
|
|
|
|
| 10 |
}
|
src/main/java/com/artandscience/security/domain/model/input/UserInput.java
CHANGED
|
@@ -5,6 +5,7 @@ import com.artandscience.security.domain.enums.Role;
|
|
| 5 |
import lombok.Builder;
|
| 6 |
import lombok.Data;
|
| 7 |
|
|
|
|
| 8 |
import java.util.List;
|
| 9 |
|
| 10 |
@Data
|
|
@@ -18,5 +19,7 @@ public class UserInput {
|
|
| 18 |
private String email;
|
| 19 |
private List<BackofficePermission> backofficePermissions;
|
| 20 |
private Role role;
|
|
|
|
|
|
|
| 21 |
|
| 22 |
}
|
|
|
|
| 5 |
import lombok.Builder;
|
| 6 |
import lombok.Data;
|
| 7 |
|
| 8 |
+
import java.time.LocalDate;
|
| 9 |
import java.util.List;
|
| 10 |
|
| 11 |
@Data
|
|
|
|
| 19 |
private String email;
|
| 20 |
private List<BackofficePermission> backofficePermissions;
|
| 21 |
private Role role;
|
| 22 |
+
private LocalDate birthday;
|
| 23 |
+
private Boolean isFirstLogin;
|
| 24 |
|
| 25 |
}
|
src/main/java/com/artandscience/security/domain/model/output/GetUserOutput.java
CHANGED
|
@@ -4,6 +4,7 @@ import com.artandscience.security.domain.response.GetUserResponse;
|
|
| 4 |
import lombok.Builder;
|
| 5 |
import lombok.Data;
|
| 6 |
|
|
|
|
| 7 |
import java.util.List;
|
| 8 |
|
| 9 |
@Data
|
|
@@ -16,6 +17,8 @@ public class GetUserOutput {
|
|
| 16 |
private String email;
|
| 17 |
private String customerNumber;
|
| 18 |
private List<String> permissions;
|
|
|
|
|
|
|
| 19 |
|
| 20 |
public GetUserResponse toResponse() {
|
| 21 |
return GetUserResponse.builder()
|
|
@@ -25,6 +28,8 @@ public class GetUserOutput {
|
|
| 25 |
.phoneNumber(phoneNumber)
|
| 26 |
.customerNumber(customerNumber)
|
| 27 |
.permissions(permissions)
|
|
|
|
|
|
|
| 28 |
.build();
|
| 29 |
}
|
| 30 |
|
|
|
|
| 4 |
import lombok.Builder;
|
| 5 |
import lombok.Data;
|
| 6 |
|
| 7 |
+
import java.time.LocalDate;
|
| 8 |
import java.util.List;
|
| 9 |
|
| 10 |
@Data
|
|
|
|
| 17 |
private String email;
|
| 18 |
private String customerNumber;
|
| 19 |
private List<String> permissions;
|
| 20 |
+
private String birthday;
|
| 21 |
+
private Boolean isLogin;
|
| 22 |
|
| 23 |
public GetUserResponse toResponse() {
|
| 24 |
return GetUserResponse.builder()
|
|
|
|
| 28 |
.phoneNumber(phoneNumber)
|
| 29 |
.customerNumber(customerNumber)
|
| 30 |
.permissions(permissions)
|
| 31 |
+
.birthday(birthday)
|
| 32 |
+
.isFirstLogin(isLogin ? "1" : "0")
|
| 33 |
.build();
|
| 34 |
}
|
| 35 |
|
src/main/java/com/artandscience/security/domain/model/output/{GetOnlineStatusOutput.java → OnlineStatusOutput.java}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
package com.artandscience.security.domain.model.output;
|
| 2 |
|
| 3 |
-
import com.artandscience.security.domain.response.
|
| 4 |
import lombok.AllArgsConstructor;
|
| 5 |
import lombok.Builder;
|
| 6 |
import lombok.Data;
|
|
@@ -10,13 +10,12 @@ import lombok.NoArgsConstructor;
|
|
| 10 |
@Builder
|
| 11 |
@AllArgsConstructor
|
| 12 |
@NoArgsConstructor
|
| 13 |
-
public class
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
return GetOnlineStatusResponse.builder()
|
| 19 |
-
.online(online)
|
| 20 |
.build();
|
| 21 |
}
|
| 22 |
|
|
|
|
| 1 |
package com.artandscience.security.domain.model.output;
|
| 2 |
|
| 3 |
+
import com.artandscience.security.domain.response.OnlineStatusResponse;
|
| 4 |
import lombok.AllArgsConstructor;
|
| 5 |
import lombok.Builder;
|
| 6 |
import lombok.Data;
|
|
|
|
| 10 |
@Builder
|
| 11 |
@AllArgsConstructor
|
| 12 |
@NoArgsConstructor
|
| 13 |
+
public class OnlineStatusOutput {
|
| 14 |
+
private Boolean isOnline;
|
| 15 |
|
| 16 |
+
public OnlineStatusResponse toResponse() {
|
| 17 |
+
return OnlineStatusResponse.builder()
|
| 18 |
+
.isOnline(isOnline)
|
|
|
|
|
|
|
| 19 |
.build();
|
| 20 |
}
|
| 21 |
|
src/main/java/com/artandscience/security/domain/request/{GetOnlineStatusRequest.java → OnlineStatusRequest.java}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
package com.artandscience.security.domain.request;
|
| 2 |
|
| 3 |
-
import com.artandscience.security.domain.model.input.
|
| 4 |
import lombok.AllArgsConstructor;
|
| 5 |
import lombok.Builder;
|
| 6 |
import lombok.Data;
|
|
@@ -10,11 +10,11 @@ import lombok.NoArgsConstructor;
|
|
| 10 |
@AllArgsConstructor
|
| 11 |
@NoArgsConstructor
|
| 12 |
@Builder
|
| 13 |
-
public class
|
| 14 |
private String customerNumber;
|
| 15 |
|
| 16 |
-
public
|
| 17 |
-
return
|
| 18 |
.customerNumber(customerNumber)
|
| 19 |
.build();
|
| 20 |
}
|
|
|
|
| 1 |
package com.artandscience.security.domain.request;
|
| 2 |
|
| 3 |
+
import com.artandscience.security.domain.model.input.OnlineStatusInput;
|
| 4 |
import lombok.AllArgsConstructor;
|
| 5 |
import lombok.Builder;
|
| 6 |
import lombok.Data;
|
|
|
|
| 10 |
@AllArgsConstructor
|
| 11 |
@NoArgsConstructor
|
| 12 |
@Builder
|
| 13 |
+
public class OnlineStatusRequest {
|
| 14 |
private String customerNumber;
|
| 15 |
|
| 16 |
+
public OnlineStatusInput toInput() {
|
| 17 |
+
return OnlineStatusInput.builder()
|
| 18 |
.customerNumber(customerNumber)
|
| 19 |
.build();
|
| 20 |
}
|
src/main/java/com/artandscience/security/domain/request/SaveOnlineStatusRequest.java
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.security.domain.request;
|
| 2 |
+
|
| 3 |
+
import lombok.AllArgsConstructor;
|
| 4 |
+
import lombok.Builder;
|
| 5 |
+
import lombok.Data;
|
| 6 |
+
import lombok.NoArgsConstructor;
|
| 7 |
+
|
| 8 |
+
@Data
|
| 9 |
+
@Builder
|
| 10 |
+
@AllArgsConstructor
|
| 11 |
+
@NoArgsConstructor
|
| 12 |
+
public class SaveOnlineStatusRequest {
|
| 13 |
+
private Boolean isOnline;
|
| 14 |
+
private String customerNumber;
|
| 15 |
+
}
|
src/main/java/com/artandscience/security/domain/request/SetFcmTokenRequest.java
CHANGED
|
@@ -12,12 +12,10 @@ import lombok.NoArgsConstructor;
|
|
| 12 |
@Builder
|
| 13 |
public class SetFcmTokenRequest {
|
| 14 |
private String fcmToken;
|
| 15 |
-
private Boolean isOnline;
|
| 16 |
|
| 17 |
public SetFcmTokenInput toInput() {
|
| 18 |
return SetFcmTokenInput.builder()
|
| 19 |
.fcmToken(fcmToken)
|
| 20 |
-
.isOnline(isOnline)
|
| 21 |
.build();
|
| 22 |
}
|
| 23 |
|
|
|
|
| 12 |
@Builder
|
| 13 |
public class SetFcmTokenRequest {
|
| 14 |
private String fcmToken;
|
|
|
|
| 15 |
|
| 16 |
public SetFcmTokenInput toInput() {
|
| 17 |
return SetFcmTokenInput.builder()
|
| 18 |
.fcmToken(fcmToken)
|
|
|
|
| 19 |
.build();
|
| 20 |
}
|
| 21 |
|
src/main/java/com/artandscience/security/domain/response/GetUserResponse.java
CHANGED
|
@@ -20,5 +20,7 @@ public class GetUserResponse implements Serializable {
|
|
| 20 |
private String email;
|
| 21 |
private String customerNumber;
|
| 22 |
private List<String> permissions;
|
|
|
|
|
|
|
| 23 |
|
| 24 |
}
|
|
|
|
| 20 |
private String email;
|
| 21 |
private String customerNumber;
|
| 22 |
private List<String> permissions;
|
| 23 |
+
private String birthday;
|
| 24 |
+
private String isFirstLogin;
|
| 25 |
|
| 26 |
}
|
src/main/java/com/artandscience/security/domain/response/{GetOnlineStatusResponse.java → OnlineStatusResponse.java}
RENAMED
|
@@ -9,8 +9,6 @@ import lombok.NoArgsConstructor;
|
|
| 9 |
@Builder
|
| 10 |
@AllArgsConstructor
|
| 11 |
@NoArgsConstructor
|
| 12 |
-
public class
|
| 13 |
-
|
| 14 |
-
private Boolean online;
|
| 15 |
-
|
| 16 |
}
|
|
|
|
| 9 |
@Builder
|
| 10 |
@AllArgsConstructor
|
| 11 |
@NoArgsConstructor
|
| 12 |
+
public class OnlineStatusResponse {
|
| 13 |
+
private Boolean isOnline;
|
|
|
|
|
|
|
| 14 |
}
|
src/main/java/com/artandscience/security/domain/service/FcmTokenService.java
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
package com.artandscience.security.domain.service;
|
| 2 |
|
| 3 |
import com.artandscience.security.domain.model.input.SetFcmTokenInput;
|
| 4 |
-
import com.artandscience.security.domain.model.input.GetOnlineStatusInput;
|
| 5 |
import com.artandscience.security.domain.model.output.GetFcmTokenOutput;
|
| 6 |
-
import com.artandscience.security.domain.model.output.GetOnlineStatusOutput;
|
| 7 |
|
| 8 |
public interface FcmTokenService {
|
| 9 |
|
|
@@ -11,6 +9,4 @@ public interface FcmTokenService {
|
|
| 11 |
|
| 12 |
GetFcmTokenOutput getFcmToken();
|
| 13 |
|
| 14 |
-
GetOnlineStatusOutput getOnlineStatus(GetOnlineStatusInput input);
|
| 15 |
-
|
| 16 |
}
|
|
|
|
| 1 |
package com.artandscience.security.domain.service;
|
| 2 |
|
| 3 |
import com.artandscience.security.domain.model.input.SetFcmTokenInput;
|
|
|
|
| 4 |
import com.artandscience.security.domain.model.output.GetFcmTokenOutput;
|
|
|
|
| 5 |
|
| 6 |
public interface FcmTokenService {
|
| 7 |
|
|
|
|
| 9 |
|
| 10 |
GetFcmTokenOutput getFcmToken();
|
| 11 |
|
|
|
|
|
|
|
| 12 |
}
|
src/main/java/com/artandscience/security/domain/service/OnlineStatusService.java
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.security.domain.service;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.security.domain.model.input.OnlineStatusInput;
|
| 4 |
+
import com.artandscience.security.domain.model.input.SaveOnlineStatusInput;
|
| 5 |
+
import com.artandscience.security.domain.model.output.OnlineStatusOutput;
|
| 6 |
+
|
| 7 |
+
public interface OnlineStatusService {
|
| 8 |
+
|
| 9 |
+
OnlineStatusOutput isOnline(OnlineStatusInput input);
|
| 10 |
+
|
| 11 |
+
void saveOnlineStatus(SaveOnlineStatusInput input);
|
| 12 |
+
|
| 13 |
+
}
|
src/main/java/com/artandscience/security/domain/service/base/UserService.java
CHANGED
|
@@ -8,10 +8,12 @@ import com.artandscience.security.domain.model.output.GetUserOutput;
|
|
| 8 |
|
| 9 |
public interface UserService {
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
GetUserOutput getUserDetail(GetUserInput input);
|
| 14 |
|
| 15 |
GetCustomerNoByMailOutput getCustomerNumberByUsers(GetCustomerNoByMailInput input);
|
| 16 |
|
|
|
|
|
|
|
| 17 |
}
|
|
|
|
| 8 |
|
| 9 |
public interface UserService {
|
| 10 |
|
| 11 |
+
String addUser(UserInput input);
|
| 12 |
|
| 13 |
GetUserOutput getUserDetail(GetUserInput input);
|
| 14 |
|
| 15 |
GetCustomerNoByMailOutput getCustomerNumberByUsers(GetCustomerNoByMailInput input);
|
| 16 |
|
| 17 |
+
void updateLoginStatus();
|
| 18 |
+
|
| 19 |
}
|
src/main/java/com/artandscience/security/domain/service/impl/ArtAndScienceAuthServiceImpl.java
CHANGED
|
@@ -9,6 +9,7 @@ import com.artandscience.security.domain.model.LoginSession;
|
|
| 9 |
import com.artandscience.security.domain.model.provider.Provider;
|
| 10 |
import com.artandscience.security.domain.model.input.*;
|
| 11 |
import com.artandscience.security.domain.model.output.*;
|
|
|
|
| 12 |
import com.artandscience.security.domain.request.ArtAndScienceAuthServiceRequest;
|
| 13 |
import com.artandscience.security.domain.service.ArtAndScienceAuthService;
|
| 14 |
import com.artandscience.security.domain.util.*;
|
|
@@ -26,9 +27,12 @@ import org.springframework.beans.factory.annotation.Value;
|
|
| 26 |
import org.springframework.context.annotation.Profile;
|
| 27 |
import org.springframework.stereotype.Service;
|
| 28 |
|
|
|
|
|
|
|
| 29 |
import java.util.ArrayList;
|
| 30 |
import java.util.List;
|
| 31 |
import java.util.Objects;
|
|
|
|
| 32 |
|
| 33 |
import static com.artandscience.security.common.constants.AuthServiceContant.*;
|
| 34 |
import static com.artandscience.security.common.constants.GeneralConstant.ARTANDSCIENCE_PROFILE;
|
|
@@ -41,9 +45,8 @@ import static com.artandscience.security.common.constants.GeneralConstant.ARTAND
|
|
| 41 |
public class ArtAndScienceAuthServiceImpl implements ArtAndScienceAuthService {
|
| 42 |
|
| 43 |
private final ArtAndScienceAuthServiceRequest serviceRequest;
|
|
|
|
| 44 |
|
| 45 |
-
@Value("${cookie.name}")
|
| 46 |
-
private String cookieName;
|
| 47 |
|
| 48 |
@Override
|
| 49 |
public RegisterOutput register(RegisterInput input) {
|
|
@@ -56,14 +59,31 @@ public class ArtAndScienceAuthServiceImpl implements ArtAndScienceAuthService {
|
|
| 56 |
|
| 57 |
serviceRequest.getFirebaseClaimUtil().setUserRoleClaim(clientResponse.getLocalId(),input.getRole().name());
|
| 58 |
|
| 59 |
-
serviceRequest.getUserService().addUser(UserInput.builder()
|
| 60 |
.name(input.getName())
|
| 61 |
.surname(input.getSurname())
|
| 62 |
.phoneNumber(input.getPhoneNumber())
|
| 63 |
.email(input.getEmail())
|
| 64 |
.localId(clientResponse.getLocalId())
|
|
|
|
| 65 |
.build());
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
return RegisterOutput.builder()
|
| 68 |
.sessionId(sessionId)
|
| 69 |
.messageBoxes(List.of(serviceRequest.getExternalAttributeService()
|
|
@@ -94,7 +114,7 @@ public class ArtAndScienceAuthServiceImpl implements ArtAndScienceAuthService {
|
|
| 94 |
throw new RuntimeException(e);
|
| 95 |
}
|
| 96 |
|
| 97 |
-
|
| 98 |
|
| 99 |
AuthLogHelper.successLoginLog(serviceRequest.getAuthLogService(), input.getEmail());
|
| 100 |
|
|
@@ -159,11 +179,9 @@ public class ArtAndScienceAuthServiceImpl implements ArtAndScienceAuthService {
|
|
| 159 |
|
| 160 |
@Override
|
| 161 |
public LogoutOutput logout() {
|
|
|
|
| 162 |
serviceRequest.getSessionService().removeSession(null,false,false);
|
| 163 |
-
|
| 164 |
-
serviceRequest.getFcmTokenService().setFcmToken(SetFcmTokenInput.builder()
|
| 165 |
-
.isOnline(false)
|
| 166 |
-
.build());
|
| 167 |
AuthLogHelper.successLogoutLog(serviceRequest.getAuthLogService(),null);
|
| 168 |
return LogoutOutput.builder()
|
| 169 |
.messageBoxes(List.of(serviceRequest.getExternalAttributeService()
|
|
|
|
| 9 |
import com.artandscience.security.domain.model.provider.Provider;
|
| 10 |
import com.artandscience.security.domain.model.input.*;
|
| 11 |
import com.artandscience.security.domain.model.output.*;
|
| 12 |
+
//import com.artandscience.security.domain.publish.KafkaNotificationPublisher;
|
| 13 |
import com.artandscience.security.domain.request.ArtAndScienceAuthServiceRequest;
|
| 14 |
import com.artandscience.security.domain.service.ArtAndScienceAuthService;
|
| 15 |
import com.artandscience.security.domain.util.*;
|
|
|
|
| 27 |
import org.springframework.context.annotation.Profile;
|
| 28 |
import org.springframework.stereotype.Service;
|
| 29 |
|
| 30 |
+
import java.time.ZonedDateTime;
|
| 31 |
+
import java.time.format.DateTimeFormatter;
|
| 32 |
import java.util.ArrayList;
|
| 33 |
import java.util.List;
|
| 34 |
import java.util.Objects;
|
| 35 |
+
import java.util.UUID;
|
| 36 |
|
| 37 |
import static com.artandscience.security.common.constants.AuthServiceContant.*;
|
| 38 |
import static com.artandscience.security.common.constants.GeneralConstant.ARTANDSCIENCE_PROFILE;
|
|
|
|
| 45 |
public class ArtAndScienceAuthServiceImpl implements ArtAndScienceAuthService {
|
| 46 |
|
| 47 |
private final ArtAndScienceAuthServiceRequest serviceRequest;
|
| 48 |
+
//private final KafkaNotificationPublisher publisher;
|
| 49 |
|
|
|
|
|
|
|
| 50 |
|
| 51 |
@Override
|
| 52 |
public RegisterOutput register(RegisterInput input) {
|
|
|
|
| 59 |
|
| 60 |
serviceRequest.getFirebaseClaimUtil().setUserRoleClaim(clientResponse.getLocalId(),input.getRole().name());
|
| 61 |
|
| 62 |
+
String customerNo = serviceRequest.getUserService().addUser(UserInput.builder()
|
| 63 |
.name(input.getName())
|
| 64 |
.surname(input.getSurname())
|
| 65 |
.phoneNumber(input.getPhoneNumber())
|
| 66 |
.email(input.getEmail())
|
| 67 |
.localId(clientResponse.getLocalId())
|
| 68 |
+
.birthday(input.getBirthday())
|
| 69 |
.build());
|
| 70 |
|
| 71 |
+
/*UserPayload payload = UserPayload.builder()
|
| 72 |
+
.customerNo(customerNo)
|
| 73 |
+
.email(input.getEmail())
|
| 74 |
+
.fullName(input.getName() + " " + input.getSurname())
|
| 75 |
+
.build();
|
| 76 |
+
|
| 77 |
+
UserEventPayload eventPayload = UserEventPayload.builder()
|
| 78 |
+
.eventId(UUID.randomUUID().toString())
|
| 79 |
+
.eventType("USER_REGISTERED")
|
| 80 |
+
.source("auth-service")
|
| 81 |
+
.occurredAt(ZonedDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))
|
| 82 |
+
.payload(payload)
|
| 83 |
+
.build();
|
| 84 |
+
|
| 85 |
+
publisher.publish(eventPayload);*/
|
| 86 |
+
|
| 87 |
return RegisterOutput.builder()
|
| 88 |
.sessionId(sessionId)
|
| 89 |
.messageBoxes(List.of(serviceRequest.getExternalAttributeService()
|
|
|
|
| 114 |
throw new RuntimeException(e);
|
| 115 |
}
|
| 116 |
|
| 117 |
+
serviceRequest.getSessionService().setSessionByDeviceId(sessionId);
|
| 118 |
|
| 119 |
AuthLogHelper.successLoginLog(serviceRequest.getAuthLogService(), input.getEmail());
|
| 120 |
|
|
|
|
| 179 |
|
| 180 |
@Override
|
| 181 |
public LogoutOutput logout() {
|
| 182 |
+
serviceRequest.getUserService().updateLoginStatus();
|
| 183 |
serviceRequest.getSessionService().removeSession(null,false,false);
|
| 184 |
+
serviceRequest.getSessionService().removeSessionByDeviceId();
|
|
|
|
|
|
|
|
|
|
| 185 |
AuthLogHelper.successLogoutLog(serviceRequest.getAuthLogService(),null);
|
| 186 |
return LogoutOutput.builder()
|
| 187 |
.messageBoxes(List.of(serviceRequest.getExternalAttributeService()
|
src/main/java/com/artandscience/security/domain/service/impl/ArtAndScienceUserServiceImpl.java
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
package com.artandscience.security.domain.service.impl;
|
| 2 |
|
|
|
|
|
|
|
| 3 |
import com.artandscience.security.common.utils.CustomerGenerator;
|
|
|
|
| 4 |
import com.artandscience.security.dao.entity.Users;
|
| 5 |
import com.artandscience.security.dao.repository.UserRepository;
|
| 6 |
import com.artandscience.security.domain.model.input.GetCustomerNoByMailInput;
|
|
@@ -28,9 +31,10 @@ public class ArtAndScienceUserServiceImpl implements ArtAndScienceUserService {
|
|
| 28 |
|
| 29 |
private final UserRepository userRepository;
|
| 30 |
private final LoginSecurityService loginSecurityService;
|
|
|
|
| 31 |
|
| 32 |
@Override
|
| 33 |
-
public
|
| 34 |
|
| 35 |
Users users = new Users();
|
| 36 |
String customerNo = CustomerGenerator.generateCustomerNumber();
|
|
@@ -39,7 +43,7 @@ public class ArtAndScienceUserServiceImpl implements ArtAndScienceUserService {
|
|
| 39 |
loginSecurityService.addLoginSecurity(LoginSecurityByCustomerNoInput.builder()
|
| 40 |
.customerNo(customerNo)
|
| 41 |
.build());
|
| 42 |
-
|
| 43 |
}
|
| 44 |
|
| 45 |
@Override
|
|
@@ -56,6 +60,8 @@ public class ArtAndScienceUserServiceImpl implements ArtAndScienceUserService {
|
|
| 56 |
.email(users.getEmail())
|
| 57 |
.phoneNumber(users.getPhoneNumber())
|
| 58 |
.customerNumber(users.getCustomerNo())
|
|
|
|
|
|
|
| 59 |
.build();
|
| 60 |
} else {
|
| 61 |
throw new RuntimeException();
|
|
@@ -70,4 +76,18 @@ public class ArtAndScienceUserServiceImpl implements ArtAndScienceUserService {
|
|
| 70 |
.customerNo(customerNo)
|
| 71 |
.build();
|
| 72 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
}
|
|
|
|
| 1 |
package com.artandscience.security.domain.service.impl;
|
| 2 |
|
| 3 |
+
import com.artandscience.security.common.helper.RequestScopeHelper;
|
| 4 |
+
import com.artandscience.security.common.scope.RequestHeaderScope;
|
| 5 |
import com.artandscience.security.common.utils.CustomerGenerator;
|
| 6 |
+
import com.artandscience.security.common.utils.DateUtil;
|
| 7 |
import com.artandscience.security.dao.entity.Users;
|
| 8 |
import com.artandscience.security.dao.repository.UserRepository;
|
| 9 |
import com.artandscience.security.domain.model.input.GetCustomerNoByMailInput;
|
|
|
|
| 31 |
|
| 32 |
private final UserRepository userRepository;
|
| 33 |
private final LoginSecurityService loginSecurityService;
|
| 34 |
+
private final RequestHeaderScope requestHeaderScope;
|
| 35 |
|
| 36 |
@Override
|
| 37 |
+
public String addUser(UserInput input) {
|
| 38 |
|
| 39 |
Users users = new Users();
|
| 40 |
String customerNo = CustomerGenerator.generateCustomerNumber();
|
|
|
|
| 43 |
loginSecurityService.addLoginSecurity(LoginSecurityByCustomerNoInput.builder()
|
| 44 |
.customerNo(customerNo)
|
| 45 |
.build());
|
| 46 |
+
return customerNo;
|
| 47 |
}
|
| 48 |
|
| 49 |
@Override
|
|
|
|
| 60 |
.email(users.getEmail())
|
| 61 |
.phoneNumber(users.getPhoneNumber())
|
| 62 |
.customerNumber(users.getCustomerNo())
|
| 63 |
+
.birthday(DateUtil.localDateToString(users.getBirthday()))
|
| 64 |
+
.isLogin(users.getIsFirstLogin())
|
| 65 |
.build();
|
| 66 |
} else {
|
| 67 |
throw new RuntimeException();
|
|
|
|
| 76 |
.customerNo(customerNo)
|
| 77 |
.build();
|
| 78 |
}
|
| 79 |
+
|
| 80 |
+
/*ilk login olan kullanıcı logout olduğunda first login statüsü false olarak güncellenir.*/
|
| 81 |
+
@Override
|
| 82 |
+
public void updateLoginStatus() {
|
| 83 |
+
var customerNo = RequestScopeHelper.getCustomerNumber(requestHeaderScope);
|
| 84 |
+
Optional<Users> optUser = userRepository.findAllByCustomerNoEquals(customerNo);
|
| 85 |
+
if (optUser.isPresent()) {
|
| 86 |
+
Users users = optUser.get();
|
| 87 |
+
if (users.getIsFirstLogin()) {
|
| 88 |
+
users.setIsFirstLogin(Boolean.FALSE);
|
| 89 |
+
userRepository.save(users);
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
}
|
src/main/java/com/artandscience/security/domain/service/impl/BackOfficeUserServiceImpl.java
CHANGED
|
@@ -38,9 +38,10 @@ public class BackOfficeUserServiceImpl implements BackOfficeUserService {
|
|
| 38 |
private final SessionService sessionService;
|
| 39 |
|
| 40 |
@Override
|
| 41 |
-
public
|
| 42 |
BackofficeUser backofficeUser = BackofficeUser.toEntity(input);
|
| 43 |
userRepository.save(backofficeUser);
|
|
|
|
| 44 |
}
|
| 45 |
|
| 46 |
@Override
|
|
@@ -113,6 +114,11 @@ public class BackOfficeUserServiceImpl implements BackOfficeUserService {
|
|
| 113 |
return null;
|
| 114 |
}
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
private void setSessionUser(BackofficeUser backofficeUser) {
|
| 117 |
UserSession userSession = UserSession.builder()
|
| 118 |
.name(backofficeUser.getName())
|
|
|
|
| 38 |
private final SessionService sessionService;
|
| 39 |
|
| 40 |
@Override
|
| 41 |
+
public String addUser(UserInput input) {
|
| 42 |
BackofficeUser backofficeUser = BackofficeUser.toEntity(input);
|
| 43 |
userRepository.save(backofficeUser);
|
| 44 |
+
return "";
|
| 45 |
}
|
| 46 |
|
| 47 |
@Override
|
|
|
|
| 114 |
return null;
|
| 115 |
}
|
| 116 |
|
| 117 |
+
@Override
|
| 118 |
+
public void updateLoginStatus() {
|
| 119 |
+
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
private void setSessionUser(BackofficeUser backofficeUser) {
|
| 123 |
UserSession userSession = UserSession.builder()
|
| 124 |
.name(backofficeUser.getName())
|
src/main/java/com/artandscience/security/domain/service/impl/FcmTokenServiceImpl.java
CHANGED
|
@@ -7,10 +7,8 @@ import com.artandscience.security.common.scope.RequestHeaderScope;
|
|
| 7 |
import com.artandscience.security.dao.entity.CustomerFcm;
|
| 8 |
import com.artandscience.security.dao.repository.CustomerFcmRepository;
|
| 9 |
import com.artandscience.security.domain.model.input.SetFcmTokenInput;
|
| 10 |
-
import com.artandscience.security.domain.model.input.GetOnlineStatusInput;
|
| 11 |
import com.artandscience.security.domain.model.mapper.GetFcmTokenMapper;
|
| 12 |
import com.artandscience.security.domain.model.output.GetFcmTokenOutput;
|
| 13 |
-
import com.artandscience.security.domain.model.output.GetOnlineStatusOutput;
|
| 14 |
import com.artandscience.security.domain.service.FcmTokenService;
|
| 15 |
import com.artandscience.security.domain.util.GenerateUtil;
|
| 16 |
import lombok.RequiredArgsConstructor;
|
|
@@ -32,7 +30,6 @@ public class FcmTokenServiceImpl implements FcmTokenService {
|
|
| 32 |
public void setFcmToken(SetFcmTokenInput input) {
|
| 33 |
|
| 34 |
// customerno ile kayıt varmı bakılır.
|
| 35 |
-
// inputtaki isonline false ise sadece isonline güncelle
|
| 36 |
|
| 37 |
String customerNo = RequestScopeHelper.getCustomerNumber(requestHeaderScope);
|
| 38 |
String chanel = RequestScopeHelper.getChanel(requestHeaderScope);
|
|
@@ -40,9 +37,9 @@ public class FcmTokenServiceImpl implements FcmTokenService {
|
|
| 40 |
var customerFcm = getCustomerFcmByCustomerNo(customerNo, chanel);
|
| 41 |
|
| 42 |
if (!Objects.isNull(customerFcm)) {
|
| 43 |
-
updateCustomerFcm(customerFcm,input.getFcmToken()
|
| 44 |
} else {
|
| 45 |
-
saveCustomerFcm(customerNo,chanel,input.
|
| 46 |
}
|
| 47 |
|
| 48 |
}
|
|
@@ -54,30 +51,19 @@ public class FcmTokenServiceImpl implements FcmTokenService {
|
|
| 54 |
return GetFcmTokenMapper.toModelList(fcmCustomer);
|
| 55 |
}
|
| 56 |
|
| 57 |
-
@Override
|
| 58 |
-
public GetOnlineStatusOutput getOnlineStatus(GetOnlineStatusInput input) {
|
| 59 |
-
Boolean isOnline = customerFcmRepository.existsByCustomerNoAndIsOnlineTrue(input.getCustomerNumber());
|
| 60 |
-
return new GetOnlineStatusOutput(isOnline);
|
| 61 |
-
}
|
| 62 |
|
| 63 |
-
private void updateCustomerFcm(CustomerFcm customerFcm, String fcmToken
|
| 64 |
-
// login oluyorsa
|
| 65 |
-
|
| 66 |
-
customerFcm.setFcmToken(fcmToken);
|
| 67 |
-
customerFcm.setIsOnline(true);
|
| 68 |
-
} else {
|
| 69 |
-
customerFcm.setIsOnline(isOnline);
|
| 70 |
-
}
|
| 71 |
customerFcmRepository.save(customerFcm);
|
| 72 |
}
|
| 73 |
|
| 74 |
-
private void saveCustomerFcm(String customerNo,String chanel,
|
| 75 |
var customerFcm = CustomerFcm.builder()
|
| 76 |
.uid(GenerateUtil.generateSession())
|
| 77 |
.customerNo(customerNo)
|
| 78 |
.fcmToken(fcmToken)
|
| 79 |
.chanel(chanel)
|
| 80 |
-
.isOnline(isOnline)
|
| 81 |
.build();
|
| 82 |
customerFcmRepository.save(customerFcm);
|
| 83 |
}
|
|
@@ -87,7 +73,7 @@ public class FcmTokenServiceImpl implements FcmTokenService {
|
|
| 87 |
}
|
| 88 |
|
| 89 |
private List<CustomerFcm> getCustomerFcmListByCustomerNo(String customerNo) {
|
| 90 |
-
var customerFcmList = customerFcmRepository.
|
| 91 |
if (!customerFcmList.isEmpty()) {
|
| 92 |
return customerFcmList;
|
| 93 |
}
|
|
|
|
| 7 |
import com.artandscience.security.dao.entity.CustomerFcm;
|
| 8 |
import com.artandscience.security.dao.repository.CustomerFcmRepository;
|
| 9 |
import com.artandscience.security.domain.model.input.SetFcmTokenInput;
|
|
|
|
| 10 |
import com.artandscience.security.domain.model.mapper.GetFcmTokenMapper;
|
| 11 |
import com.artandscience.security.domain.model.output.GetFcmTokenOutput;
|
|
|
|
| 12 |
import com.artandscience.security.domain.service.FcmTokenService;
|
| 13 |
import com.artandscience.security.domain.util.GenerateUtil;
|
| 14 |
import lombok.RequiredArgsConstructor;
|
|
|
|
| 30 |
public void setFcmToken(SetFcmTokenInput input) {
|
| 31 |
|
| 32 |
// customerno ile kayıt varmı bakılır.
|
|
|
|
| 33 |
|
| 34 |
String customerNo = RequestScopeHelper.getCustomerNumber(requestHeaderScope);
|
| 35 |
String chanel = RequestScopeHelper.getChanel(requestHeaderScope);
|
|
|
|
| 37 |
var customerFcm = getCustomerFcmByCustomerNo(customerNo, chanel);
|
| 38 |
|
| 39 |
if (!Objects.isNull(customerFcm)) {
|
| 40 |
+
updateCustomerFcm(customerFcm,input.getFcmToken());
|
| 41 |
} else {
|
| 42 |
+
saveCustomerFcm(customerNo,chanel,input.getFcmToken());
|
| 43 |
}
|
| 44 |
|
| 45 |
}
|
|
|
|
| 51 |
return GetFcmTokenMapper.toModelList(fcmCustomer);
|
| 52 |
}
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
private void updateCustomerFcm(CustomerFcm customerFcm, String fcmToken) {
|
| 56 |
+
// login oluyorsa fcm token güncellenir.
|
| 57 |
+
customerFcm.setFcmToken(fcmToken);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
customerFcmRepository.save(customerFcm);
|
| 59 |
}
|
| 60 |
|
| 61 |
+
private void saveCustomerFcm(String customerNo,String chanel, String fcmToken) {
|
| 62 |
var customerFcm = CustomerFcm.builder()
|
| 63 |
.uid(GenerateUtil.generateSession())
|
| 64 |
.customerNo(customerNo)
|
| 65 |
.fcmToken(fcmToken)
|
| 66 |
.chanel(chanel)
|
|
|
|
| 67 |
.build();
|
| 68 |
customerFcmRepository.save(customerFcm);
|
| 69 |
}
|
|
|
|
| 73 |
}
|
| 74 |
|
| 75 |
private List<CustomerFcm> getCustomerFcmListByCustomerNo(String customerNo) {
|
| 76 |
+
var customerFcmList = customerFcmRepository.getCustomerNo(customerNo);
|
| 77 |
if (!customerFcmList.isEmpty()) {
|
| 78 |
return customerFcmList;
|
| 79 |
}
|
src/main/java/com/artandscience/security/domain/service/impl/OnlineStatusServiceImpl.java
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.security.domain.service.impl;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.security.dao.entity.CustomerOnlineStatus;
|
| 4 |
+
import com.artandscience.security.dao.repository.CustomerOnlineStatusRepository;
|
| 5 |
+
import com.artandscience.security.domain.model.input.OnlineStatusInput;
|
| 6 |
+
import com.artandscience.security.domain.model.input.SaveOnlineStatusInput;
|
| 7 |
+
import com.artandscience.security.domain.model.output.OnlineStatusOutput;
|
| 8 |
+
import com.artandscience.security.domain.service.OnlineStatusService;
|
| 9 |
+
import lombok.RequiredArgsConstructor;
|
| 10 |
+
import org.springframework.stereotype.Service;
|
| 11 |
+
|
| 12 |
+
import java.util.Objects;
|
| 13 |
+
import java.util.UUID;
|
| 14 |
+
|
| 15 |
+
@Service
|
| 16 |
+
@RequiredArgsConstructor
|
| 17 |
+
public class OnlineStatusServiceImpl implements OnlineStatusService {
|
| 18 |
+
|
| 19 |
+
private final CustomerOnlineStatusRepository customerOnlineStatusRepository;
|
| 20 |
+
|
| 21 |
+
@Override
|
| 22 |
+
public OnlineStatusOutput isOnline(OnlineStatusInput input) {
|
| 23 |
+
var isOnline = customerOnlineStatusRepository.isOnlineForCustomerNo(input.getCustomerNumber());
|
| 24 |
+
return OnlineStatusOutput.builder()
|
| 25 |
+
.isOnline(isOnline)
|
| 26 |
+
.build();
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
@Override
|
| 30 |
+
public void saveOnlineStatus(SaveOnlineStatusInput input) {
|
| 31 |
+
var entity = getEntityByCustomerNo(input.getCustomerNumber());
|
| 32 |
+
if (Objects.isNull(entity)) {
|
| 33 |
+
saveOnlineStatus(input.getCustomerNumber());
|
| 34 |
+
} else {
|
| 35 |
+
updateOnlineStatus(input.getIsOnline(), entity);
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
private void updateOnlineStatus(Boolean isOnline, CustomerOnlineStatus customerOnlineStatus) {
|
| 40 |
+
customerOnlineStatus.setIsOnline(isOnline);
|
| 41 |
+
customerOnlineStatusRepository.save(customerOnlineStatus);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
private void saveOnlineStatus(String customerNo) {
|
| 45 |
+
var entity = CustomerOnlineStatus.builder()
|
| 46 |
+
.uid(UUID.randomUUID().toString())
|
| 47 |
+
.isOnline(true)
|
| 48 |
+
.customerNumber(customerNo)
|
| 49 |
+
.build();
|
| 50 |
+
customerOnlineStatusRepository.save(entity);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
private CustomerOnlineStatus getEntityByCustomerNo(String customerNo) {
|
| 54 |
+
return customerOnlineStatusRepository
|
| 55 |
+
.findAllByCustomerNumberEquals(customerNo).orElse(null);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
}
|
src/main/java/com/artandscience/security/domain/util/CookieUtil.java
DELETED
|
@@ -1,41 +0,0 @@
|
|
| 1 |
-
package com.artandscience.security.domain.util;
|
| 2 |
-
|
| 3 |
-
import jakarta.servlet.http.Cookie;
|
| 4 |
-
import jakarta.servlet.http.HttpServletResponse;
|
| 5 |
-
import org.springframework.web.context.request.RequestContextHolder;
|
| 6 |
-
import org.springframework.web.context.request.ServletRequestAttributes;
|
| 7 |
-
|
| 8 |
-
public class CookieUtil {
|
| 9 |
-
|
| 10 |
-
private CookieUtil() {}
|
| 11 |
-
|
| 12 |
-
public static void addCookie(String cookieName, String sessionId, String expireIn) {
|
| 13 |
-
HttpServletResponse resp =
|
| 14 |
-
((ServletRequestAttributes) RequestContextHolder
|
| 15 |
-
.currentRequestAttributes()).getResponse();
|
| 16 |
-
|
| 17 |
-
Cookie cookie = new Cookie(cookieName, sessionId);
|
| 18 |
-
cookie.setHttpOnly(true);
|
| 19 |
-
cookie.setSecure(true);
|
| 20 |
-
cookie.setPath("/");
|
| 21 |
-
cookie.setMaxAge(Integer.parseInt(expireIn));
|
| 22 |
-
assert resp != null;
|
| 23 |
-
resp.addCookie(cookie);
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
public static void removeCookie(String cookieName) {
|
| 27 |
-
HttpServletResponse resp =
|
| 28 |
-
((ServletRequestAttributes) RequestContextHolder
|
| 29 |
-
.currentRequestAttributes()).getResponse();
|
| 30 |
-
|
| 31 |
-
Cookie cookie = new Cookie(cookieName, null);
|
| 32 |
-
cookie.setHttpOnly(true);
|
| 33 |
-
cookie.setSecure(true);
|
| 34 |
-
cookie.setPath("/");
|
| 35 |
-
cookie.setMaxAge(0);
|
| 36 |
-
|
| 37 |
-
assert resp != null;
|
| 38 |
-
resp.addCookie(cookie);
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|