Skip to content

Commit

Permalink
feat: read me file chamges, sample reponse added
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-vavdiya committed Jun 2, 2023
1 parent a51127e commit ff51983
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 53 deletions.
8 changes: 3 additions & 5 deletions README_did_web.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ Following tools the MIW development team used successfully:
5. set ORG_GRADLE_PROJECT_githubUserName and ORG_GRADLE_PROJECT_githubToken values
in [dev.env](dev-assets%2Fdid-web%2Fdev.env)
6. Setup [dev.env](dev-assets%2Fdid-web%2Fdev.env) values either in application.yaml or in IDE
7.
Run [ManagedIdentityWalletsApplication.java](src%2Fmain%2Fjava%2Forg%2Feclipse%2Ftractusx%2Fmanagedidentitywallets%2FManagedIdentityWalletsApplication.java)
in IDE
7. Run [ManagedIdentityWalletsApplication.java](src%2Fmain%2Fjava%2Forg%2Feclipse%2Ftractusx%2Fmanagedidentitywallets%2FManagedIdentityWalletsApplication.java) in IDE
8. Open API doc on http://localhost:8080
9. Click on Authorize on swagger UI and on the dialog click again on Authorize.
10. Login with username=catena-x and password=password
Expand Down Expand Up @@ -60,7 +58,7 @@ Currently the minimum is 80%

| name | description | default value |
|------------------------------|-----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| APPLICATION_PORT | port number of application | 8087 |
| APPLICATION_PORT | port number of application | 8080 |
| APPLICATION_ENVIRONMENT | Environment of the application ie. local, dev, int and prod | local |
| DB_HOST | Database host | localhost |
| DB_PORT | Port of database | 5432 |
Expand Down Expand Up @@ -88,4 +86,4 @@ Currently the minimum is 80%

1. https://www.testcontainers.org/modules/databases/postgres/
2. https://github.com/dasniko/testcontainers-keycloak
3. https://github.com/smartSenseSolutions/smartsense-java-commons
3. https://github.com/smartSenseSolutions/smartsense-java-commons
2 changes: 1 addition & 1 deletion dev-assets/did-web/dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ VC_EXPIRY_DATE=01-01-2025
SUPPORTED_FRAMEWORK_VC_TYPES=cx-behavior-twin=Behavior Twin,cx-pcf=PCF,cx-quality=Quality,cx-resiliency=Resiliency,cx-sustainability=Sustainability,cx-traceability=ID_3.0_Trace
KEYCLOAK_REALM=miw_test
KEYCLOAK_CLIENT_ID=miw_private_client
AUTH_SERVER_URL:http://localhost:8081
AUTH_SERVER_URL=http://localhost:8081

