aboutsummaryrefslogtreecommitdiffstats
path: root/athenz-identity-provider-service/src/main/java/com/yahoo/vespa/hosted/ca/instance/InstanceIdentity.java
blob: 25c4cbb22811c9463e332d8296849bb1b5f78047 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.ca.instance;

import java.security.cert.X509Certificate;
import java.util.Objects;
import java.util.Optional;

/**
 * A signed instance identity object that includes a client certificate. This is the result of a successful
 * {@link InstanceRegistration} and is the same type as InstanceIdentity in the ZTS API.
 *
 * @author mpolden
 */
public class InstanceIdentity {

    private final String provider;
    private final String service;
    private final String instanceId;
    private final Optional<X509Certificate> x509Certificate;

    public InstanceIdentity(String provider, String service, String instanceId, Optional<X509Certificate> x509Certificate) {
        this.provider = Objects.requireNonNull(provider, "provider must be non-null");
        this.service = Objects.requireNonNull(service, "service must be non-null");
        this.instanceId = Objects.requireNonNull(instanceId, "instanceId must be non-null");
        this.x509Certificate = Objects.requireNonNull(x509Certificate, "x509Certificate must be non-null");
    }

    /** Same as {@link InstanceRegistration#domain()} */
    public String provider() {
        return provider;
    }

    /** Same as {@link InstanceRegistration#service()} ()} */
    public String service() {
        return service;
    }

    /** A unique identifier of the instance to which the certificate is issued */
    public String instanceId() {
        return instanceId;
    }

    /** The issued certificate */
    public Optional<X509Certificate> x509Certificate() {
        return x509Certificate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        InstanceIdentity that = (InstanceIdentity) o;
        return provider.equals(that.provider) &&
               service.equals(that.service) &&
               instanceId.equals(that.instanceId) &&
               x509Certificate.equals(that.x509Certificate);
    }

    @Override
    public int hashCode() {
        return Objects.hash(provider, service, instanceId, x509Certificate);
    }

}