1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.util.repository;
20
21 import java.util.Map;
22
23 import org.eclipse.aether.repository.Authentication;
24 import org.eclipse.aether.repository.AuthenticationContext;
25 import org.eclipse.aether.repository.AuthenticationDigest;
26
27 import static java.util.Objects.requireNonNull;
28
29
30
31
32
33 final class ComponentAuthentication implements Authentication {
34
35 private final String key;
36
37 private final Object value;
38
39 ComponentAuthentication(String key, Object value) {
40 this.key = requireNonNull(key, "authentication key cannot be null");
41 if (key.isEmpty()) {
42 throw new IllegalArgumentException("authentication key cannot be empty");
43 }
44 this.value = value;
45 }
46
47 public void fill(AuthenticationContext context, String key, Map<String, String> data) {
48 requireNonNull(context, "context cannot be null");
49 context.put(this.key, value);
50 }
51
52 public void digest(AuthenticationDigest digest) {
53 requireNonNull(digest, "digest cannot be null");
54 if (value != null) {
55 digest.update(key, value.getClass().getName());
56 }
57 }
58
59 @Override
60 public boolean equals(Object obj) {
61 if (this == obj) {
62 return true;
63 }
64 if (obj == null || !getClass().equals(obj.getClass())) {
65 return false;
66 }
67 ComponentAuthentication that = (ComponentAuthentication) obj;
68 return key.equals(that.key) && eqClass(value, that.value);
69 }
70
71 private static <T> boolean eqClass(T s1, T s2) {
72 return (s1 == null) ? s2 == null : s2 != null && s1.getClass().equals(s2.getClass());
73 }
74
75 @Override
76 public int hashCode() {
77 int hash = 17;
78 hash = hash * 31 + key.hashCode();
79 hash = hash * 31 + ((value != null) ? value.getClass().hashCode() : 0);
80 return hash;
81 }
82
83 @Override
84 public String toString() {
85 return key + "=" + value;
86 }
87 }