• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FIWARE / credentials-config-service / 122

27 Oct 2026 04:04PM UTC coverage: 77.612% (-0.05%) from 77.657%
122

Pull #30

github

Mortega5
test: cover allowed redirect URI mapping

Update mapper expectations for serialized allowedRedirectUris.
Pull Request #30: feat: persist allowed redirect URIs

147 of 238 branches covered (61.76%)

Branch coverage included in aggregate %.

8 of 12 new or added lines in 1 file covered. (66.67%)

581 of 700 relevant lines covered (83.0%)

0.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.94
/src/main/java/org/fiware/iam/ServiceMapper.java
1
package org.fiware.iam;
2

3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.core.type.TypeReference;
5
import com.fasterxml.jackson.databind.ObjectMapper;
6
import io.github.wistefan.dcql.model.ClaimsQuery;
7
import io.github.wistefan.dcql.model.CredentialFormat;
8
import io.github.wistefan.dcql.model.CredentialQuery;
9
import io.github.wistefan.dcql.model.CredentialSetQuery;
10
import io.github.wistefan.dcql.model.DcqlQuery;
11
import io.github.wistefan.dcql.model.TrustedAuthorityQuery;
12
import io.github.wistefan.dcql.model.TrustedAuthorityType;
13
import org.fiware.iam.ccs.model.ClaimsQueryVO;
14
import org.fiware.iam.ccs.model.CredentialQueryVO;
15
import org.fiware.iam.ccs.model.CredentialSetQueryVO;
16
import org.fiware.iam.ccs.model.CredentialVO;
17
import org.fiware.iam.ccs.model.DCQLVO;
18
import org.fiware.iam.ccs.model.HolderVerificationVO;
19
import org.fiware.iam.ccs.model.InputDescriptorVO;
20
import org.fiware.iam.ccs.model.JwtInclusionVO;
21
import org.fiware.iam.ccs.model.MetaDataQueryVO;
22
import org.fiware.iam.ccs.model.PresentationDefinitionVO;
23
import org.fiware.iam.ccs.model.ServiceScopesEntryVO;
24
import org.fiware.iam.ccs.model.ServiceVO;
25
import org.fiware.iam.ccs.model.TrustedAuthorityQueryVO;
26
import org.fiware.iam.ccs.model.TrustedParticipantsListEndpointVO;
27
import org.fiware.iam.repository.AuthorizationType;
28
import org.fiware.iam.repository.Credential;
29
import org.fiware.iam.repository.EndpointEntry;
30
import org.fiware.iam.repository.EndpointType;
31
import org.fiware.iam.repository.Format;
32
import org.fiware.iam.repository.FormatObject;
33
import org.fiware.iam.repository.InputDescriptor;
34
import org.fiware.iam.repository.JwtInclusion;
35
import org.fiware.iam.repository.ListType;
36
import org.fiware.iam.repository.PresentationDefinition;
37
import org.fiware.iam.repository.ScopeEntry;
38
import org.fiware.iam.repository.Service;
39
import org.mapstruct.Mapper;
40

41
import java.util.ArrayList;
42
import java.util.Collection;
43
import java.util.HashMap;
44
import java.util.LinkedHashMap;
45
import java.util.List;
46
import java.util.Map;
47
import java.util.Optional;
48

49
/**
50
 * Responsible for mapping entities from the Service api domain to the internal model.
51
 */
