Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit e00620d

Browse files
committed
fix: formatting
1 parent 697ff85 commit e00620d

17 files changed

+125
-112
lines changed

src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/CredentialVerificationRequest.java

+16-17
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,21 @@
1919
* ******************************************************************************
2020
*/
2121

22-
package org.eclipse.tractusx.managedidentitywallets.dto;
22+
package org.eclipse.tractusx.managedidentitywallets.dto;
2323

24-
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;
25-
26-
import java.util.LinkedHashMap;
27-
import java.util.Map;
28-
29-
public class CredentialVerificationRequest extends LinkedHashMap<String, Object> {
30-
31-
32-
public void setJwt(String jwt) {
33-
put(StringPool.VC_JWT_KEY, jwt);
34-
}
24+
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;
25+
26+
import java.util.LinkedHashMap;
27+
import java.util.Map;
3528

36-
public void setVc(Map<String,Object> vc) {
37-
putAll(vc);
38-
}
39-
}
40-
29+
public class CredentialVerificationRequest extends LinkedHashMap<String, Object> {
30+
31+
32+
public void setJwt(String jwt) {
33+
put(StringPool.VC_JWT_KEY, jwt);
34+
}
35+
36+
public void setVc(Map<String, Object> vc) {
37+
putAll(vc);
38+
}
39+
}

src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/CredentialsResponse.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public void setJwt(String jwt) {
3232
put(StringPool.VC_JWT_KEY, jwt);
3333
}
3434

35-
public void setVc(Map<String,Object> vc) {
35+
public void setVc(Map<String, Object> vc) {
3636
putAll(vc);
3737
}
38-
38+
3939
}

src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/IssueMembershipCredentialRequest.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* ******************************************************************************
2020
*/
2121

22-
package org.eclipse.tractusx.managedidentitywallets.dto;
22+
package org.eclipse.tractusx.managedidentitywallets.dto;
2323

2424
import com.fasterxml.jackson.annotation.JsonProperty;
2525
import jakarta.validation.constraints.NotBlank;
@@ -34,18 +34,18 @@
3434
/**
3535
* The type Issue membership credential request.
3636
*/
37-
@Getter
38-
@Setter
39-
@NoArgsConstructor
40-
@Builder
41-
@AllArgsConstructor
42-
public class IssueMembershipCredentialRequest {
37+
@Getter
38+
@Setter
39+
@NoArgsConstructor
40+
@Builder
41+
@AllArgsConstructor
42+
public class IssueMembershipCredentialRequest {
4343

44-
@NotBlank(message = "Please provide BPN")
45-
@Pattern(regexp = StringPool.BPN_NUMBER_REGEX, message = "Please provide valid BPN")
46-
private String bpn;
44+
@NotBlank(message = "Please provide BPN")
45+
@Pattern(regexp = StringPool.BPN_NUMBER_REGEX, message = "Please provide valid BPN")
46+
private String bpn;
4747

4848
@JsonProperty("asJwt")
4949
private boolean asJwt;
50-
}
50+
}
5151

src/main/java/org/eclipse/tractusx/managedidentitywallets/service/CommonService.java

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.eclipse.tractusx.managedidentitywallets.exception.WalletNotFoundProblem;
3030
import org.eclipse.tractusx.managedidentitywallets.utils.CommonUtils;
3131
import org.eclipse.tractusx.managedidentitywallets.utils.Validate;
32-
import org.eclipse.tractusx.ssi.lib.exception.did.DidParseException;
3332
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential;
3433
import org.springframework.stereotype.Service;
3534

src/main/java/org/eclipse/tractusx/managedidentitywallets/service/HoldersCredentialService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public PageImpl<CredentialsResponse> getCredentials(GetCredentialsCommand comman
130130
for (HoldersCredential credential : filter.getContent()) {
131131
CredentialsResponse cr = new CredentialsResponse();
132132
if (command.isAsJwt()) {
133-
cr.setJwt(CommonUtils.vcAsJwt(command.getIdentifier() != null ? commonService.getWalletByIdentifier(command.getIdentifier()) : holderWallet , holderWallet, credential.getData(), walletKeyService));
133+
cr.setJwt(CommonUtils.vcAsJwt(command.getIdentifier() != null ? commonService.getWalletByIdentifier(command.getIdentifier()) : holderWallet, holderWallet, credential.getData(), walletKeyService));
134134
} else {
135135
cr.setVc(credential.getData());
136136
}
@@ -176,7 +176,7 @@ public CredentialsResponse issueCredential(Map<String, Object> data, String call
176176

177177
// Return VC
178178
if (asJwt) {
179-
cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, commonService.getWalletByIdentifier(callerBpn), credential.getData() , walletKeyService));
179+
cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, commonService.getWalletByIdentifier(callerBpn), credential.getData(), walletKeyService));
180180
} else {
181181
cr.setVc(credential.getData());
182182
}

