1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.linecorp.centraldogma.server.internal.mirror.credential;
18
19 import static com.linecorp.centraldogma.server.CentralDogmaConfig.convertValue;
20 import static com.linecorp.centraldogma.server.internal.mirror.credential.MirrorCredentialUtil.requireNonEmpty;
21
22 import java.util.regex.Pattern;
23
24 import javax.annotation.Nullable;
25
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import com.fasterxml.jackson.annotation.JsonCreator;
30 import com.fasterxml.jackson.annotation.JsonProperty;
31 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
32 import com.google.common.base.MoreObjects.ToStringHelper;
33
34 public final class AccessTokenMirrorCredential extends AbstractMirrorCredential {
35
36 private static final Logger logger = LoggerFactory.getLogger(AccessTokenMirrorCredential.class);
37
38 private final String accessToken;
39
40 @JsonCreator
41 public AccessTokenMirrorCredential(@JsonProperty("id") @Nullable String id,
42 @JsonProperty("hostnamePatterns") @Nullable
43 @JsonDeserialize(contentAs = Pattern.class)
44 Iterable<Pattern> hostnamePatterns,
45 @JsonProperty("accessToken") String accessToken) {
46 super(id, hostnamePatterns);
47 this.accessToken = requireNonEmpty(accessToken, "accessToken");
48 }
49
50 public String accessToken() {
51 try {
52 return convertValue(accessToken, "credentials.accessToken");
53 } catch (Throwable t) {
54
55 logger.debug("Failed to convert the access token of the credential: {}", id(), t);
56 return accessToken;
57 }
58 }
59
60 @Override
61 public int hashCode() {
62 int result = super.hashCode();
63 result = 31 * result + accessToken.hashCode();
64 return result;
65 }
66
67 @Override
68 public boolean equals(Object o) {
69 if (this == o) {
70 return true;
71 }
72
73 if (!(o instanceof AccessTokenMirrorCredential)) {
74 return false;
75 }
76
77 if (!super.equals(o)) {
78 return false;
79 }
80
81 final AccessTokenMirrorCredential that = (AccessTokenMirrorCredential) o;
82 return accessToken.equals(that.accessToken);
83 }
84
85 @Override
86 void addProperties(ToStringHelper helper) {
87
88 }
89 }