-
Notifications
You must be signed in to change notification settings - Fork 131
/
ProxyDelegationStore.java
95 lines (81 loc) · 3.33 KB
/
ProxyDelegationStore.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* dCache - http://www.dcache.org/
*
* Copyright (C) 2014 - 2017 Deutsches Elektronen-Synchrotron
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.dcache.xrootd.security;
import static java.util.Arrays.asList;
import eu.emi.security.authn.x509.X509CertChainValidatorExt;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import org.dcache.gsi.KeyPairCache;
import org.dcache.gsi.X509Delegation;
import org.italiangrid.voms.VOMSValidators;
import org.italiangrid.voms.ac.VOMSACValidator;
import org.italiangrid.voms.store.VOMSTrustStore;
import org.italiangrid.voms.store.VOMSTrustStores;
import org.italiangrid.voms.util.CertificateValidatorBuilder;
public class ProxyDelegationStore {
/*
* Visible to the client this is used to initialize.
*/
final Map<String, X509Delegation> delegations = new ConcurrentHashMap<>();
VOMSACValidator vomsValidator;
KeyPairCache keyPairCache;
private String vomsDir;
private String caCertificatePath;
private long trustAnchorRefreshInterval;
private TimeUnit trustAnchorRefreshIntervalUnit;
public void initialize() {
long refresh = trustAnchorRefreshIntervalUnit
.toMillis(trustAnchorRefreshInterval);
VOMSTrustStore vomsTrustStore
= VOMSTrustStores.newTrustStore(asList(vomsDir));
X509CertChainValidatorExt certChainValidator
= new CertificateValidatorBuilder()
.lazyAnchorsLoading(false)
.trustAnchorsUpdateInterval(refresh)
.trustAnchorsDir(caCertificatePath)
.build();
vomsValidator = VOMSValidators.newValidator(vomsTrustStore,
certChainValidator);
}
public void setVomsDir(String vomsDir) throws FileNotFoundException {
if(!new File(vomsDir).isDirectory()) {
throw new FileNotFoundException("Local trust directory does not exist: " + vomsDir);
}
this.vomsDir = vomsDir;
}
public void setCaCertificatePath(String caCertificatePath) {
this.caCertificatePath = caCertificatePath;
}
public void setKeyPairCache(KeyPairCache keyPairCache) {
this.keyPairCache = keyPairCache;
}
public void setTrustAnchorRefreshInterval(long trustAnchorRefreshInterval) {
this.trustAnchorRefreshInterval = trustAnchorRefreshInterval;
}
public void setTrustAnchorRefreshIntervalUnit(TimeUnit trustAnchorRefreshIntervalUnit) {
this.trustAnchorRefreshIntervalUnit = trustAnchorRefreshIntervalUnit;
}
public void shutdown() {
if (vomsValidator != null) {
vomsValidator.shutdown();
}
}
}