src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public CredentialsResponse issueFrameworkCredential(IssueFrameworkCredentialRequ
260260

261261
// Return VC
262262
if (asJwt) {
263-
cr.setJwt(CommonUtils.vcAsJwt(baseWallet, holderWallet, issuersCredential.getData() , walletKeyService));
263+
cr.setJwt(CommonUtils.vcAsJwt(baseWallet, holderWallet, issuersCredential.getData(), walletKeyService));
264264
} else {
265265
cr.setVc(issuersCredential.getData());
266266
}
@@ -279,7 +279,7 @@ public CredentialsResponse issueFrameworkCredential(IssueFrameworkCredentialRequ
279279
* @return the verifiable credential
280280
*/
281281
@Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED)
282-
public CredentialsResponse issueDismantlerCredential(IssueDismantlerCredentialRequest request, boolean asJwt, String callerBPN) {
282+
public CredentialsResponse issueDismantlerCredential(IssueDismantlerCredentialRequest request, boolean asJwt, String callerBPN) {
283283

284284
//Fetch Holder Wallet
285285
Wallet holderWallet = commonService.getWalletByIdentifier(request.getBpn());
@@ -320,7 +320,7 @@ public CredentialsResponse issueDismantlerCredential(IssueDismantlerCredentialRe
320320

321321
// Return VC
322322
if (asJwt) {
323-
cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, holderWallet, issuersCredential.getData() , walletKeyService));
323+
cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, holderWallet, issuersCredential.getData(), walletKeyService));
324324
} else {
325325
cr.setVc(issuersCredential.getData());
326326
}
@@ -383,7 +383,7 @@ public CredentialsResponse issueMembershipCredential(IssueMembershipCredentialRe
383383

384384
// Return VC
385385
if (asJwt) {
386-
cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, holderWallet, issuersCredential.getData() , walletKeyService));
386+
cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, holderWallet, issuersCredential.getData(), walletKeyService));
387387
} else {
388388
cr.setVc(issuersCredential.getData());
389389
}
@@ -441,7 +441,7 @@ public CredentialsResponse issueCredentialUsingBaseWallet(String holderDid, Map<
441441

442442
// Return VC
443443
if (asJwt) {
444-
cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, holderWallet, issuersCredential.getData() , walletKeyService));
444+
cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, holderWallet, issuersCredential.getData(), walletKeyService));
445445
} else {
446446
cr.setVc(issuersCredential.getData());
447447
}
@@ -518,7 +518,7 @@ public Map<String, Object> credentialsValidation(CredentialVerificationRequest v
518518
* @return the map
519519
*/
520520
@SneakyThrows
521-
public Map<String, Object> credentialsValidation(CredentialVerificationRequest verificationRequest, boolean withCredentialsValidation , boolean withCredentialExpiryDate) {
521+
public Map<String, Object> credentialsValidation(CredentialVerificationRequest verificationRequest, boolean withCredentialsValidation, boolean withCredentialExpiryDate) {
522522
HttpClient httpClient = HttpClient.newBuilder()
523523
.followRedirects(HttpClient.Redirect.ALWAYS)
524524
.build();

src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ public Map<String, Object> createPresentation(Map<String, Object> data, boolean
145145
return buildVP(asJwt, audience, callerBpn, callerWallet, verifiableCredentials, SupportedAlgorithms.ED25519);
146146
}
147147

148-
private Map<String, Object> buildVP(boolean asJwt, String audience, String callerBpn, Wallet callerWallet,
149-
List<VerifiableCredential> verifiableCredentials, SupportedAlgorithms algorithm){
148+
private Map<String, Object> buildVP(boolean asJwt, String audience, String callerBpn, Wallet callerWallet, List<VerifiableCredential> verifiableCredentials, SupportedAlgorithms algorithm) {
150149
Map<String, Object> response = new HashMap<>();
151150
if (asJwt && algorithm.equals(SupportedAlgorithms.ES256K)) {
152151
buildVPJwtES256K(audience, callerBpn, callerWallet, verifiableCredentials, algorithm, response);
@@ -172,7 +171,7 @@ private void buildVPJsonLd(String callerBpn, List<VerifiableCredential> verifiab
172171
response.put(StringPool.VP, verifiablePresentation);
173172
}
174173

175-
@SneakyThrows({ InvalidPrivateKeyFormatException.class})
174+
@SneakyThrows({ InvalidPrivateKeyFormatException.class })
176175
private void buildVPJwtEdDSA(String audience, String callerBpn, Wallet callerWallet, List<VerifiableCredential> verifiableCredentials, SupportedAlgorithms algorithm, Map<String, Object> response) {
177176
Pair<Did, Object> result = getPrivateKey(callerWallet, algorithm, audience, callerBpn);
178177
String keyId = walletKeyService.getWalletKeyIdByWalletId(callerWallet.getId());
@@ -182,7 +181,7 @@ private void buildVPJwtEdDSA(String audience, String callerBpn, Wallet callerWal
182181

183182
X25519PrivateKey ed25519Key = (X25519PrivateKey) result.getRight();
184183
X25519PrivateKey privateKey = new X25519PrivateKey(ed25519Key.asByte());
185-
SignedJWT presentation = presentationFactory.createPresentation(result.getLeft(), verifiableCredentials, audience, privateKey , keyId);
184+
SignedJWT presentation = presentationFactory.createPresentation(result.getLeft(), verifiableCredentials, audience, privateKey, keyId);
186185
response.put(StringPool.VP, presentation.serialize());
187186
}
188187

src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletKeyService.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected SpecificationUtil<WalletKey> getSpecificationUtil() {
6868
/**
6969
* Get private key by wallet identifier as bytes byte [ ].
7070
*
71-
* @param walletId the wallet id
71+
* @param walletId the wallet id
7272
* @param algorithm the algorithm
7373
* @return the byte [ ]
7474
*/
@@ -85,7 +85,7 @@ public byte[] getPrivateKeyByWalletIdAsBytes(long walletId, String algorithm) {
8585
/**
8686
* Gets private key by wallet identifier.
8787
*
88-
* @param walletId the wallet id
88+
* @param walletId the wallet id
8989
* @param algorithm the algorithm
9090
* @return the private key by wallet identifier
9191
*/
@@ -104,8 +104,8 @@ public Object getPrivateKeyByWalletIdAndAlgorithm(long walletId, SupportedAlgori
104104
}
105105
}
106106

107-
/**
108-
* Gets wallet key by wallet id.
107+
/**
108+
* Gets wallet key by wallet id.
109109
*
110110
* @param walletId the wallet id
111111
* @return the wallet key by wallet identifier

src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CommonUtils.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ public static String getIdentifierType(String identifier) {
9999
* @param holderDid the holder did
100100
* @return the credential
101101
*/
102-
public static HoldersCredential getHoldersCredential(VerifiableCredentialSubject subject, List<String> types,
103-
DidDocument issuerDoc,
104-
byte[] privateKeyBytes, String holderDid, List<URI> contexts, Date expiryDate, boolean selfIssued) {
102+
public static HoldersCredential getHoldersCredential(VerifiableCredentialSubject subject, List<String> types, DidDocument issuerDoc, byte[] privateKeyBytes, String holderDid, List<URI> contexts, Date expiryDate, boolean selfIssued) {
105103
List<String> cloneTypes = new ArrayList<>(types);
106104

107105
// Create VC
@@ -121,11 +119,8 @@ public static HoldersCredential getHoldersCredential(VerifiableCredentialSubject
121119
.build();
122120
}
123121

124-
@SneakyThrows({UnsupportedSignatureTypeException.class , InvalidPrivateKeyFormatException.class , SignatureGenerateFailedException.class , TransformJsonLdException.class})
125-
private static VerifiableCredential createVerifiableCredential(DidDocument issuerDoc,
126-
List<String> verifiableCredentialType,
127-
VerifiableCredentialSubject verifiableCredentialSubject,
128-
byte[] privateKey, List<URI> contexts, Date expiryDate) {
122+
@SneakyThrows({ UnsupportedSignatureTypeException.class, InvalidPrivateKeyFormatException.class, SignatureGenerateFailedException.class, TransformJsonLdException.class })
123+
private static VerifiableCredential createVerifiableCredential(DidDocument issuerDoc, List<String> verifiableCredentialType, VerifiableCredentialSubject verifiableCredentialSubject, byte[] privateKey, List<URI> contexts, Date expiryDate) {
129124
// VC Builder
130125

131126
// if the credential does not contain the JWS proof-context add it
@@ -180,8 +175,9 @@ public static SecureTokenRequest getSecureTokenRequest(MultiValueMap<String, Str
180175
Map<String, String> singleValueMap = map.toSingleValueMap();
181176
return objectMapper.convertValue(singleValueMap, SecureTokenRequest.class);
182177
}
183-
@SneakyThrows({DidParseException.class})
184-
public static String vcAsJwt(Wallet issuerWallet, Wallet holderWallet, VerifiableCredential vc , WalletKeyService walletKeyService){
178+
179+
@SneakyThrows({ DidParseException.class })
180+
public static String vcAsJwt(Wallet issuerWallet, Wallet holderWallet, VerifiableCredential vc, WalletKeyService walletKeyService) {
185181

186182
Did issuerDid = DidParser.parse(issuerWallet.getDid());
187183
Did holderDid = DidParser.parse(holderWallet.getDid());

src/test/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialServiceTest.java

+12-15
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ public static void beforeAll() throws SQLException {
135135
walletKeyService,
136136
holdersCredentialRepository,
137137
commonService,
138-
objectMapper
139-
);
138+
objectMapper);
140139
}
141140

142141
@BeforeEach
@@ -174,10 +173,10 @@ void shouldIssueCredentialAsJwt()
174173
when(walletKey.getKeyId()).thenReturn(KEY_ID);
175174
when(walletKey.getId()).thenReturn(42L);
176175
when(baseWallet.getAlgorithm()).thenReturn("ED25519");
177-
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
176+
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId(), SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
178177
.thenReturn(new X25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
179178
when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId);
180-
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey()
179+
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId(), "ED25519")).thenReturn(keyPair.getPrivateKey()
181180
.asByte());
182181
CredentialsResponse credentialsResponse = assertDoesNotThrow(
183182
() -> issuersCredentialService.issueMembershipCredential(
@@ -225,9 +224,9 @@ void shouldIssueCredentialAsJwt()
225224
when(walletKey.getKeyId()).thenReturn(KEY_ID);
226225
when(walletKey.getId()).thenReturn(42L);
227226
when(baseWallet.getAlgorithm()).thenReturn("ED25519");
228-
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey()
227+
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId(), "ED25519")).thenReturn(keyPair.getPrivateKey()
229228
.asByte());
230-
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
229+
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId(), SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
231230
.thenReturn(new X25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
232231
when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId);
233232

@@ -266,10 +265,9 @@ void shouldIssueCredentialAsJwt() throws IOException, InvalidPrivateKeyFormatExc
266265
when(walletKey.getKeyId()).thenReturn(KEY_ID);
267266
when(walletKey.getId()).thenReturn(42L);
268267
when(baseWallet.getAlgorithm()).thenReturn("ED25519");
269-
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
268+
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId(), SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
270269
.thenReturn(new X25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
271-
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey()
272-
.asByte());
270+
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId(), "ED25519")).thenReturn(keyPair.getPrivateKey().asByte());
273271
when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId);
274272

275273
CredentialsResponse credentialsResponse = assertDoesNotThrow(
@@ -301,7 +299,7 @@ void shouldIssueCredentialAsJwt() throws IOException, ParseException, InvalidPri
301299
MockUtil.generateDid("basewallet")).build();
302300

303301
MockUtil.makeCreateWorkForIssuer(issuersCredentialRepository);
304-
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey()
302+
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId(), "ED25519")).thenReturn(keyPair.getPrivateKey()
305303
.asByte());
306304
when(commonService.getWalletByIdentifier(holderWalletBpn)).thenReturn(holderWallet);
307305
when(commonService.getWalletByIdentifier(verifiableCredential.getIssuer()
@@ -321,7 +319,7 @@ public HoldersCredential answer(InvocationOnMock invocation) throws Throwable {
321319
when(walletKey.getKeyId()).thenReturn(KEY_ID);
322320
when(baseWallet.getAlgorithm()).thenReturn("ED25519");
323321
when(walletKey.getId()).thenReturn(42L);
324-
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
322+
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId(), SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
325323
.thenReturn(new X25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
326324
when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId);
327325

@@ -343,9 +341,8 @@ class jwtValidationTest {
343341

344342
@RegisterExtension
345343
static WireMockExtension issuer = WireMockExtension.newInstance()
346-
.options(wireMockConfig()
347-
.dynamicPort()
348-
// .notifier(new ConsoleNotifier(true))
344+
.options(wireMockConfig().dynamicPort()
345+
// .notifier(new ConsoleNotifier(true))
349346
)
350347
.build();
351348

@@ -435,7 +432,7 @@ private void mockCommon(
435432
when(miwSettings.authorityWalletBpn()).thenReturn(baseWalletBpn);
436433
when(commonService.getWalletByIdentifier(baseWalletBpn)).thenReturn(baseWallet);
437434
when(commonService.getWalletByIdentifier(holderWalletBpn)).thenReturn(holderWallet);
438-
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() ,baseWallet.getAlgorithm()))
435+
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId(), baseWallet.getAlgorithm()))
439436
.thenReturn(keyPair.getPrivateKey().asByte());
440437
when(miwSettings.supportedFrameworkVCTypes()).thenReturn(Set.of("SustainabilityCredential"));
441438
when(holdersCredentialRepository.save(any(HoldersCredential.class)))

0 commit comments

Comments
 (0)