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

Commit b604f3d

Browse files
mustafasalfitinitin-vavdiya
authored andcommitted
fix: add asJwt to controllers and services
1 parent 179b590 commit b604f3d

12 files changed

+389
-137
lines changed

src/main/java/org/eclipse/tractusx/managedidentitywallets/apidocs/IssuersCredentialControllerApiDocs.java

Lines changed: 114 additions & 42 deletions
Large diffs are not rendered by default.

src/main/java/org/eclipse/tractusx/managedidentitywallets/constant/StringPool.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,6 @@ private StringPool() {
102102

103103
public static final String PRIVATE_KEY = "PRIVATE KEY";
104104
public static final String PUBLIC_KEY = "PUBLIC KEY";
105+
public static final String VC_JWT_KEY = "jwt";
106+
105107
}

src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/HoldersCredentialController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.tractusx.managedidentitywallets.apidocs.HoldersCredentialControllerApiDocs.GetCredentialsApiDocs;
3030
import org.eclipse.tractusx.managedidentitywallets.apidocs.HoldersCredentialControllerApiDocs.IssueCredentialApiDoc;
3131
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
32+
import org.eclipse.tractusx.managedidentitywallets.dto.CredentialsResponse;
3233
import org.eclipse.tractusx.managedidentitywallets.service.HoldersCredentialService;
3334
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential;
3435
import org.springframework.data.domain.PageImpl;
@@ -101,8 +102,10 @@ public ResponseEntity<PageImpl<VerifiableCredential>> getCredentials(@Parameter(
101102

102103
@IssueCredentialApiDoc
103104
@PostMapping(path = RestURI.CREDENTIALS, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
104-
public ResponseEntity<VerifiableCredential> issueCredential(@RequestBody Map<String, Object> data, Principal principal) {
105+
public ResponseEntity<CredentialsResponse> issueCredential(@RequestBody Map<String, Object> data, Principal principal,
106+
@RequestParam(name = "asJwt", defaultValue = "false") boolean asJwt
107+
) {
105108
log.debug("Received request to issue credential. BPN: {}", getBPNFromToken(principal));
106-
return ResponseEntity.status(HttpStatus.CREATED).body(holdersCredentialService.issueCredential(data, getBPNFromToken(principal)));
109+
return ResponseEntity.status(HttpStatus.CREATED).body(holdersCredentialService.issueCredential(data, getBPNFromToken(principal) , asJwt));
107110
}
108111
}

src/main/java/org/eclipse/tractusx/managedidentitywallets/controller/IssuersCredentialController.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.IssueVerifiableCredentialUsingBaseWalletApiDocs;
3737
import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.ValidateVerifiableCredentialApiDocs;
3838
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
39+
import org.eclipse.tractusx.managedidentitywallets.dto.CredentialVerificationRequest;
40+
import org.eclipse.tractusx.managedidentitywallets.dto.CredentialsResponse;
3941
import org.eclipse.tractusx.managedidentitywallets.dto.IssueDismantlerCredentialRequest;
4042
import org.eclipse.tractusx.managedidentitywallets.dto.IssueFrameworkCredentialRequest;
4143
import org.eclipse.tractusx.managedidentitywallets.dto.IssueMembershipCredentialRequest;
@@ -113,7 +115,7 @@ public ResponseEntity<PageImpl<VerifiableCredential>> getCredentials(@Parameter(
113115
*/
114116
@IssueMembershipCredentialApiDoc
115117
@PostMapping(path = RestURI.CREDENTIALS_ISSUER_MEMBERSHIP, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
116-
public ResponseEntity<VerifiableCredential> issueMembershipCredential(@Valid @RequestBody IssueMembershipCredentialRequest issueMembershipCredentialRequest, Principal principal) {
118+
public ResponseEntity<CredentialsResponse> issueMembershipCredential(@Valid @RequestBody IssueMembershipCredentialRequest issueMembershipCredentialRequest, Principal principal) {
117119
log.debug("Received request to issue membership credential. BPN: {}", getBPNFromToken(principal));
118120
return ResponseEntity.status(HttpStatus.CREATED).body(issuersCredentialService.issueMembershipCredential(issueMembershipCredentialRequest, getBPNFromToken(principal)));
119121
}
@@ -127,7 +129,7 @@ public ResponseEntity<VerifiableCredential> issueMembershipCredential(@Valid @Re
127129
*/
128130
@IssueDismantlerCredentialApiDoc
129131
@PostMapping(path = RestURI.CREDENTIALS_ISSUER_DISMANTLER, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
130-
public ResponseEntity<VerifiableCredential> issueDismantlerCredential(@Valid @RequestBody IssueDismantlerCredentialRequest request, Principal principal) {
132+
public ResponseEntity<CredentialsResponse> issueDismantlerCredential(@Valid @RequestBody IssueDismantlerCredentialRequest request, Principal principal) {
131133
log.debug("Received request to issue dismantler credential. BPN: {}", getBPNFromToken(principal));
132134
return ResponseEntity.status(HttpStatus.CREATED).body(issuersCredentialService.issueDismantlerCredential(request, getBPNFromToken(principal)));
133135
}
@@ -141,7 +143,7 @@ public ResponseEntity<VerifiableCredential> issueDismantlerCredential(@Valid @Re
141143
*/
142144
@IssueFrameworkCredentialApiDocs
143145
@PostMapping(path = RestURI.API_CREDENTIALS_ISSUER_FRAMEWORK, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
144-
public ResponseEntity<VerifiableCredential> issueFrameworkCredential(@Valid @RequestBody IssueFrameworkCredentialRequest request, Principal principal) {
146+
public ResponseEntity<CredentialsResponse> issueFrameworkCredential(@Valid @RequestBody IssueFrameworkCredentialRequest request, Principal principal) {
145147
log.debug("Received request to issue framework credential. BPN: {}", getBPNFromToken(principal));
146148
return ResponseEntity.status(HttpStatus.CREATED).body(issuersCredentialService.issueFrameworkCredential(request, getBPNFromToken(principal)));
147149
}
@@ -155,10 +157,10 @@ public ResponseEntity<VerifiableCredential> issueFrameworkCredential(@Valid @Req
155157
*/
156158
@PostMapping(path = RestURI.CREDENTIALS_VALIDATION, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
157159
@ValidateVerifiableCredentialApiDocs
158-
public ResponseEntity<Map<String, Object>> credentialsValidation(@RequestBody Map<String, Object> data,
160+
public ResponseEntity<Map<String, Object>> credentialsValidation(@RequestBody CredentialVerificationRequest credentialVerificationRequest,
159161
@Parameter(description = "Check expiry of VC") @RequestParam(name = "withCredentialExpiryDate", defaultValue = "false", required = false) boolean withCredentialExpiryDate) {
160162
log.debug("Received request to validate verifiable credentials");
161-
return ResponseEntity.status(HttpStatus.OK).body(issuersCredentialService.credentialsValidation(data, withCredentialExpiryDate));
163+
return ResponseEntity.status(HttpStatus.OK).body(issuersCredentialService.credentialsValidation(credentialVerificationRequest, withCredentialExpiryDate));
162164
}
163165

164166
/**
@@ -171,8 +173,10 @@ public ResponseEntity<Map<String, Object>> credentialsValidation(@RequestBody Ma
171173
*/
172174
@PostMapping(path = RestURI.ISSUERS_CREDENTIALS, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
173175
@IssueVerifiableCredentialUsingBaseWalletApiDocs
174-
public ResponseEntity<VerifiableCredential> issueCredentialUsingBaseWallet(@Parameter(description = "Holder DID", examples = {@ExampleObject(description = "did", name = "did", value = "did:web:localhost:BPNL000000000000")}) @RequestParam(name = "holderDid") String holderDid, @RequestBody Map<String, Object> data, Principal principal) {
176+
public ResponseEntity<CredentialsResponse> issueCredentialUsingBaseWallet(@Parameter(description = "Holder DID", examples = {@ExampleObject(description = "did", name = "did", value = "did:web:localhost:BPNL000000000000")}) @RequestParam(name = "holderDid") String holderDid,
177+
@RequestBody Map<String, Object> data, Principal principal,
178+
@RequestParam(name = "asJwt", defaultValue = "false") boolean asJwt) {
175179
log.debug("Received request to issue verifiable credential. BPN: {}", getBPNFromToken(principal));
176-
return ResponseEntity.status(HttpStatus.CREATED).body(issuersCredentialService.issueCredentialUsingBaseWallet(holderDid, data, getBPNFromToken(principal)));
180+
return ResponseEntity.status(HttpStatus.CREATED).body(issuersCredentialService.issueCredentialUsingBaseWallet(holderDid, data, getBPNFromToken(principal) , asJwt));
177181
}
178182
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* *******************************************************************************
3+
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
4+
*
5+
* See the NOTICE file(s) distributed with this work for additional
6+
* information regarding copyright ownership.
7+
*
8+
* This program and the accompanying materials are made available under the
9+
* terms of the Apache License, Version 2.0 which is available at
10+
* https://www.apache.org/licenses/LICENSE-2.0.
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations
16+
* under the License.
17+
*
18+
* SPDX-License-Identifier: Apache-2.0
19+
* ******************************************************************************
20+
*/
21+
22+
package org.eclipse.tractusx.managedidentitywallets.dto;
23+
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+
}
35+
36+
public void setVc(Map<String,Object> vc) {
37+
putAll(vc);
38+
}
39+
}
40+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* *******************************************************************************
3+
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
4+
*
5+
* See the NOTICE file(s) distributed with this work for additional
6+
* information regarding copyright ownership.
7+
*
8+
* This program and the accompanying materials are made available under the
9+
* terms of the Apache License, Version 2.0 which is available at
10+
* https://www.apache.org/licenses/LICENSE-2.0.
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations
16+
* under the License.
17+
*
18+
* SPDX-License-Identifier: Apache-2.0
19+
* ******************************************************************************
20+
*/
21+
22+
package org.eclipse.tractusx.managedidentitywallets.dto;
23+
24+
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;
25+
26+
import java.util.LinkedHashMap;
27+
import java.util.Map;
28+
29+
public class CredentialsResponse extends LinkedHashMap<String, Object> {
30+
31+
public void setJwt(String jwt) {
32+
put(StringPool.VC_JWT_KEY, jwt);
33+
}
34+
35+
public void setVc(Map<String,Object> vc) {
36+
putAll(vc);
37+
}
38+
39+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* *******************************************************************************
3-
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
3+
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
44
*
55
* See the NOTICE file(s) distributed with this work for additional
66
* information regarding copyright ownership.
@@ -27,6 +27,8 @@
2727
import lombok.*;
2828
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;
2929

30+
import com.fasterxml.jackson.annotation.JsonProperty;
31+
3032
import java.util.Set;
3133

3234
/**
@@ -49,4 +51,7 @@ public class IssueDismantlerCredentialRequest {
4951

5052
@Builder.Default
5153
private Set<@NotBlank String> allowedVehicleBrands = Set.of();
54+
55+
@JsonProperty("asJwt")
56+
private boolean asJwt;
5257
}
Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* *******************************************************************************
3-
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
3+
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
44
*
55
* See the NOTICE file(s) distributed with this work for additional
66
* information regarding copyright ownership.
@@ -19,36 +19,41 @@
1919
* ******************************************************************************
2020
*/
2121

22-
package org.eclipse.tractusx.managedidentitywallets.dto;
23-
24-
import com.fasterxml.jackson.annotation.JsonProperty;
25-
import jakarta.validation.constraints.NotBlank;
26-
import jakarta.validation.constraints.Size;
27-
import lombok.*;
28-
29-
30-
/**
31-
* The type Issue framework credential request.
32-
*/
33-
@Getter
34-
@Setter
35-
@NoArgsConstructor
36-
@AllArgsConstructor
37-
@Builder
38-
public class IssueFrameworkCredentialRequest {
39-
40-
@NotBlank(message = "Please provide holder identifier")
41-
@Size(min = 5, max = 255, message = "Please provide valid identifier")
42-
private String holderIdentifier;
43-
44-
@NotBlank(message = "Please provide type")
45-
private String type;
46-
47-
@NotBlank(message = "Please provide contract-template")
48-
@JsonProperty("contract-template")
49-
private String contractTemplate;
50-
51-
@NotBlank(message = "Please provide contract-template")
52-
@JsonProperty("contract-version")
53-
private String contractVersion;
54-
}
22+
package org.eclipse.tractusx.managedidentitywallets.dto;
23+
24+
import com.fasterxml.jackson.annotation.JsonProperty;
25+
import jakarta.validation.constraints.NotBlank;
26+
import jakarta.validation.constraints.Size;
27+
import lombok.*;
28+
29+
30+
/**
31+
* The type Issue framework credential request.
32+
*/
33+
@Getter
34+
@Setter
35+
@NoArgsConstructor
36+
@AllArgsConstructor
37+
@Builder
38+
public class IssueFrameworkCredentialRequest {
39+
40+
@NotBlank(message = "Please provide holder identifier")
41+
@Size(min = 5, max = 255, message = "Please provide valid identifier")
42+
private String holderIdentifier;
43+
44+
@NotBlank(message = "Please provide type")
45+
private String type;
46+
47+
@NotBlank(message = "Please provide contract-template")
48+
@JsonProperty("contract-template")
49+
private String contractTemplate;
50+
51+
@NotBlank(message = "Please provide contract-template")
52+
@JsonProperty("contract-version")
53+
private String contractVersion;
54+
55+
@JsonProperty("asJwt")
56+
private boolean asJwt;
57+
58+
}
59+
Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* *******************************************************************************
3-
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
3+
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
44
*
55
* See the NOTICE file(s) distributed with this work for additional
66
* information regarding copyright ownership.
@@ -19,25 +19,31 @@
1919
* ******************************************************************************
2020
*/
2121

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

24-
import jakarta.validation.constraints.NotBlank;
25-
import jakarta.validation.constraints.Pattern;
26-
import lombok.*;
27-
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;
28-
29-
/**
30-
* The type Issue membership credential request.
31-
*/
32-
@Getter
33-
@Setter
34-
@NoArgsConstructor
35-
@Builder
36-
@AllArgsConstructor
37-
public class IssueMembershipCredentialRequest {
38-
39-
@NotBlank(message = "Please provide BPN")
40-
@Pattern(regexp = StringPool.BPN_NUMBER_REGEX, message = "Please provide valid BPN")
41-
private String bpn;
42-
}
24+
import jakarta.validation.constraints.NotBlank;
25+
import jakarta.validation.constraints.Pattern;
26+
import lombok.*;
27+
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;
4328

29+
import com.fasterxml.jackson.annotation.JsonProperty;
30+
31+
/**
32+
* The type Issue membership credential request.
33+
*/
34+
@Getter
35+
@Setter
36+
@NoArgsConstructor
37+
@Builder
38+
@AllArgsConstructor
39+
public class IssueMembershipCredentialRequest {
40+
41+
@NotBlank(message = "Please provide BPN")
42+
@Pattern(regexp = StringPool.BPN_NUMBER_REGEX, message = "Please provide valid BPN")
43+
private String bpn;
44+
45+
@JsonProperty("asJwt")
46+
private boolean asJwt;
47+
}
48+
49+

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.eclipse.tractusx.managedidentitywallets.dao.entity.HoldersCredential;
3737
import org.eclipse.tractusx.managedidentitywallets.dao.entity.Wallet;
3838
import org.eclipse.tractusx.managedidentitywallets.dao.repository.HoldersCredentialRepository;
39+
import org.eclipse.tractusx.managedidentitywallets.dto.CredentialsResponse;
3940
import org.eclipse.tractusx.managedidentitywallets.exception.CredentialNotFoundProblem;
4041
import org.eclipse.tractusx.managedidentitywallets.exception.ForbiddenException;
4142
import org.eclipse.tractusx.managedidentitywallets.utils.CommonUtils;
@@ -143,7 +144,7 @@ public PageImpl<VerifiableCredential> getCredentials(String credentialId, String
143144
* @param callerBpn the caller bpn
144145
* @return the verifiable credential
145146
*/
146-
public VerifiableCredential issueCredential(Map<String, Object> data, String callerBpn) {
147+
public CredentialsResponse issueCredential(Map<String, Object> data, String callerBpn , boolean asJwt) {
147148
VerifiableCredential verifiableCredential = new VerifiableCredential(data);
148149
Wallet issuerWallet = commonService.getWalletByIdentifier(verifiableCredential.getIssuer().toString());
149150

@@ -167,9 +168,18 @@ public VerifiableCredential issueCredential(Map<String, Object> data, String cal
167168
//Store Credential in holder table
168169
credential = create(credential);
169170

170-
log.debug("VC type of {} issued to bpn ->{}", StringEscapeUtils.escapeJava(verifiableCredential.getTypes().toString()), StringEscapeUtils.escapeJava(callerBpn));
171+
final CredentialsResponse cr = new CredentialsResponse();
172+
171173
// Return VC
172-
return credential.getData();
174+
if (asJwt) {
175+
cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, commonService.getWalletByIdentifier(callerBpn), credential.getData() , walletKeyService));
176+
} else {
177+
cr.setVc(credential.getData());
178+
}
179+
180+
log.debug("VC type of {} issued to bpn ->{}", StringEscapeUtils.escapeJava(verifiableCredential.getTypes().toString()), StringEscapeUtils.escapeJava(callerBpn));
181+
182+
return cr;
173183
}
174184

175185
private void isCredentialExistWithId(String holderDid, String credentialId) {

0 commit comments

Comments
 (0)