|
1 | 1 | /* |
2 | | - * Copyright (C) 2016-2022 Authlete, Inc. |
| 2 | + * Copyright (C) 2016-2023 Authlete, Inc. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
19 | 19 |
|
20 | 20 | import java.time.LocalDate; |
21 | 21 | import java.time.ZoneOffset; |
| 22 | +import java.util.ArrayList; |
22 | 23 | import java.util.Arrays; |
23 | 24 | import java.util.Date; |
24 | 25 | import java.util.HashMap; |
| 26 | +import java.util.LinkedHashMap; |
| 27 | +import java.util.List; |
25 | 28 | import java.util.Map; |
26 | 29 | import com.authlete.common.dto.Address; |
27 | 30 | import com.authlete.common.types.User; |
| 31 | +import com.authlete.mdoc.constants.MDLClaimNames; |
| 32 | +import com.authlete.mdoc.constants.MDLConstants; |
28 | 33 |
|
29 | 34 |
|
30 | 35 | /** |
@@ -68,12 +73,65 @@ public class UserDao |
68 | 73 | null, null, "Inga", "Silverstone", null, null, |
69 | 74 | "https://example.com/inga/profile", "https://example.com/inga/me.jpg", |
70 | 75 | "https://example.com/inga/", "female", "America/Toronto", "en-US", |
71 | | - "inga", "1991-11-06", toDate("2022-04-30") |
72 | | - ) |
| 76 | + "inga", "1991-11-06", toDate("2022-04-30")) |
| 77 | + .setAttribute(MDLConstants.DOC_TYPE_MDL, createMDLData1004()) |
73 | 78 | ); |
74 | 79 | }; |
75 | 80 |
|
76 | 81 |
|
| 82 | + private static Map<String, Object> createMDLData1004() |
| 83 | + { |
| 84 | + // Some string claim values in the data below have the prefix "cbor:". |
| 85 | + // They are interpreted by Authlete server. See the JavaDoc of the |
| 86 | + // CredentialIssuanceOrder class in the authlete-java-common library |
| 87 | + // for details. |
| 88 | + // |
| 89 | + // CredentialIssuerOrder JavaDoc |
| 90 | + // https://authlete.github.io/authlete-java-common/com/authlete/common/dto/CredentialIssuanceOrder.html |
| 91 | + // |
| 92 | + |
| 93 | + // { |
| 94 | + // "vehicle_category_code" : "A", |
| 95 | + // "issue_date" : "2023-01-01", |
| 96 | + // "expiry_date" : "2043-01-01" |
| 97 | + // } |
| 98 | + Map<String, Object> vehicleA = new LinkedHashMap<>(); |
| 99 | + vehicleA.put("vehicle_category_code", "A"); |
| 100 | + vehicleA.put("issue_date", "cbor:1004(\"2023-01-01\")"); |
| 101 | + vehicleA.put("expiry_date", "cbor:1004(\"2043-01-01\")"); |
| 102 | + |
| 103 | + // [ |
| 104 | + // vehicleA |
| 105 | + // ] |
| 106 | + List<Map<String, Object>> drivingPrivileges = new ArrayList<>(); |
| 107 | + drivingPrivileges.add(vehicleA); |
| 108 | + |
| 109 | + // { |
| 110 | + // "family_name" : "Silverstone", |
| 111 | + // "given_name" : "Inga", |
| 112 | + // "birth_date" : "1991-11-06", |
| 113 | + // "issuing_country" : "US", |
| 114 | + // "document_number" : "12345678", |
| 115 | + // "driving_privileges" : drivingPrivileges |
| 116 | + // } |
| 117 | + Map<String, Object> nameSpace = new LinkedHashMap<>(); |
| 118 | + nameSpace.put(MDLClaimNames.FAMILY_NAME, "Silverstone"); |
| 119 | + nameSpace.put(MDLClaimNames.GIVEN_NAME, "Inga"); |
| 120 | + nameSpace.put(MDLClaimNames.BIRTH_DATE, "cbor:1004(\"1991-11-06\")"); |
| 121 | + nameSpace.put(MDLClaimNames.ISSUING_COUNTRY, "US"); |
| 122 | + nameSpace.put(MDLClaimNames.DOCUMENT_NUMBER, "12345678"); |
| 123 | + nameSpace.put(MDLClaimNames.DRIVING_PRIVILEGES, drivingPrivileges); |
| 124 | + |
| 125 | + // { |
| 126 | + // "org.iso.18013.5.1" : nameSpace |
| 127 | + // } |
| 128 | + Map<String, Object> root = new LinkedHashMap<>(); |
| 129 | + root.put(MDLConstants.NAME_SPACE_MDL, nameSpace); |
| 130 | + |
| 131 | + return root; |
| 132 | + } |
| 133 | + |
| 134 | + |
77 | 135 | private static Date toDate(String input) |
78 | 136 | { |
79 | 137 | return Date.from(LocalDate.parse(input).atStartOfDay().toInstant(ZoneOffset.UTC)); |
|
0 commit comments