Skip to content

Commit

Permalink
fix: add asJwt to controllers and services
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafasalfiti authored and nitin-vavdiya committed May 21, 2024
1 parent 14f6195 commit 050358e
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ public class IssuersCredentialControllerApiDocs {
@RequestBody(content = {
@Content(examples = @ExampleObject("""
{
"bpn": "BPNL000000000000"
"bpn": "BPNL000000000000",
"asJwt": false
}
"""))
})
Expand Down Expand Up @@ -330,7 +331,8 @@ public class IssuersCredentialControllerApiDocs {
"activityType": "vehicleDismantle",
"allowedVehicleBrands": [
"Audi", "Abarth", "Alfa Romeo", "Chrysler"
]
],
"asJwt": false
}
"""))
})
Expand Down Expand Up @@ -462,55 +464,62 @@ public class IssuersCredentialControllerApiDocs {
"holderIdentifier": "BPNL000000000000",
"type": "BehaviorTwinCredential",
"contract-template": "https://eclipse-tractusx.github.io/tractusx-profiles/cx/context/credentials.context.json",
"contract-version": "1.0.0"
"contract-version": "1.0.0",
"asJwt": false
}
"""),
@ExampleObject(name = "PcfCredential", value = """
{
"holderIdentifier": "BPNL000000000000",
"type": "PcfCredential",
"contract-template": "https://eclipse-tractusx.github.io/tractusx-profiles/cx/context/credentials.context.json",
"contract-version": "1.0.0"
"contract-version": "1.0.0",
"asJwt": false
}
"""),
@ExampleObject(name = "SustainabilityCredential", value = """
{
"holderIdentifier": "BPNL000000000000",
"type": "SustainabilityCredential",
"contract-template": "https://eclipse-tractusx.github.io/tractusx-profiles/cx/context/credentials.context.json",
"contract-version": "1.0.0"
"contract-version": "1.0.0",
"asJwt": false
}
"""),
@ExampleObject(name = "QualityCredential", value = """
{
"holderIdentifier": "BPNL000000000000",
"type": "QualityCredential",
"contract-template": "https://eclipse-tractusx.github.io/tractusx-profiles/cx/context/credentials.context.json",
"contract-version": "1.0.0"
"contract-version": "1.0.0",
"asJwt": false
}
"""),
@ExampleObject(name = "TraceabilityCredential", value = """
{
"holderIdentifier": "BPNL000000000000",
"type": "TraceabilityCredential",
"contract-template": "https://eclipse-tractusx.github.io/tractusx-profiles/cx/context/credentials.context.json",
"contract-version": "1.0.0"
"contract-version": "1.0.0",
"asJwt": false
}
"""),
@ExampleObject(name = "BehaviorTwinCredential", value = """
{
"holderIdentifier": "BPNL000000000000",
"type": "BehaviorTwinCredential",
"contract-template": "https://eclipse-tractusx.github.io/tractusx-profiles/cx/context/credentials.context.json",
"contract-version": "1.0.0"
"contract-version": "1.0.0",
"asJwt": false
}
"""),
@ExampleObject(name = "ResiliencyCredential", value = """
{
"holderIdentifier": "BPNL000000000000",
"type": "ResiliencyCredential",
"contract-template": "https://eclipse-tractusx.github.io/tractusx-profiles/cx/context/credentials.context.json",
"contract-version": "1.0.0"
"contract-version": "1.0.0",
"asJwt": false
}
""")

