1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.transport;
11
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.List;
15
16 import org.eclipse.jgit.errors.UnsupportedCredentialItem;
17
18
19
20
21
22
23 public class ChainingCredentialsProvider extends CredentialsProvider {
24
25 private List<CredentialsProvider> credentialProviders;
26
27
28
29
30
31
32
33
34
35
36
37 public ChainingCredentialsProvider(CredentialsProvider... providers) {
38 this.credentialProviders = new ArrayList<>(
39 Arrays.asList(providers));
40 }
41
42
43 @Override
44 public boolean isInteractive() {
45 for (CredentialsProvider p : credentialProviders)
46 if (p.isInteractive())
47 return true;
48 return false;
49 }
50
51
52 @Override
53 public boolean supports(CredentialItem... items) {
54 for (CredentialsProvider p : credentialProviders)
55 if (p.supports(items))
56 return true;
57 return false;
58 }
59
60
61
62
63
64
65
66
67
68 @Override
69 public boolean get(URIish uri, CredentialItem... items)
70 throws UnsupportedCredentialItem {
71 for (CredentialsProvider p : credentialProviders) {
72 if (p.supports(items)) {
73 if (!p.get(uri, items)) {
74 if (p.isInteractive()) {
75 return false;
76 }
77 continue;
78 }
79 if (isAnyNull(items)) {
80 continue;
81 }
82 return true;
83 }
84 }
85 return false;
86 }
87 }