Skip to content

Commit

Permalink
fix: sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-vavdiya committed Sep 5, 2024
1 parent ec8bb00 commit b1c5417
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,7 @@ private boolean validateCredential(VerifiableCredential credential) {
final DidResolver resolver = didDocumentResolverService.getCompositeDidResolver();
final LinkedDataProofValidation linkedDataProofValidation = LinkedDataProofValidation.newInstance(resolver);
final boolean isValid = linkedDataProofValidation.verify(credential);

if (isValid) {
log.debug("Credential validation result: (valid: {}, credential-id: {})", isValid, credential.getId());
} else {
log.info("Credential validation result: (valid: {}, credential-id: {})", isValid, credential.getId());
}
log.info("Credential validation result: (valid: {}, credential-id: {})", isValid, credential.getId());
return isValid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,7 @@ private void validateCreateWallet(CreateWalletRequest request, String callerBpn)
}


@RequiredArgsConstructor
private class WalletKeyInfo {
private final String keyId;
private final KeyPair keyPair;
private final SupportedAlgorithms algorithm;
private final VerificationMethod verificationMethod;
private record WalletKeyInfo(String keyId, KeyPair keyPair, SupportedAlgorithms algorithm,
VerificationMethod verificationMethod) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private SignedJWT generateJwtPresentation(PresentationCreationConfig config, byt

private VerifiablePresentation generateJsonLdPresentation(PresentationCreationConfig config, byte[] privateKeyBytes) throws UnsupportedSignatureTypeException, InvalidPrivateKeyFormatException, SignatureGenerateFailedException, TransformJsonLdException {
VerifiablePresentationBuilder verifiablePresentationBuilder =
new VerifiablePresentationBuilder().id(URI.create(config.getVpIssuerDid() + "#" + UUID.randomUUID().toString()))
new VerifiablePresentationBuilder().id(URI.create(config.getVpIssuerDid() + "#" + UUID.randomUUID()))
.type(List.of(VerifiablePresentationType.VERIFIABLE_PRESENTATION))
.verifiableCredentials(config.getVerifiableCredentials());

Expand Down Expand Up @@ -339,7 +339,7 @@ private SignedJWT buildED25519(PresentationCreationConfig config, byte[] private
SerializedJwtPresentationFactory presentationFactory = new SerializedJwtPresentationFactoryImpl(
new SignedJwtFactory(new OctetKeyPairFactory()), new JsonLdSerializerImpl(), config.getVpIssuerDid());

X25519PrivateKey privateKey = null;
X25519PrivateKey privateKey;
try {
privateKey = new X25519PrivateKey(privateKeyBytes);
} catch (InvalidPrivateKeyFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,15 @@ private static String getJwtToken(String username) {
.clientId(StringPool.CLIENT_ID)
.clientSecret(StringPool.CLIENT_SECRET)
.username(username)
.password(StringPool.USER_PASSWORD)
.password(getUserPassword())
.build();
String access_token = keycloakAdminClient.tokenManager().getAccessToken().getToken();

return StringPool.BEARER_SPACE + access_token;
}

@NotNull
private static String getUserPassword() {
return "s3cr3t";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public ResponseEntity<Map<String, String>> verifyRevocation(
/**
* The function `getCredentialsByIssuerId` retrieves a list of credentials by their issuer ID.
*
* @param issuerId The `issuerId` parameter is a string that represents the identifier of the
* @param issuerBPN The `issuerBPN` parameter is a string that represents the BPn of the
* issuer.
* @return The method is returning a ResponseEntity object that wraps a VerifiableCredential
* object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ public boolean isValid(VerifiableCredential credential, ConstraintValidatorConte
// Assuming 'id' within 'credentialSubject' is the field to be validated as a URI
@NonNull
List<VerifiableCredentialSubject> credentialSubject = credential.getCredentialSubject();
if (credentialSubject != null) {
if (!validateCredentialSubject(credentialSubject, context)) {
return false;
}
}
return validateCredentialSubject(credentialSubject, context);

// Additional validation checks can be added here, e.g., checking the proof object

return true;
}

private boolean validateCredentialSubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@

class CustomAuthenticationConverterTest {

private static String VALID =
private static final String VALID =
"eyJhbGciOiJSUzI1NiIsImFscGhhIjoiZzB1ZjNycjlycnN2cHlhcTVuamg4In0.eyJpc3MiOiJEaW5vQ2hpZXNhLmdpdGh1Yi5pbyIsInN1YiI6Im1heGluZSIsImF1ZCI6ImlkcmlzIiwiaWF0IjoxNzAyNjUwMTc2LCJleHAiOjE3MDI2NTA3NzYsInJlc291cmNlX2FjY2VzcyI6eyJyZXNvdXJjZUlkIjp7InJvbGVzIjpbImRlaV9tdWRhIl19fX0.wTv9GBX3AuRO8UIsAuu2YJU77ai-wchDyxRn-_yX9PeHt23vCmp_JAbkkdMdyLAWWOKncjgNeG-4lB9RCBsjmbdb1imujUrAocp3VZQqNg6OVaNV58kdsIpNNF9S8XlFI4hr1BANrw2rWJDkTRu1id-Fu-BVE1BF7ySCKHS_NaY3e7yXQM-jtU63z5FBpPvfMF-La3blPle93rgut7V3LlG-tNOp93TgFzGrQQXuJUsew34T0u4OlQa3TjQuMdZMTy0SVSLSpIzAqDsAkHv34W6SdY1p6FVQ14TfawRLkrI2QY-YM_dCFAEE7KqqnUrVVyw6XG1ydeFDuX8SJuQX7g";

private static String MISSING_RESOURCE_ID =
private static final String MISSING_RESOURCE_ID =
"{\n" + " \"resource_access\": {\n" + " }\n" + "}";

private static String MISSING_ROLES =
private static final String MISSING_ROLES =
"{\n"
+ " \"resource_access\": {\n"
+ " \"resourceId\": {\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.BitSet;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -104,6 +104,6 @@ void encodeToStringAndDecodeFromString_AreReversible() {

byte[] decodedData = BitSetManager.decodeFromString(encoded);
assertNotNull(decodedData);
assertTrue(Arrays.equals(originalData, decodedData));
assertArrayEquals(originalData, decodedData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public class StringPool {
public static final String CLIENT_SECRET = "miw_private_client_secret";

public static final String REALM = "miw_test";

public static final String USER_PASSWORD = "s3cr3t";

public static final String VALID_USER_NAME = "valid_user";

public static final String INVALID_USER_NAME = "invalid_user";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum SupportedAlgorithms {
ED25519("ED25519"),
ES256K("ES256K");

private String value;
private final String value;

SupportedAlgorithms(String value) {
this.value = value;
Expand Down

0 comments on commit b1c5417

Please sign in to comment.