## Github user name
ORG_GRADLE_PROJECT_githubUserName=
Expand Down
6 changes: 4 additions & 2 deletions dev-assets/did-web/miw_test_realm.json
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,13 @@
"clientAuthenticatorType": "client-secret",
"redirectUris": [
"http://localhost/*",
"http://localhost:8087/*"
"http://localhost:8087/*",
"http://localhost:8080/*"
],
"webOrigins": [
"http://localhost",
"http://localhost:8087"
"http://localhost:8087",
"http://localhost:8080"
],
"notBefore": 0,
"bearerOnly": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package org.eclipse.tractusx.managedidentitywallets.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
Expand Down Expand Up @@ -51,13 +52,13 @@ public class DidDocumentController {
*/
@Operation(description = "Resolve the DID document for a given DID or BPN", summary = "Resolve DID Document")
@GetMapping(path = RestURI.DID_DOCUMENTS, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<DidDocument> getDidDocument(@PathVariable(name = "identifier") String identifier) {
public ResponseEntity<DidDocument> getDidDocument(@Parameter(description = "Did or BPN") @PathVariable(name = "identifier") String identifier) {
return ResponseEntity.status(HttpStatus.OK).body(service.getDidDocument(identifier));
}

@Operation(description = "Resolve the DID document for a given BPN", summary = "Resolve DID Document")
@GetMapping(path = RestURI.DID_RESOLVE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<DidDocument> getDidResolve(@PathVariable(name = "bpn") String bpn) {
public ResponseEntity<DidDocument> getDidResolve(@Parameter(description = "Did or BPN") @PathVariable(name = "bpn") String bpn) {
return ResponseEntity.status(HttpStatus.OK).body(service.getDidDocument(bpn));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package org.eclipse.tractusx.managedidentitywallets.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -92,43 +93,65 @@ public ResponseEntity<Map<String, Object>> createPresentation(@RequestBody Map<S
@PostMapping(path = RestURI.API_PRESENTATIONS_VALIDATION, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)

@io.swagger.v3.oas.annotations.parameters.RequestBody(content = {
@Content(examples = @ExampleObject("""
{
"holderIdentifier": "did:example:76e12ec712ebc6f1c221ebfeb1f",
"verifiableCredentials": [
{
"id": "http://example.edu/credentials/333",
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1"
],
"type": [
"University-Degree-Credential, VerifiableCredential"
],
"issuer": "did:example:76e12ec712ebc6f1c221ebfeb1f",
"issuanceDate": "2019-06-16T18:56:59Z",
"expirationDate": "2019-06-17T18:56:59Z",
"credentialSubject": {
"college": "Test-University"
},
"proof": {
"type": "Ed25519Signature2018",
"created": "2021-11-17T22:20:27Z",
"proofPurpose": "assertionMethod",
"verificationMethod": "did:example:76e12ec712ebc6f1c221ebfeb1f#keys-1",
"jws": "eyJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCJdLCJhbGciOiJFZERTQSJ9..JNerzfrK46Mq4XxYZEnY9xOK80xsEaWCLAHuZsFie1-NTJD17wWWENn_DAlA_OwxGF5dhxUJ05P6Dm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mlmaWNhdGlvbk1ldGhvZCI6ImRpZDp3ZWI6bG9jYWxob3N0OkJQTkwwMDAwMDAwMDAwMDAiLCJ0eXBlIjoiRWQyNTUxOVNpZ25hdHVyZTIwMjAiLCJwcm9vZlZhbHVlIjoiejRkdUJmY0NzYVN6aU5lVXc4WUJ5eUZkdlpYVzhlQUs5MjhkeDNQeExqV0N2S3p0Slo5bWh4aEh3ZTVCdVRRUW5KRmtvb01nUUdLREU0OGNpTHJHaHBzUEEiLCJjcmVhdGVkIjoiMjAyMy0wNi0wMVQwODo1Nzo1MFoifX19LCJleHAiOjE2ODU2ODEwNTIsImp0aSI6IjFhYmQxYjAxLTBkZTUtNGY1Ny04ZjBlLWRmNzBhNzNkMjE2NyJ9.Hfm-ANjoeZ8fO-32LPOsQ3-xXSclPUd28p9hvlWyVVB0Mz7n0k-KAHra5kpT0oGrGtdhC1lZ0AitdB_td6VrAQ"
}
""")

, @ExampleObject(name = "VP as json-ld", value = """
{
"vp": {
"id": "b9d97cef-758d-4a7c-843d-86f17632b08a",
"type": [
"VerifiablePresentation"
],
"@context": [
"https://www.w3.org/2018/credentials/v1"
],
"verifiableCredential": [
{
"issuanceDate": "2023-06-01T08:57:50Z",
"credentialSubject": [
{
"bpn": "BPNL000000000000",
"id": "did:web:localhost:BPNL000000000000",
"type": "BpnCredential"
}
],
"id": "acb9522f-db22-4f90-9475-c3f3511f9cde",
"proof": {
"proofPurpose": "proofPurpose",
"verificationMethod": "did:web:localhost:BPNL000000000000",
"type": "Ed25519Signature2020",
"proofValue": "z4duBfcCsaSziNeUw8YByyFdvZXW8eAK928dx3PxLjWCvKztJZ9mhxhHwe5BuTQQnJFkooMgQGKDE48ciLrGhpsPA",
"created": "2023-06-01T08:57:50Z"
},
"type": [
"VerifiableCredential",
"BpnCredentialCX"
],
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://raw.githubusercontent.com/catenax-ng/product-core-schemas/main/businessPartnerData"
],
"issuer": "did:web:localhost:BPNL000000000000",
"expirationDate": "2024-12-31T18:30:00Z"
}
]
}
}
""")

})
})
public ResponseEntity<Map<String, Object>> validatePresentation(@RequestBody Map<String, Object> data,
@RequestParam(name = "audience", required = false) String audience,
@RequestParam(name = "asJwt", required = false, defaultValue = "false") boolean asJwt,
@RequestParam(name = "withCredentialExpiryDate", required = false, defaultValue = "false") boolean withCredentialExpiryDate,
@RequestParam(name = "withCredentialsValidation", required = false, defaultValue = "false") boolean withCredentialsValidation
@Parameter(description = "Audience to validate in VP (Only supported in case of JWT formatted VP)") @RequestParam(name = "audience", required = false) String audience,
@Parameter(description = "Pass true in case of VP is in JWT format") @RequestParam(name = "asJwt", required = false, defaultValue = "false") boolean asJwt,
@Parameter(description = "Check expiry of VC(Only supported in case of JWT formatted VP)") @RequestParam(name = "withCredentialExpiryDate", required = false, defaultValue = "false") boolean withCredentialExpiryDate
) {
return ResponseEntity.status(HttpStatus.CREATED).body(presentationService.validatePresentation(data, asJwt, withCredentialExpiryDate, withCredentialsValidation));
return ResponseEntity.status(HttpStatus.CREATED).body(presentationService.validatePresentation(data, asJwt, withCredentialExpiryDate, audience));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package org.eclipse.tractusx.managedidentitywallets.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -56,6 +57,17 @@ public class WalletController extends BaseController {
* @param request the request
* @return the response entity
*/
@io.swagger.v3.oas.annotations.parameters.RequestBody(content = {
@Content(examples = {

@ExampleObject(name = "Create wallet with BPN", value = """
{
"bpn": "BPNL000000000001",
"name": "smartSense"
}
""")
})
})
@Operation(summary = "Create Wallet", description = "Permission: **add_wallets** \n\n Create a wallet and store it")
@PostMapping(path = RestURI.WALLETS, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Wallet> createWallet(@Valid @RequestBody CreateWalletRequest request) {
Expand Down Expand Up @@ -106,7 +118,8 @@ public ResponseEntity<Wallet> createWallet(@Valid @RequestBody CreateWalletReque
}
"""))
})
public ResponseEntity<Map<String, String>> storeCredential(@RequestBody Map<String, Object> data, @PathVariable(name = "identifier") String identifier, Principal principal) {
public ResponseEntity<Map<String, String>> storeCredential(@RequestBody Map<String, Object> data,
@Parameter(description = "Did or BPN") @PathVariable(name = "identifier") String identifier, Principal principal) {
return ResponseEntity.status(HttpStatus.CREATED).body(service.storeCredential(data, identifier, getBPNFromToken(principal)));
}

Expand All @@ -120,7 +133,7 @@ public ResponseEntity<Map<String, String>> storeCredential(@RequestBody Map<Stri
@Operation(summary = "Retrieve wallet by identifier", description = "Permission: **view_wallets** OR **view_wallet** (The BPN of Wallet to retrieve must equal the BPN of caller) \n\n Retrieve single wallet by identifier, with or without its credentials")
@GetMapping(path = RestURI.API_WALLETS_IDENTIFIER, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Wallet> getWalletByIdentifier(@PathVariable(name = "identifier") String identifier,
@RequestParam(name = "withCredentials", defaultValue = "false") boolean withCredentials,
@Parameter(description = "Did or BPN") @RequestParam(name = "withCredentials", defaultValue = "false") boolean withCredentials,
Principal principal) {

return ResponseEntity.status(HttpStatus.OK).body(service.getWalletByIdentifier(identifier, withCredentials, getBPNFromToken(principal)));
Expand Down
Loading

0 comments on commit ff51983

Please sign in to comment.