-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRotatingClientKeyProvider.java
More file actions
83 lines (70 loc) · 2.16 KB
/
RotatingClientKeyProvider.java
File metadata and controls
83 lines (70 loc) · 2.16 KB
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
package com.uid2.shared.store.reader;
import com.uid2.shared.auth.ClientKey;
import com.uid2.shared.auth.IAuthorizable;
import com.uid2.shared.cloud.ICloudStorage;
import com.uid2.shared.store.CloudPath;
import com.uid2.shared.store.ScopedStoreReader;
import com.uid2.shared.store.IClientKeyProvider;
import com.uid2.shared.store.parser.ClientParser;
import com.uid2.shared.store.scope.StoreScope;
import io.vertx.core.json.JsonObject;
import java.util.Collection;
import java.util.Map;
/*
1. metadata.json format
{
"version" : <long>,
"generated" : <unix_epoch_seconds>,
"client_keys" : {
"location": "s3_path"
}
}
2. client keys file format
[
{
key = "aksjdkajsdkajsdja",
name = "ClientName",
contact = "ClientEmail",
created = "timestamp",
site_id = N,
roles = [],
},
...
]
*/
public class RotatingClientKeyProvider implements IClientKeyProvider, StoreReader<Collection<ClientKey>> {
private final ScopedStoreReader<Map<String, ClientKey>> reader;
public RotatingClientKeyProvider(ICloudStorage fileStreamProvider, StoreScope scope) {
this.reader = new ScopedStoreReader<>(fileStreamProvider, scope, new ClientParser(), "auth keys");
}
@Override
public JsonObject getMetadata() throws Exception {
return reader.getMetadata();
}
@Override
public long getVersion(JsonObject metadata) {
return metadata.getLong("version");
}
@Override
public long loadContent(JsonObject metadata) throws Exception {
return reader.loadContent(metadata, "client_keys");
}
@Override
public ClientKey getClientKey(String token) {
return reader.getSnapshot().get(token);
}
@Override
public Collection<ClientKey> getAll() {
return reader.getSnapshot().values();
}
public void loadContent() throws Exception {
this.loadContent(this.getMetadata());
}
public CloudPath getMetadataPath() {
return reader.getMetadataPath();
}
@Override
public IAuthorizable get(String key) {
return getClientKey(key);
}
}