52
@Mapper(componentModel = "jsr330")
53
public interface ServiceMapper {
54

55
    ObjectMapper OBJECT_MAPPER = new ObjectMapper();
1 ✔
56
    String JSON_PROPERTY_VCT_VALUES = "vct_values";
57
    String JSON_PROPERTY_DOCTYPE_VALUE = "doctype_value";
58
    String JSON_PROPERTY_TYPE_VALUES = "type_values";
59

60
    default Service map(ServiceVO serviceVO) {
61
        if (serviceVO == null) {
1 !
62
            return null;
×
63
        }
64
        Service service = new Service();
1 ✔
65
        service.setId(serviceVO.getId());
1 ✔
66
        service.setAuthorizationType(map(serviceVO.getAuthorizationType()));
1 ✔
67
        service.setDefaultOidcScope(serviceVO.getDefaultOidcScope());
1 ✔
68
        service.setAllowedRedirectUrisJson(serializeAllowedRedirectUris(serviceVO.getAllowedRedirectUris()));
1 ✔
69
        service.setOidcScopes(
1 ✔
70
                serviceVO.getOidcScopes()
1 ✔
71
                        .entrySet()
1 ✔
72
                        .stream()
1 ✔
73
                        .map(e -> {
1 ✔
74
                            ScopeEntry scopeEntry = new ScopeEntry();
1 ✔
75
                            scopeEntry.setScopeKey(e.getKey());
1 ✔
76
                            scopeEntry.setCredentials(Optional.ofNullable(e.getValue().getCredentials()).
1 ✔
77
                                    orElse(List.of()).stream().map(this::map).toList());
1 ✔
78
                            scopeEntry.setPresentationDefinition(this.map(e.getValue().getPresentationDefinition()));
1 ✔
79
                            scopeEntry.setDcqlQuery(this.map(e.getValue().getDcql()));
1 ✔
80
                            return scopeEntry;
1 ✔
81
                        })
82
                        .toList());
1 ✔
83
        return service;
1 ✔
84
    }
85

86
    default ServiceVO map(Service service) {
87
        if (service == null) {
1 !
88
            return null;
×
89
        }
90
        return new ServiceVO().id(service.getId())
1 ✔
91
                .authorizationType(map(service.getAuthorizationType()))
1 ✔
92
                .defaultOidcScope(service.getDefaultOidcScope())
1 ✔
93
                .allowedRedirectUris(deserializeAllowedRedirectUris(service.getAllowedRedirectUrisJson()))
1 ✔
94
                .oidcScopes(this.toOidcScopes(service.getOidcScopes()));
1 ✔
95
    }
96

97
    default String serializeAllowedRedirectUris(List<String> allowedRedirectUris) {
98
        if (allowedRedirectUris == null) {
1 ✔
99
            return null;
1 ✔
100
        }
101
        try {
102
            return OBJECT_MAPPER.writeValueAsString(allowedRedirectUris);
1 ✔
NEW
103
        } catch (JsonProcessingException e) {
×
NEW
104
            throw new IllegalArgumentException("Unable to serialize allowed redirect URIs.", e);
×
105
        }
106
    }
107

108
    default List<String> deserializeAllowedRedirectUris(String allowedRedirectUrisJson) {
109
        if (allowedRedirectUrisJson == null) {
1 ✔
110
            return null;
1 ✔
111
        }
112
        try {
113
            return OBJECT_MAPPER.readValue(allowedRedirectUrisJson, new TypeReference<>() {});
1 ✔
NEW
114
        } catch (JsonProcessingException e) {
×
NEW
115
            throw new IllegalStateException("Unable to deserialize stored allowed redirect URIs.", e);
×
116
        }
117
    }
118

119
    default PresentationDefinition map(PresentationDefinitionVO presentationDefinitionVO) {
120
        if (presentationDefinitionVO == null) {
1 ✔
121
            return null;
1 ✔
122
        }
123

124
        PresentationDefinition presentationDefinition = new PresentationDefinition();
1 ✔
125
        presentationDefinition.setId(presentationDefinitionVO.getId());
1 ✔
126
        presentationDefinition.setName(presentationDefinitionVO.getName());
1 ✔
127
        presentationDefinition.setPurpose(presentationDefinitionVO.getPurpose());
1 ✔
128
        presentationDefinition.setInputDescriptors(this.mapInputDescriptors(presentationDefinitionVO
1 ✔
129
                .getInputDescriptors()));
1 ✔
130
        presentationDefinition.setFormat(this.mapFormatVO(presentationDefinitionVO
1 ✔
131
                .getFormat()));
1 ✔
132

133
        return presentationDefinition;
1 ✔
134
    }
135

136
    default Collection<InputDescriptor> mapInputDescriptors(Collection<InputDescriptorVO> inputDescriptorVOS) {
137
        if (inputDescriptorVOS == null) {
1 !
138
            return null;
×
139
        }
140
        return inputDescriptorVOS
1 ✔
141
                .stream()
1 ✔
142
                .map(this::mapInputDescriptorVO).toList();
1 ✔
143
    }
144

145
    default Collection<Format> mapFormatVO(Map<String, Object> formatsMap) {
146
        if (formatsMap == null) {
1 !
147
            return null;
×
148
        }
149

150
        return formatsMap
1 ✔
151
                .entrySet()
1 ✔
152
                .stream()
1 ✔
153
                .map(e -> {
1 ✔
154
                    FormatObject formatObject = OBJECT_MAPPER.convertValue(e.getValue(), FormatObject.class);
1 ✔
155
                    Format format = new Format();
1 ✔
156
                    format.setFormatKey(e.getKey());
1 ✔
157
                    format.setAlg(formatObject.getAlg());
1 ✔
158
                    format.setProofType(formatObject.getProofType());
1 ✔
159
                    return format;
1 ✔
160
                }).toList();
1 ✔
161
    }
162

163
    default Map<String, Object> mapFormats(Collection<Format> formats) {
164
        if (formats == null) {
1 ✔
165
            return null;
1 ✔
166
        }
167

168
        Map<String, Object> formatsMap = new HashMap<>();
1 ✔
169

170
        formats.forEach(format -> {
1 ✔
171
            Map<String, Object> formatMap = new HashMap<>();
1 ✔
172
            Optional.ofNullable(format.getAlg()).ifPresent(algs -> formatMap.put("alg", algs));
1 ✔
173
            Optional.ofNullable(format.getProofType()).ifPresent(pt -> formatMap.put("proof_type", pt));
1 ✔
174
            formatsMap.put(format.getFormatKey(), formatMap);
1 ✔
175
        });
1 ✔
176

177
        return formatsMap;
1 ✔
178
    }
179

180
    AuthorizationType map(ServiceVO.AuthorizationType authorizationType);
181

182
    ServiceVO.AuthorizationType map(AuthorizationType authorizationType);
183

184
    InputDescriptorVO mapInputDescriptor(InputDescriptor inputDescriptor);
185

186
    InputDescriptor mapInputDescriptorVO(InputDescriptorVO inputDescriptor);
187

188
    PresentationDefinitionVO map(PresentationDefinition presentationDefinition);
189

190
    TrustedParticipantsListEndpointVO.Type map(ListType type);
191

192
    ListType map(TrustedParticipantsListEndpointVO.Type type);
193

194
    default Map<String, ServiceScopesEntryVO> toOidcScopes(Collection<ScopeEntry> scopeEntries) {
195
        if (scopeEntries == null) {
1 !
196
            return null;
×
197
        }
198
        Map<String, ServiceScopesEntryVO> scopes = new LinkedHashMap<>();
1 ✔
199
        scopeEntries
1 ✔
200
                .forEach(entry -> {
1 ✔
201
                    ServiceScopesEntryVO scopesEntryVO = new ServiceScopesEntryVO();
1 ✔
202
                    scopesEntryVO.setPresentationDefinition(this.map(entry.getPresentationDefinition()));
1 ✔
203
                    scopesEntryVO.setCredentials(this.map(entry.getCredentials()));
1 ✔
204
                    scopesEntryVO.setDcql(this.map(entry.getDcqlQuery()));
1 ✔
205
                    scopes.put(entry.getScopeKey(), scopesEntryVO);
1 ✔
206
                });
1 ✔
207
        return scopes;
1 ✔
208
    }
209

210
    DCQLVO map(DcqlQuery dcqlQuery);
211

212
    DcqlQuery map(DCQLVO dcqlvo);
213

214
    default CredentialQuery map(CredentialQueryVO credentialQueryVO) {
215
        if (credentialQueryVO == null) {
1 !
216
            return null;
×
217
        }
218
        CredentialQuery credentialQuery = new CredentialQuery();
1 ✔
219
        credentialQuery.setId(credentialQueryVO.getId());
1 ✔
220
        credentialQuery.setFormat(this.map(credentialQueryVO.getFormat()));
1 ✔
221
        credentialQuery.setMultiple(credentialQueryVO.getMultiple());
1 ✔
222
        credentialQuery.setClaims(Optional.ofNullable(credentialQueryVO.getClaims()).orElse(List.of())
1 ✔
223
                .stream().map(this::map).toList());
1 ✔
224
        credentialQuery.setMeta(this.map(credentialQueryVO.getMeta()));
1 ✔
225
        credentialQuery.setRequireCryptographicHolderBinding(credentialQueryVO.getRequireCryptographicHolderBinding());
1 ✔
226
        credentialQuery.setClaimSets(credentialQueryVO.getClaimSets());
1 ✔
227
        credentialQuery.setTrustedAuthorities(Optional.ofNullable(credentialQueryVO.getTrustedAuthorities()).orElse(List.of())
1 ✔
228
                .stream().map(this::map).toList());
1 ✔
229
        return credentialQuery;
1 ✔
230
    }
231

232
    default CredentialQueryVO map(CredentialQuery credentialQuery) {
233
        if (credentialQuery == null) {
1 !
234
            return null;
×
235
        }
236
        CredentialQueryVO credentialQueryVO = new CredentialQueryVO();
1 ✔
237
        credentialQueryVO.setId(credentialQuery.getId());
1 ✔
238
        credentialQueryVO.setFormat(this.map(credentialQuery.getFormat()));
1 ✔
239
        credentialQueryVO.setMultiple(credentialQuery.getMultiple());
1 ✔
240
        credentialQueryVO.setClaims(Optional.ofNullable(credentialQuery.getClaims()).orElse(List.of())
1 ✔
241
                .stream().map(this::map).toList());
1 ✔
242
        credentialQueryVO.setMeta(map(credentialQuery.getMeta()));
1 ✔
243
        credentialQueryVO.setRequireCryptographicHolderBinding(credentialQuery.getRequireCryptographicHolderBinding());
1 ✔
244
        credentialQueryVO.setClaimSets(credentialQuery.getClaimSets());
1 ✔
245
        credentialQueryVO.setTrustedAuthorities(Optional.ofNullable(credentialQuery.getTrustedAuthorities()).orElse(List.of())
1 ✔
246
                .stream().map(this::map).toList());
1 ✔
247
        return credentialQueryVO;
1 ✔
248
    }
249

250
    TrustedAuthorityQueryVO map(TrustedAuthorityQuery trustedAuthorityQuery);
251

252
    TrustedAuthorityQuery map(TrustedAuthorityQueryVO trustedAuthorityQueryVO);
253

254
    default TrustedAuthorityType map(String type) {
255
        return TrustedAuthorityType.fromValue(type);
1 ✔
256
    }
257

258
    default String map(TrustedAuthorityType type) {
259
        return type.getValue();
1 ✔
260
    }
261

262
    default Map<String, Object> map(MetaDataQueryVO metaDataQueryVO) {
263
        if (metaDataQueryVO == null) {
1 !
264
            return null;
×
265
        }
266
        Map<String, Object> metaMap = new HashMap<>();
1 ✔
267
        if (metaDataQueryVO.getVctValues() != null) {
1 !
268
            metaMap.put(JSON_PROPERTY_VCT_VALUES, metaDataQueryVO.getVctValues());
1 ✔
269
        }
270
        if (metaDataQueryVO.getTypeValues() != null) {
1 !
271
            metaMap.put(JSON_PROPERTY_TYPE_VALUES, metaDataQueryVO.getTypeValues());
1 ✔
272
        }
273
        if (metaDataQueryVO.getDoctypeValue() != null) {
1 !
274
            metaMap.put(JSON_PROPERTY_DOCTYPE_VALUE, metaDataQueryVO.getDoctypeValue());
1 ✔
275
        }
276
        return metaMap;
1 ✔
277
    }
278

279
    default MetaDataQueryVO map(Map<String, Object> meta) {
280
        if (meta == null) {
1 !
281
            return null;
×
282
        }
283
        MetaDataQueryVO metaDataQueryVO = new MetaDataQueryVO();
1 ✔
284
        if (meta.containsKey(JSON_PROPERTY_VCT_VALUES)) {
1 !
285
            metaDataQueryVO.setVctValues((List<String>) meta.get(JSON_PROPERTY_VCT_VALUES));
1 ✔
286
        }
287
        if (meta.containsKey(JSON_PROPERTY_DOCTYPE_VALUE)) {
1 !
288
            metaDataQueryVO.setDoctypeValue((String) meta.get(JSON_PROPERTY_DOCTYPE_VALUE));
1 ✔
289
        }
290
        if (meta.containsKey(JSON_PROPERTY_TYPE_VALUES)) {
1 !
291
            metaDataQueryVO.setTypeValues((List<List<String>>) meta.get(JSON_PROPERTY_TYPE_VALUES));
1 ✔
292
        }
293
        return metaDataQueryVO;
1 ✔
294
    }
295

296
    ClaimsQuery map(ClaimsQueryVO claimsQueryVO);
297

298
    ClaimsQueryVO map(ClaimsQuery claimsQuery);
299

300
    CredentialQueryVO.Format map(CredentialFormat credentialFormat);
301

302
    CredentialFormat map(CredentialQueryVO.Format credentialFormat);
303

304
    CredentialSetQueryVO map(CredentialSetQuery credentialSetQuery);
305

306
    CredentialSetQuery map(CredentialSetQueryVO credentialSetQueryVO);
307

308
    default EndpointEntry stringToEndpointEntry(String url) {
309
        EndpointEntry entry = new EndpointEntry();
1 ✔
310
        entry.setType(EndpointType.TRUSTED_PARTICIPANTS);
1 ✔
311
        entry.setListType(ListType.EBSI);
1 ✔
312
        entry.setEndpoint(url);
1 ✔
313
        return entry;
1 ✔
314
    }
315

316
    default Credential map(CredentialVO credentialVO) {
317
        if (credentialVO == null) {
1 !
318
            return null;
×
319
        }
320
        Credential credential = new Credential();
1 ✔
321
        credential.setCredentialType(credentialVO.getType());
1 ✔
322
        List<EndpointEntry> trustedList = new ArrayList<>();
1 ✔
323
        Optional.ofNullable(issuersToEntries(credentialVO.getTrustedIssuersLists())).ifPresent(trustedList::addAll);
1 ✔
324

325
        credentialVO.getTrustedParticipantsLists()
1 ✔
326
                .forEach(tpl -> {
1 ✔
327
                    if (tpl instanceof String tplS) {
1 ✔
328
                        trustedList.add(stringToEndpointEntry(tplS));
1 ✔
329
                    } else {
330
                        trustedList.add(participantToEntry(OBJECT_MAPPER.convertValue(tpl, TrustedParticipantsListEndpointVO.class)));
1 ✔
331
                    }
332
                });
1 ✔
333

334
        credential.setTrustedLists(trustedList);
1 ✔
335

336
        if (credentialVO.getHolderVerification() != null) {
1 !
337
            credential.setHolderClaim(credentialVO.getHolderVerification().getClaim());
1 ✔
338
            credential.setVerifyHolder(credentialVO.getHolderVerification().getEnabled());
1 ✔
339
        } else {
340
            credential.setVerifyHolder(false);
×
341
            credential.setHolderClaim(null);
×
342
        }
343
        credential.setRequireCompliance(credentialVO.getRequireCompliance());
1 ✔
344
        credential.setJwtInclusion(map(credentialVO.getJwtInclusion()));
1 ✔
345
        return credential;
1 ✔
346
    }
347

348
    JwtInclusion map(JwtInclusionVO jwtInclusionVO);
349

350
    JwtInclusionVO map(JwtInclusion jwtInclusion);
351

352
    default List<CredentialVO> map(Collection<Credential> credentials) {
353
        if (credentials == null) {
1 !
354
            return null;
×
355
        }
356
        return credentials.stream().map(this::map).toList();
1 ✔
357
    }
358

359
    default CredentialVO map(Credential credential) {
360
        if (credential == null) {
1 !
361
            return null;
×
362
        }
363
        return new CredentialVO()
1 ✔
364
                .type(credential.getCredentialType())
1 ✔
365
                .trustedIssuersLists(entriesToIssuers(credential.getTrustedLists()))
1 ✔
366
                .trustedParticipantsLists(entriesToParticipants(credential.getTrustedLists()).stream().map(Object.class::cast).toList())
1 ✔
367
                .requireCompliance(credential.isRequireCompliance())
1 ✔
368
                .jwtInclusion(map(credential.getJwtInclusion()))
1 ✔
369
                .holderVerification(new HolderVerificationVO()
1 ✔
370
                        .enabled(credential.isVerifyHolder())
1 ✔
371
                        .claim(credential.getHolderClaim()));
1 ✔
372
    }
373

374
    /**
375
     * Map a list of TrustedParticipantsListVO-entries, to a list of {@link EndpointEntry} with
376
     * type {{@link EndpointType#TRUSTED_PARTICIPANTS}
377
     */
378
    default List<EndpointEntry> participantsToEntries(List<TrustedParticipantsListEndpointVO> endpoints) {
379
        if (endpoints == null) {
×
380
            return null;
×
381
        }
382
        return endpoints.stream()
×
383
                .map(endpoint -> {
×
384
                    EndpointEntry entry = new EndpointEntry();
×
385
                    entry.setEndpoint(endpoint.getUrl());
×
386
                    entry.setListType(map(endpoint.getType()));
×
387
                    entry.setType(EndpointType.TRUSTED_PARTICIPANTS);
×
388
                    return entry;
×
389
                })
390
                .toList();
×
391
    }
392

393
    default EndpointEntry participantToEntry(TrustedParticipantsListEndpointVO trustedParticipantsListVO) {
394
        if (trustedParticipantsListVO == null) {
1 !
395
            return null;
×
396
        }
397
        EndpointEntry entry = new EndpointEntry();
1 ✔
398
        entry.setEndpoint(trustedParticipantsListVO.getUrl());
1 ✔
399
        entry.setListType(map(trustedParticipantsListVO.getType()));
1 ✔
400
        entry.setType(EndpointType.TRUSTED_PARTICIPANTS);
1 ✔
401
        return entry;
1 ✔
402
    }
403

404
    /**
405
     * Map a list of string-entries, encoding TrustedIssuers endpoints to a list of {@link EndpointEntry} with
406
     * type {{@link EndpointType#TRUSTED_ISSUERS}
407
     */
408
    default List<EndpointEntry> issuersToEntries(List<String> endpoints) {
409
        if (endpoints == null) {
1 !
410
            return null;
×
411
        }
412
        return endpoints.stream()
1 ✔
413
                .map(endpoint -> {
1 ✔
414
                    EndpointEntry entry = new EndpointEntry();
1 ✔
415
                    entry.setEndpoint(endpoint);
1 ✔
416
                    entry.setType(EndpointType.TRUSTED_ISSUERS);
1 ✔
417
                    return entry;
1 ✔
418
                })
419
                .toList();
1 ✔
420
    }
421

422
    /**
423
     * Return issuer endpoints from the {@link EndpointEntry} list to a list of strings
424
     */
425
    default List<String> entriesToIssuers(List<EndpointEntry> endpoints) {
426
        if (endpoints == null) {
1 ✔
427
            return List.of();
1 ✔
428
        }
429
        return endpoints.stream()
1 ✔
430
                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_ISSUERS))
1 ✔
431
                .map(EndpointEntry::getEndpoint)
1 ✔
432
                .toList();
1 ✔
433
    }
434

435
    /**
436
     * Return participant endpoints from the {@link EndpointEntry} list to a list of strings
437
     */
438
    default List<TrustedParticipantsListEndpointVO> entriesToParticipants(List<EndpointEntry> endpoints) {
439
        if (endpoints == null) {
1 ✔
440
            return List.of();
1 ✔
441
        }
442
        return endpoints.stream()
1 ✔
443
                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_PARTICIPANTS))
1 ✔
444
                .map(entry -> new TrustedParticipantsListEndpointVO()
1 ✔
445
                        .type(map(entry.getListType()))
1 ✔
446
                        .url(entry.getEndpoint()))
1 ✔
447
                .toList();
1 ✔
448
    }
449

450
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc