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.Arrays;
22 import java.util.Collection;
23 import java.util.Map;
24
25 import org.eclipse.aether.repository.Authentication;
26 import org.eclipse.aether.repository.AuthenticationContext;
27 import org.eclipse.aether.repository.AuthenticationDigest;
28
29 import static java.util.Objects.requireNonNull;
30
31
32
33
34
35 final class ChainedAuthentication implements Authentication {
36
37 private final Authentication[] authentications;
38
39 ChainedAuthentication(Authentication... authentications) {
40 if (authentications != null && authentications.length > 0) {
41 this.authentications = authentications.clone();
42 } else {
43 this.authentications = new Authentication[0];
44 }
45 }
46
47 ChainedAuthentication(Collection<? extends Authentication> authentications) {
48 if (authentications != null && !authentications.isEmpty()) {
49 this.authentications = authentications.toArray(new Authentication[0]);
50 } else {
51 this.authentications = new Authentication[0];
52 }
53 }
54
55 public void fill(AuthenticationContext context, String key, Map<String, String> data) {
56 requireNonNull(context, "context cannot be null");
57 for (Authentication authentication : authentications) {
58 authentication.fill(context, key, data);
59 }
60 }
61
62 public void digest(AuthenticationDigest digest) {
63 requireNonNull(digest, "digest cannot be null");
64 for (Authentication authentication : authentications) {
65 authentication.digest(digest);
66 }
67 }
68
69 @Override
70 public boolean equals(Object obj) {
71 if (this == obj) {
72 return true;
73 }
74 if (obj == null || !getClass().equals(obj.getClass())) {
75 return false;
76 }
77 ChainedAuthentication that = (ChainedAuthentication) obj;
78 return Arrays.equals(authentications, that.authentications);
79 }
80
81 @Override
82 public int hashCode() {
83 return Arrays.hashCode(authentications);
84 }
85
86 @Override
87 public String toString() {
88 StringBuilder buffer = new StringBuilder(256);
89 for (Authentication authentication : authentications) {
90 if (buffer.length() > 0) {
91 buffer.append(", ");
92 }
93 buffer.append(authentication);
94 }
95 return buffer.toString();
96 }
97 }