Skip to content

Commit

Permalink
Merge pull request #6 from ren2003u/apply-sdk-java
Browse files Browse the repository at this point in the history
fix the known bugs.
  • Loading branch information
wzzc-dev committed Oct 26, 2023
2 parents cbc5dbf + 67d35e0 commit 8b1cbc3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>io.github.ren2003u</groupId>
<artifactId>platform-sdk-java</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.github.ren2003u</groupId>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import space.ao.services.config.ApplicationProperties;
import space.ao.services.support.OperationUtils;
import space.ao.services.support.platform.info.registry.ClientRegistryInfo;
import space.ao.services.support.platform.info.registry.ClientRegistryResult;
import space.ao.services.support.platform.info.registry.UserRegistryInfo;
import space.ao.services.support.platform.info.registry.UserRegistryResult;
import space.ao.services.support.platform.info.token.TokenVerifySignInfo;
import space.ao.services.support.security.SecurityUtils;

import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Base64;
import java.util.List;

@ApplicationScoped
Expand All @@ -26,6 +31,11 @@ public class PlatformClient {
@Inject
ApplicationProperties properties;

@Inject
SecurityUtils securityUtils;

@Inject
OperationUtils utils;
private String host;
private Client client;

Expand All @@ -49,6 +59,8 @@ private void init() {
public UserRegistryResult registerUser(String requestId, UserRegistryInfo userRegistryInfo) {
init();
try {
LOG.info("requestId:{}",requestId);
LOG.info("UserRegistryInfo:{}",userRegistryInfo);
// Obtain BoxRegKey
String boxRegKey = obtainBoxRegKey(requestId);
if (boxRegKey == null) {
Expand All @@ -69,6 +81,7 @@ public UserRegistryResult registerUser(String requestId, UserRegistryInfo userRe
}
}
public ClientRegistryResult registerClient(String requestId, ClientRegistryInfo clientRegistryInfo, String userId) {
init();
try {
// Obtain BoxRegKey
String boxRegKey = obtainBoxRegKey(requestId);
Expand All @@ -91,13 +104,17 @@ public ClientRegistryResult registerClient(String requestId, ClientRegistryInfo
}

private String obtainBoxRegKey(String requestId) {
init();
try {
// Check if the cache is still valid
if (cachedBoxRegKey != null && lastFetchedTime != null && Duration.between(lastFetchedTime, LocalDateTime.now()).compareTo(CACHE_DURATION) <= 0) {
return cachedBoxRegKey;
}

ApiResponse<ObtainBoxRegKeyResponse> response = client.obtainBoxRegKey(properties.boxUuid(), List.of("10001"), requestId);
var sign = securityUtils.getSecurityProvider().signUsingBoxPrivateKey(requestId,
Base64.getEncoder().encodeToString(
utils.objectToJson(TokenVerifySignInfo.of(properties.boxUuid(), List.of("10001")))
.getBytes(StandardCharsets.UTF_8)));
ApiResponse<ObtainBoxRegKeyResponse> response = client.obtainBoxRegKey(properties.boxUuid(), List.of("10001"), requestId,sign);
if (response.getError() != null) {
LOG.error("Error obtaining BoxRegKey: {}", response.getError().getMessage());
return null;
Expand All @@ -114,6 +131,7 @@ private String obtainBoxRegKey(String requestId) {
}
}
public void deleteUser(String requestId, String userId) {
init();
try {
// Obtain BoxRegKey
String boxRegKey = obtainBoxRegKey(requestId);
Expand All @@ -129,6 +147,7 @@ public void deleteUser(String requestId, String userId) {
}
}
public void deleteClient(String requestId, String userId, String clientUUID) {
init();
try {
// Obtain BoxRegKey
String boxRegKey = obtainBoxRegKey(requestId);
Expand Down

0 comments on commit 8b1cbc3

Please sign in to comment.