Expand Down Expand Up @@ -1044,7 +1053,7 @@ public class IssuersCredentialControllerApiDocs {
})
public @interface ValidateVerifiableCredentialApiDocs {
}

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Tag(name = API_TAG_VERIFIABLE_CREDENTIAL_ISSUER)
Expand Down Expand Up @@ -1169,7 +1178,7 @@ public class IssuersCredentialControllerApiDocs {
public @interface IssueVerifiableCredentialUsingBaseWalletApiDocs {
}


@Parameter(description = "Specifies whether the VC (Verifiable Credential) should be created as a JWT (JSON Web Token). "
+
"If set to true, the VC will be generated in JWT format"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ public ResponseEntity<PageImpl<CredentialsResponse>> getCredentials(@Parameter(n
* @param principal the principal
* @return the response entity
*/

@IssueCredentialApiDoc
@PostMapping(path = RestURI.CREDENTIALS, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CredentialsResponse> issueCredential(@RequestBody Map<String, Object> data, Principal principal,
@AsJwtParam @RequestParam(name = "asJwt", defaultValue = "false") boolean asJwt
) {
log.debug("Received request to issue credential. BPN: {}", getBPNFromToken(principal));
return ResponseEntity.status(HttpStatus.CREATED).body(holdersCredentialService.issueCredential(data, asJwt, getBPNFromToken(principal)));
return ResponseEntity.status(HttpStatus.CREATED).body(holdersCredentialService.issueCredential(data, getBPNFromToken(principal) , asJwt));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.AsJwtParam;
import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.GetCredentialsApiDocs;
import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.IssueDismantlerCredentialApiDoc;
import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.IssueMembershipCredentialApiDoc;
import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.IssueFrameworkCredentialApiDocs;
import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.IssueMembershipCredentialApiDoc;
import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.IssueVerifiableCredentialUsingBaseWalletApiDocs;
import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs.ValidateVerifiableCredentialApiDocs;
import org.eclipse.tractusx.managedidentitywallets.command.GetCredentialsCommand;
Expand All @@ -49,7 +48,11 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.List;
Expand Down Expand Up @@ -103,7 +106,7 @@ public ResponseEntity<PageImpl<CredentialsResponse>> getCredentials(@Parameter(n
@ExampleObject(value = "credentialId", name = "Credential id")
}
) @RequestParam(required = false, defaultValue = "createdAt") String sortColumn,
@Parameter(name = "sortTpe", description = "Sort order", examples = {@ExampleObject(value = "desc", name = "Descending order"), @ExampleObject(value = "asc", name = "Ascending order")}) @RequestParam(required = false, defaultValue = "desc") String sortTpe,
@Parameter(name = "sortTpe", description = "Sort order", examples = { @ExampleObject(value = "desc", name = "Descending order"), @ExampleObject(value = "asc", name = "Ascending order") }) @RequestParam(required = false, defaultValue = "desc") String sortTpe,
@AsJwtParam @RequestParam(name = StringPool.AS_JWT, defaultValue = "false") boolean asJwt,
Principal principal) {
log.debug("Received request to get credentials. BPN: {}", getBPNFromToken(principal));
Expand Down Expand Up @@ -173,7 +176,7 @@ public ResponseEntity<CredentialsResponse> issueFrameworkCredential(@Valid @Requ
/**
* Credentials validation response entity.
*
* @param data the data
* @param credentialVerificationRequest the request
* @param withCredentialExpiryDate the with credential expiry date
* @return the response entity
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -27,6 +27,8 @@
import lombok.*;
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Set;

/**
Expand All @@ -49,4 +51,7 @@ public class IssueDismantlerCredentialRequest {

@Builder.Default
private Set<@NotBlank String> allowedVehicleBrands = Set.of();

@JsonProperty("asJwt")
private boolean asJwt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,42 @@

package org.eclipse.tractusx.managedidentitywallets.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.*;


/**
* The type Issue framework credential request.
*/
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;


/**
* The type Issue framework credential request.
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class IssueFrameworkCredentialRequest {

@NotBlank(message = "Please provide holder identifier")
@Size(min = 5, max = 255, message = "Please provide valid identifier")
private String holderIdentifier;
@NotBlank(message = "Please provide type")

@NotBlank(message = "Please provide type")
private String type;
@NotBlank(message = "Please provide contract-template")

@NotBlank(message = "Please provide contract-template")
@JsonProperty("contract-template")
private String contractTemplate;
@NotBlank(message = "Please provide contract-template")

@NotBlank(message = "Please provide contract-template")
@JsonProperty("contract-version")
private String contractVersion;


}


@JsonProperty("asJwt")
private boolean asJwt;

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,31 @@

package org.eclipse.tractusx.managedidentitywallets.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.*;
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;


/**
* The type Issue membership credential request.
*/
/**
* The type Issue membership credential request.
*/
@Getter
@Setter
@NoArgsConstructor
@Builder
@AllArgsConstructor
public class IssueMembershipCredentialRequest {

@NotBlank(message = "Please provide BPN")
@Pattern(regexp = StringPool.BPN_NUMBER_REGEX, message = "Please provide valid BPN")
private String bpn;


@JsonProperty("asJwt")
private boolean asJwt;
}



Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,9 @@ protected SpecificationUtil<HoldersCredential> getSpecificationUtil() {


/**
* Gets list of holder's credentials
* Gets credentials.
*
* @param credentialId the credentialId
* @param issuerIdentifier the issuer identifier
* @param type the type
* @param sortColumn the sort column
* @param sortType the sort type
* @param callerBPN the caller bpn
* @param command the command
* @return the credentials
*/
public PageImpl<CredentialsResponse> getCredentials(GetCredentialsCommand command) {
Expand Down Expand Up @@ -150,9 +145,10 @@ public PageImpl<CredentialsResponse> getCredentials(GetCredentialsCommand comman
*
* @param data the data
* @param callerBpn the caller bpn
* @param asJwt the as jwt
* @return the verifiable credential
*/
public CredentialsResponse issueCredential(Map<String, Object> data, boolean asJwt, String callerBpn) {
public CredentialsResponse issueCredential(Map<String, Object> data, String callerBpn, boolean asJwt) {
VerifiableCredential verifiableCredential = new VerifiableCredential(data);
Wallet issuerWallet = commonService.getWalletByIdentifier(verifiableCredential.getIssuer().toString());

Expand All @@ -167,7 +163,7 @@ public CredentialsResponse issueCredential(Map<String, Object> data, boolean asJ
if (verifiableCredential.getExpirationDate() != null) {
expiryDate = Date.from(verifiableCredential.getExpirationDate());
}

// Create Credential
HoldersCredential credential = CommonUtils.getHoldersCredential(verifiableCredential.getCredentialSubject().get(0),
verifiableCredential.getTypes(), issuerWallet.getDidDocument(),
Expand Down
Loading

0 comments on commit 050358e

Please sign in to comment.