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

FIWARE / trusted-issuers-list / 85

26 May 2026 10:38AM UTC coverage: 87.146% (+2.6%) from 84.584%
85

Pull #26

github

web-flow
Update changelog-v0_0_5.xml
Pull Request #26: enable v5 api

147 of 187 branches covered (78.61%)

Branch coverage included in aggregate %.

497 of 548 new or added lines in 16 files covered. (90.69%)

592 of 661 relevant lines covered (89.56%)

0.9 hits per line

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

78.95
/src/main/java/org/fiware/iam/TIRMapper.java
1
/*
2
 * Copyright 2023 FIWARE Foundation e.V. and/or its affiliates
3
 * and other contributors as indicated by the @author tags.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.fiware.iam;
18

19
import com.fasterxml.jackson.core.JsonProcessingException;
20
import com.fasterxml.jackson.databind.ObjectMapper;
21
import com.fasterxml.jackson.databind.ObjectWriter;
22
import java.security.MessageDigest;
23
import java.util.Base64;
24
import java.util.List;
25
import java.util.Objects;
26
import lombok.SneakyThrows;
27
import org.fiware.iam.repository.Claim;
28
import org.fiware.iam.repository.Credential;
29
import org.fiware.iam.repository.TrustedIssuer;
30
import org.fiware.iam.til.model.ClaimVO;
31
import org.fiware.iam.til.model.CredentialsVO;
32
import org.fiware.iam.tir.model.IssuerAttributeVO;
33
import org.fiware.iam.tir.model.IssuerVO;
34
import org.mapstruct.Mapper;
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

38
/**
39
 * Responsible for mapping entities from the (EBSI-) Trusted Issuers Registry domain to the internal
40
 * model.
41
 */
42
@Mapper(componentModel = "jsr330")
43
public interface TIRMapper {
44

45
  Logger LOGGER = LoggerFactory.getLogger(TIRMapper.class);
1✔
46
  ObjectWriter OBJECT_WRITER = new ObjectMapper().writer();
1✔
47

48
  CredentialsVO map(Credential credential);
49

50
  default ClaimVO map(Claim claim) {
51
    return new ClaimVO()
1✔
52
        .name(claim.getName())
1✔
53
        .path(claim.getPath())
1✔
54
        .allowedValues(
1✔
55
            claim.getClaimValues().stream()
1✔
56
                .map(TILMapper::readToObject)
1✔
57
                .filter(Objects::nonNull)
1✔
58
                .toList());
1✔
59
  }
60

61
  /**
62
   * Map an internal trusted issuer to a proper issuerVO. Will handle the hashing and encoding of
63
   * the attributes.
64
   */
65
  default IssuerVO map(TrustedIssuer trustedIssuer) {
66
    IssuerVO issuerVO = new IssuerVO().did(trustedIssuer.getDid());
1✔
67

68
    List<IssuerAttributeVO> issuerAttributeVOS =
1✔
69
        trustedIssuer.getCredentials().stream().map(this::mapToAttribute).toList();
1✔
70
    issuerVO.attributes(issuerAttributeVOS);
1✔
71
    return issuerVO;
1✔
72
  }
73

74
  /**
75
   * Map a credential entity directly to an IssuerAttributeVO, preserving issuerType, tao, and
76
   * rootTao. The credential body is serialized from its CredentialsVO representation, then
77
   * Base64-encoded.
78
   *
79
   * @param credential the credential entity
80
   * @return the mapped issuer attribute VO
81
   */
82
  default IssuerAttributeVO mapToAttribute(Credential credential) {
83
    IssuerAttributeVO issuerAttributeVO = new IssuerAttributeVO();
1✔
84
    issuerAttributeVO.issuerType(mapIssuerType(credential.getIssuerType()));
1✔
85
    issuerAttributeVO.tao(credential.getTao());
1✔
86
    issuerAttributeVO.rootTao(credential.getRootTao());
1✔
87
    try {
88
      CredentialsVO credentialsVO = map(credential);
1✔
89
      byte[] body = OBJECT_WRITER.writeValueAsBytes(credentialsVO);
1✔
90
      issuerAttributeVO.body(Base64.getEncoder().encodeToString(body));
1✔
91
      issuerAttributeVO.hash(Base64.getEncoder().encodeToString(getSHA256(body)));
1✔
NEW
92
    } catch (JsonProcessingException jpe) {
×
NEW
93
      LOGGER.warn(
×
94
          "Was not able to process the given credential {}. Will not include it into the issuer.",
95
          credential,
96
          jpe);
97
    }
1✔
98
    return issuerAttributeVO;
1✔
99
  }
100

101
  /**
102
   * Convert a stored issuerType string to the v4 IssuerType enum. Falls back to {@link
103
   * IssuerAttributeVO.IssuerType#UNDEFINED} for null or unrecognized values.
104
   *
105
   * @param issuerType the stored issuer type string (may be null)
106
   * @return the corresponding enum value
107
   */
108
  default IssuerAttributeVO.IssuerType mapIssuerType(String issuerType) {
109
    if (issuerType == null) {
1!
110
      return IssuerAttributeVO.IssuerType.UNDEFINED;
1✔
111
    }
112
    try {
NEW
113
      return IssuerAttributeVO.IssuerType.toEnum(issuerType);
×
NEW
114
    } catch (IllegalArgumentException e) {
×
NEW
115
      LOGGER.warn("Unknown issuerType value '{}', defaulting to UNDEFINED.", issuerType);
×
NEW
116
      return IssuerAttributeVO.IssuerType.UNDEFINED;
×
117
    }
118
  }
119

120
  /**
121
   * Builds a sha-256 hash for the given byte array
122
   *
123
   * @param toHash the array to hash
124
   * @return the hash
125
   */
NEW
126
  @SneakyThrows
×
127
  default byte[] getSHA256(byte[] toHash) {
128
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
1✔
129
    return digest.digest(toHash);
1✔
130
  }
131
}
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