• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

FIWARE / contract-management / #67

27 Oct 2025 12:33PM UTC coverage: 1.686% (+0.04%) from 1.651%
#67

Pull #12

wistefan
wait for the policy
Pull Request #12: Support for central marketplace and policy creation

117 of 1238 new or added lines in 31 files covered. (9.45%)

5 existing lines in 2 files now uncovered.

587 of 34807 relevant lines covered (1.69%)

0.02 hits per line

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

56.67
/src/main/java/org/fiware/iam/til/TrustedIssuersListAdapter.java
1
package org.fiware.iam.til;
2

3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
import io.micronaut.http.HttpResponse;
6
import io.micronaut.http.HttpStatus;
7
import io.micronaut.http.client.exceptions.HttpClientResponseException;
8
import io.micronaut.http.exceptions.HttpException;
9
import jakarta.inject.Singleton;
10
import lombok.RequiredArgsConstructor;
11
import lombok.extern.slf4j.Slf4j;
12
import org.fiware.iam.exception.TMForumException;
13
import org.fiware.iam.exception.TrustedIssuersException;
14
import org.fiware.iam.til.api.IssuerApiClient;
15
import org.fiware.iam.til.model.ClaimVO;
16
import org.fiware.iam.til.model.CredentialsVO;
17
import org.fiware.iam.til.model.TrustedIssuerVO;
18
import org.fiware.iam.tmforum.CredentialsConfigResolver;
19
import reactor.core.publisher.Mono;
20

21
import java.util.*;
22

23
@Singleton
24
@RequiredArgsConstructor
25
@Slf4j
1✔
26
public class TrustedIssuersListAdapter {
27

28
    private final IssuerApiClient apiClient;
29

30
    public Mono<Boolean> allowIssuer(String issuerDid, List<CredentialsConfigResolver.CredentialConfig> credentialsConfig) {
31

32
        List<CredentialsVO> credentialsVOS = filterLocalCredentialsVO(credentialsConfig);
1✔
33
        if (credentialsVOS.isEmpty()) {
1✔
34
            // nothing to do, if no local cm is configured
NEW
35
            return Mono.just(true);
×
36
        }
37

38
        return getIssuer(issuerDid)
1✔
39
                .onErrorResume(e -> {
1✔
NEW
40
                    if (e instanceof HttpClientResponseException hcr && hcr.getStatus() == HttpStatus.NOT_FOUND) {
×
NEW
41
                        log.debug("Requested issuer {} does not exist.", issuerDid);
×
NEW
42
                        return Mono.just(Optional.empty());
×
43
                    }
NEW
44
                    throw new TrustedIssuersException("Client error on issuer retrieval.", e);
×
45
                })
46
                .flatMap(optionalIssuer -> {
1✔
47
                    if (optionalIssuer.isPresent()) {
1✔
48
                        TrustedIssuerVO trustedIssuerVO = optionalIssuer.get();
1✔
49
                        Set<CredentialsVO> credentialsVOSet = new HashSet<>(trustedIssuerVO.getCredentials());
1✔
50
                        credentialsVOSet.addAll(credentialsVOS);
1✔
51
                        trustedIssuerVO.setCredentials(new ArrayList<>(credentialsVOSet));
1✔
52
                        try {
53
                            log.debug("Updating existing issuer with {}", new ObjectMapper().writeValueAsString(trustedIssuerVO));
1✔
NEW
54
                        } catch (JsonProcessingException e) {
×
NEW
55
                            throw new RuntimeException(e);
×
56
                        }
1✔
57
                        return apiClient.updateIssuer(issuerDid, trustedIssuerVO)
1✔
58
                                .map(TrustedIssuersListAdapter::isSuccess);
1✔
59
                    } else {
60
                        //remove duplicates
61
                        Set<CredentialsVO> credentialsVOSet = new HashSet<>(credentialsVOS);
1✔
62
                        TrustedIssuerVO newIssuer = new TrustedIssuerVO().did(issuerDid).credentials(new ArrayList<>(credentialsVOSet));
1✔
63
                        log.debug("Adding new issuer with {}", newIssuer);
1✔
64
                        return apiClient.createTrustedIssuer(newIssuer).map(TrustedIssuersListAdapter::isSuccess);
1✔
65
                    }
66
                })
67
                .onErrorMap(e -> {
1✔
68
                    log.warn("Failed to allow.", e);
1✔
69
                    throw new TrustedIssuersException("Was not able to allow the issuer.", e);
1✔
70
                });
71
    }
72

73
    private static boolean isSuccess(HttpResponse response) {
74
        return response.getStatus().getCode() > 199 && response.getStatus().getCode() < 300;
1✔
75
    }
76

77
    public Mono<HttpResponse<?>> denyIssuer(String issuerDid, List<CredentialsConfigResolver.CredentialConfig> credentialsConfig) {
78

NEW
79
        List<CredentialsVO> credentialsVOS = filterLocalCredentialsVO(credentialsConfig);
×
NEW
80
        if (credentialsVOS.isEmpty()) {
×
81
            // nothing to do, if no local cm is configured
NEW
82
            return Mono.just(HttpResponse.noContent());
×
83
        }
NEW
84
        return getIssuer(issuerDid)
×
NEW
85
                .onErrorResume(e -> {
×
NEW
86
                    log.info("Was not able to get the issuer.", e);
×
NEW
87
                    return Mono.just(Optional.empty());
×
88
                })
NEW
89
                .flatMap(optionalIssuer -> {
×
NEW
90
                    if (optionalIssuer.isPresent()) {
×
NEW
91
                        TrustedIssuerVO updatedIssuer = optionalIssuer.get();
×
NEW
92
                        credentialsVOS.forEach(updatedIssuer::removeCredentialsItem);
×
93
                        try {
NEW
94
                            log.debug("Updating existing issuer with {}", new ObjectMapper().writeValueAsString(updatedIssuer));
×
NEW
95
                        } catch (JsonProcessingException e) {
×
NEW
96
                            throw new RuntimeException(e);
×
NEW
97
                        }
×
NEW
98
                        return apiClient.updateIssuer(issuerDid, updatedIssuer);
×
99
                    }
NEW
100
                    return Mono.just(HttpResponse.noContent());
×
101
                })
NEW
102
                .onErrorMap(e -> {
×
NEW
103
                    throw new TrustedIssuersException("Was not able to deny the issuer.", e);
×
104
                });
105
    }
106

107
    private Mono<Optional<TrustedIssuerVO>> getIssuer(String issuerDid) {
108
        return apiClient.getIssuer(issuerDid)
1✔
109
                .map(trustedIssuerVOHttpResponse -> {
1✔
110
                    if (trustedIssuerVOHttpResponse.code() != HttpStatus.OK.getCode()) {
1✔
111
                        log.debug("Could not find issuer {} in Trusted Issuers List. Status {}", issuerDid, trustedIssuerVOHttpResponse.code());
1✔
112
                        return Optional.empty();
1✔
113
                    }
114
                    return Optional.ofNullable(trustedIssuerVOHttpResponse.body());
1✔
115
                });
116

117
    }
118

119
    // only return credentials intended for local
120
    private List<CredentialsVO> filterLocalCredentialsVO(List<CredentialsConfigResolver.CredentialConfig> credentialsConfig) {
121
        return credentialsConfig.stream()
1✔
122
                .filter(credentialConfig -> credentialConfig.contractManagement().isLocal())
1✔
123
                .map(CredentialsConfigResolver.CredentialConfig::credentialsVOS)
1✔
124
                .flatMap(List::stream)
1✔
125
                .toList();
1✔
126
    }
127
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc