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

FIWARE / contract-management / #26

28 Jan 2025 10:59AM UTC coverage: 0.982% (-0.6%) from 1.629%
#26

push

web-flow
Merge pull request #3 from FIWARE/tpp-integration

Tpp integration

99 of 500 new or added lines in 14 files covered. (19.8%)

4 existing lines in 3 files now uncovered.

281 of 28625 relevant lines covered (0.98%)

0.01 hits per line

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

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

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

18
import java.util.*;
19

20
@Singleton
21
@RequiredArgsConstructor
22
@Slf4j
1✔
23
public class TrustedIssuersListAdapter {
24

25
        private final IssuerApiClient apiClient;
26
        private final TrustedIssuerConfigProvider trustedIssuerConfigProvider;
27

28
        public Mono<?> allowIssuer(String issuerDid) {
29
                CredentialsVO credentialToBeAdded = trustedIssuerConfigProvider.createCredentialConfigForTargetService();
1✔
30

31
                return getIssuer(issuerDid)
1✔
32
                                .onErrorResume(e -> {
1✔
NEW
33
                                        if (e instanceof HttpClientResponseException hcr && hcr.getStatus() == HttpStatus.NOT_FOUND) {
×
NEW
34
                                                log.debug("Requested issuer {} does not exist.", issuerDid);
×
NEW
35
                                                return Mono.just(Optional.empty());
×
36
                                        }
NEW
37
                                        throw new TrustedIssuersException("Client error on issuer retrieval.", e);
×
38
                                })
39
                                .flatMap(optionalIssuer -> {
1✔
40
                                        if (optionalIssuer.isPresent()) {
1✔
41
                                                CredentialsVO cvo = optionalIssuer.get().getCredentials()
1✔
42
                                                                .stream()
1✔
43
                                                                .filter(credentialsVO -> credentialsVO.getCredentialsType().equals(credentialToBeAdded.getCredentialsType()))
1✔
44
                                                                .findAny()
1✔
45
                                                                .orElse(credentialToBeAdded);
1✔
46
                                                TrustedIssuerVO trustedIssuerVO = optionalIssuer.get();
1✔
47

48
                                                // convert to set, to prevent duplicates
49
                                                Set<ClaimVO> claimSet = new HashSet<>(cvo.getClaims());
1✔
50
                                                claimSet.addAll(credentialToBeAdded.getClaims());
1✔
51
                                                cvo.claims(new ArrayList<>(claimSet));
1✔
52

53
                                                Set<CredentialsVO> credentialsVOSet = new HashSet<>(trustedIssuerVO.getCredentials());
1✔
54
                                                credentialsVOSet.add(cvo);
1✔
55
                                                trustedIssuerVO.setCredentials(new ArrayList<>(credentialsVOSet));
1✔
56
                                                log.debug("Updating existing issuer with {}", trustedIssuerVO);
1✔
57
                                                return apiClient.updateIssuer(issuerDid, trustedIssuerVO);
1✔
58
                                        } else {
59
                                                TrustedIssuerVO newIssuer = new TrustedIssuerVO().did(issuerDid).addCredentialsItem(credentialToBeAdded);
1✔
60
                                                log.debug("Adding new issuer with {}", newIssuer);
1✔
61
                                                return apiClient.createTrustedIssuer(newIssuer);
1✔
62
                                        }
63
                                })
64
                                .onErrorMap(e -> {
1✔
65
                                        throw new TrustedIssuersException("Was not able to allow the issuer.", e);
1✔
66
                                });
67

68
        }
69

70
        public Mono<HttpResponse<?>> denyIssuer(String issuerDid) {
NEW
71
                CredentialsVO credentialToBeRemoved = trustedIssuerConfigProvider.createCredentialConfigForTargetService();
×
72

NEW
73
                return getIssuer(issuerDid)
×
NEW
74
                                .onErrorResume(e -> {
×
NEW
75
                                        log.info("Was not able to get the issuer.", e);
×
NEW
76
                                        return Mono.just(Optional.empty());
×
77
                                })
NEW
78
                                .flatMap(optionalIssuer -> {
×
NEW
79
                                        if (optionalIssuer.isPresent()) {
×
NEW
80
                                                TrustedIssuerVO updatedIssuer = optionalIssuer.get().removeCredentialsItem(credentialToBeRemoved);
×
NEW
81
                                                log.debug("Updating existing issuer with {}", updatedIssuer);
×
NEW
82
                                                return apiClient.updateIssuer(issuerDid, updatedIssuer);
×
83
                                        }
NEW
84
                                        return Mono.just(HttpResponse.noContent());
×
85
                                })
NEW
86
                                .onErrorMap(e -> {
×
NEW
87
                                        throw new TrustedIssuersException("Was not able to deny the issuer.", e);
×
88
                                });
89

90
        }
91

92
        private Mono<Optional<TrustedIssuerVO>> getIssuer(String issuerDid) {
93
                return apiClient.getIssuer(issuerDid)
1✔
94
                                .map(trustedIssuerVOHttpResponse -> {
1✔
95
                                        if (trustedIssuerVOHttpResponse.code() != HttpStatus.OK.getCode()) {
1✔
96
                                                log.debug("Could not find issuer {} in Trusted Issuers List. Status {}", issuerDid, trustedIssuerVOHttpResponse.code());
1✔
97
                                                return Optional.empty();
1✔
98
                                        }
99
                                        return Optional.ofNullable(trustedIssuerVOHttpResponse.body());
1✔
100
                                });
101

102
        }
103
}
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