Skip to content

Commit

Permalink
feat: handle read RSA key
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-PhucNguyen5 committed Oct 2, 2023
1 parent ced99ff commit 3ba0b41
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 84 deletions.
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ services:
- KEYCLOAK_ROLE_MAPPING=${KEYCLOAK_ROLE_MAPPING}
- KEYCLOAK_BEARER_ONLY=${KEYCLOAK_BEARER_ONLY}

- RSA_PUBLIC_KEY_AUTH=${RSA_PUBLIC_KEY_AUTH}
- RSA_PRIVATE_KEY_MAIL=${RSA_PRIVATE_KEY_MAIL}
- RSA_PUBLIC_KEY_MAIL=${RSA_PUBLIC_KEY_MAIL}

ports:
- "${PORT}:8080"
volumes:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<version.eddsa>0.3.0</version.eddsa>
<version.springdoc-webmvc-ui>2.1.0</version.springdoc-webmvc-ui>
<version.github-classgraph>4.8.157</version.github-classgraph>
<version.explorer-common>0.1.2-SNAPSHOT</version.explorer-common>
<version.explorer-common>0.1.2-SNAPSHOT-PR38</version.explorer-common>
<version.mapstruct>1.5.3.Final</version.mapstruct>
<version.springdoc-openapi-common>1.7.0</version.springdoc-openapi-common>
<version.lettuce-core>6.2.3.RELEASE</version.lettuce-core>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.cardanofoundation.authentication.provider.RsaProvider;
import org.cardanofoundation.explorer.common.utils.RsaUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

Expand All @@ -17,25 +17,23 @@
@RequiredArgsConstructor
public class RsaConfig {

private String publicKeyAuthPath;
private String publicAuth;

private String privateKeyMailPath;
private String privateMail;

private String publicKeyMailPath;
private String publicMail;

private PublicKey publicKeyAuth;

private PrivateKey privateKeyMail;

private PublicKey publicKeyMail;

private final RsaProvider rsaProvider;

@PostConstruct
public void createRsaKey() {
java.security.Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
publicKeyAuth = rsaProvider.getPublicKey(publicKeyAuthPath);
privateKeyMail = rsaProvider.getPrivateKey(privateKeyMailPath);
publicKeyMail = rsaProvider.getPublicKey(publicKeyMailPath);
publicKeyAuth = RsaUtils.getPublicKey(publicAuth);
privateKeyMail = RsaUtils.getPrivateKey(privateMail);
publicKeyMail = RsaUtils.getPublicKey(publicMail);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ public BasePageResponse<BookMarkResponse> findBookMarkByType(
Map<String, List<String>> attributes = user.getAttributes();
String bookmarkKey = CommonConstant.ATTRIBUTE_BOOKMARK + network + "_" + bookMarkType;
List<BookMarkResponse> bookMarkResponseList = new ArrayList<>();
List<String> bookmarkList = new ArrayList<>();
List<String> bookmarkList;
int size = 0;
if (Objects.nonNull(attributes) && Objects.nonNull(attributes.get(bookmarkKey))) {
bookmarkList = attributes.get(bookmarkKey);
bookmarkList.forEach(value -> bookMarkResponseList.add(
size = bookmarkList.size();
int start = (int) pageable.getOffset();
int end = Math.min((start + pageable.getPageSize()), size);
List<String> bookmarkPage = bookmarkList.subList(start, end);
bookmarkPage.forEach(value -> bookMarkResponseList.add(
BookMarkResponse.builder().keyword(
StringUtils.substringBefore(value, CommonConstant.ATTRIBUTE_BOOKMARK_ADD_TIME))
.createdDate(Instant.parse(
Expand All @@ -93,7 +98,7 @@ public BasePageResponse<BookMarkResponse> findBookMarkByType(
.network(network)
.build()));
}
response.setTotalItems(bookmarkList.size());
response.setTotalItems(size);
response.setData(bookMarkResponseList);
return response;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ keycloak:
bearer-only: ${KEYCLOAK_BEARER_ONLY:true}

timeToLiveRedisSignOut: ${TIME_TO_LIVE_REDIS_SIGN_OUT:48}

rsa:
key:
public-auth: ${RSA_PUBLIC_KEY_AUTH}
private-mail: ${RSA_PRIVATE_KEY_MAIL}
public-mail: ${RSA_PUBLIC_KEY_MAIL}
8 changes: 7 additions & 1 deletion src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ keycloak:
use-resource-role-mappings: ${KEYCLOAK_ROLE_MAPPING:true}
bearer-only: ${KEYCLOAK_BEARER_ONLY:true}

timeToLiveRedisSignOut: ${TIME_TO_LIVE_REDIS_SIGN_OUT:48}
timeToLiveRedisSignOut: ${TIME_TO_LIVE_REDIS_SIGN_OUT:48}

rsa:
key:
public-auth: ${RSA_PUBLIC_KEY_AUTH}
private-mail: ${RSA_PRIVATE_KEY_MAIL}
public-mail: ${RSA_PUBLIC_KEY_MAIL}
6 changes: 0 additions & 6 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ logging:
level:
root: info

rsa:
key:
public-key-auth-path: /key/auth/public_key
private-key-mail-path: /key/mail/private_key
public-key-mail-path: /key/mail/public_key

mail:
from: 'test.sotatek1@gmail.com'
sender: 'Sotatek'
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/key/auth/public_key

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/key/mail/private_key

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/key/mail/public_key

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand Down Expand Up @@ -65,6 +66,16 @@ void whenCallExistEmail() throws Exception {
.andDo(print());
}

@Test
void whenCallRoleMapping() throws Exception {
given(keycloakService.roleMapping("resourcePathTest")).willReturn(true);
mockMvc.perform(post("/api/v1/user/role-mapping")
.content("resourcePathTest")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(print());
}

private String asJsonString(final Object obj) {
try {
return new Gson().toJson(obj);
Expand Down

0 comments on commit 3ba0b41

Please sign in to comment.