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 import java.util.Objects;
23
24 import org.eclipse.aether.repository.Authentication;
25 import org.eclipse.aether.repository.AuthenticationContext;
26 import org.eclipse.aether.repository.AuthenticationDigest;
27
28 import static java.util.Objects.requireNonNull;
29
30
31
32
33 final class StringAuthentication implements Authentication {
34
35 private final String key;
36
37 private final String value;
38
39 StringAuthentication(String key, String 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 digest.update(key, value);
55 }
56
57 @Override
58 public boolean equals(Object obj) {
59 if (this == obj) {
60 return true;
61 }
62 if (obj == null || !getClass().equals(obj.getClass())) {
63 return false;
64 }
65 StringAuthentication that = (StringAuthentication) obj;
66 return Objects.equals(key, that.key) && Objects.equals(value, that.value);
67 }
68
69 @Override
70 public int hashCode() {
71 int hash = 17;
72 hash = hash * 31 + key.hashCode();
73 hash = hash * 31 + ((value != null) ? value.hashCode() : 0);
74 return hash;
75 }
76
77 @Override
78 public String toString() {
79 return key + "=" + value;
80 }
81 }