diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/openapi/OpenApiConfig.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/openapi/OpenApiConfig.java index 1b8e032ba..435ae8585 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/openapi/OpenApiConfig.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/openapi/OpenApiConfig.java @@ -25,8 +25,6 @@ import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.security.OAuthFlow; -import io.swagger.v3.oas.models.security.OAuthFlows; import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; import lombok.AllArgsConstructor; diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/security/CustomAuthenticationConverter.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/security/CustomAuthenticationConverter.java index d02c5ad2e..2630d4282 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/security/CustomAuthenticationConverter.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/security/CustomAuthenticationConverter.java @@ -20,6 +20,7 @@ */ package org.eclipse.tractusx.managedidentitywallets.config.security; + import org.springframework.core.convert.converter.Converter; import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.core.GrantedAuthority; @@ -27,9 +28,11 @@ import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter; -import org.springframework.util.CollectionUtils; -import java.util.*; +import java.util.Collection; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; /** @@ -49,18 +52,14 @@ public CustomAuthenticationConverter(String resourceId) { this.resourceId = resourceId; grantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter(); } - @Override public AbstractAuthenticationToken convert(Jwt source) { - Collection convert = grantedAuthoritiesConverter.convert(source); - if (!CollectionUtils.isEmpty(convert)) { - Collection authorities = new HashSet<>(convert); - authorities.addAll(extractResourceRoles(source, resourceId)); - extractResourceRoles(source, resourceId); - return new JwtAuthenticationToken(source, authorities); - } else { - return new JwtAuthenticationToken(source, Collections.emptyList()); - } + Collection authorities = (grantedAuthoritiesConverter.convert(source)) + .stream() + .collect(Collectors.toSet()); + authorities.addAll(extractResourceRoles(source, resourceId)); + extractResourceRoles(source, resourceId); + return new JwtAuthenticationToken(source, authorities); } private Collection extractResourceRoles(Jwt jwt, String resourceId) { diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/HoldersCredentialService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/HoldersCredentialService.java index 78b04f8aa..664cff8dc 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/HoldersCredentialService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/HoldersCredentialService.java @@ -104,11 +104,11 @@ public PageImpl getCredentials(String credentialId, String //Holder must be caller of API Wallet holderWallet = commonService.getWalletByIdentifier(callerBPN); - filterRequest.appendCriteria(StringPool.HOLDER_DID, Operator.EQUALS, holderWallet.getDid().toString()); + filterRequest.appendCriteria(StringPool.HOLDER_DID, Operator.EQUALS, holderWallet.getDid()); if (StringUtils.hasText(issuerIdentifier)) { Wallet issuerWallet = commonService.getWalletByIdentifier(issuerIdentifier); - filterRequest.appendCriteria(StringPool.ISSUER_DID, Operator.EQUALS, issuerWallet.getDid().toString()); + filterRequest.appendCriteria(StringPool.ISSUER_DID, Operator.EQUALS, issuerWallet.getDid()); } if (StringUtils.hasText(credentialId)) { diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletService.java index 9b546abe6..0de7d4a83 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletService.java @@ -237,8 +237,8 @@ private Wallet createWallet(CreateWalletRequest request, boolean authority) { //Save key walletKeyService.getRepository().save(WalletKey.builder() .walletId(wallet.getId()) - .referenceKey("dummy ref key") //TODO removed once vault setup is ready - .vaultAccessToken("dummy vault access token") ////TODO removed once vault setup is ready + .referenceKey("dummy ref key, removed once vault setup is ready") + .vaultAccessToken("dummy vault access token, removed once vault setup is ready") .privateKey(encryptionUtils.encrypt(getPrivateKeyString(keyPair.getPrivateKey().asByte()))) .publicKey(encryptionUtils.encrypt(getPublicKeyString(keyPair.getPublicKey().asByte()))) .build()); @@ -277,24 +277,6 @@ private void validateCreateWallet(CreateWalletRequest request) { } } -/* - @SneakyThrows - private Ed25519KeySet createKeyPair() { - KeyPairGeneratorSpi.Ed25519 ed25519 = new KeyPairGeneratorSpi.Ed25519(); - ed25519.initialize(256, new SecureRandom()); - KeyPair keyPair = ed25519.generateKeyPair(); - PublicKey PubKey = keyPair.getPublic(); - PrivateKey PivKey = keyPair.getPrivate(); - Ed25519PrivateKeyParameters ed25519PrivateKeyParameters = - (Ed25519PrivateKeyParameters) PrivateKeyFactory.createKey(PivKey.getEncoded()); - Ed25519PublicKeyParameters publicKeyParameters = - (Ed25519PublicKeyParameters) PublicKeyFactory.createKey(PubKey.getEncoded()); - - byte[] privateKeyBytes = ed25519PrivateKeyParameters.getEncoded(); - byte[] publicKeyBytes = publicKeyParameters.getEncoded(); - return new Ed25519KeySet(privateKeyBytes, publicKeyBytes); - }*/ - @SneakyThrows private String getPrivateKeyString(byte[] privateKeyBytes) { StringWriter stringWriter = new StringWriter(); diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/StringToDidDocumentConverter.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/StringToDidDocumentConverter.java index 87ac6f807..5dd273291 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/StringToDidDocumentConverter.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/StringToDidDocumentConverter.java @@ -25,9 +25,6 @@ import lombok.SneakyThrows; import org.eclipse.tractusx.ssi.lib.model.did.DidDocument; -import java.net.URLDecoder; -import java.nio.charset.StandardCharsets; - /** * The type String to did document converter. */