Skip to content

Commit 7b4785c

Browse files
authored
feat: add security identity management support (#3)
https://coveord.atlassian.net/browse/CDX-386
1 parent 191acb1 commit 7b4785c

11 files changed

+223
-16
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.coveo.pushapiclient;
2+
3+
import java.util.Map;
4+
5+
public class AliasMapping extends IdentityModel {
6+
public String provider;
7+
8+
public AliasMapping(String provider, String name, SecurityIdentityType type, Map<String, String> additionalInfo) {
9+
super(name, type, additionalInfo);
10+
this.provider = provider;
11+
}
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.coveo.pushapiclient;
2+
3+
import java.util.Map;
4+
5+
public class IdentityModel {
6+
public Map<String, String> additionalInfo;
7+
public String name;
8+
public SecurityIdentityType type;
9+
10+
public IdentityModel(String name, SecurityIdentityType type, Map<String, String> additionalInfo) {
11+
this.name = name;
12+
this.type = type;
13+
this.additionalInfo = additionalInfo;
14+
}
15+
}

src/main/java/com/coveo/pushapiclient/PlatformClient.java

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,75 @@ public HttpResponse<String> createSource(String name, SourceVisibility sourceVis
4242
return this.httpClient.send(request, HttpResponse.BodyHandlers.ofString());
4343
}
4444

45-
public void createOrUpdateSecurityIdentity(String securityProviderId, Object securityIdentityModel) {
46-
// TODO
45+
public HttpResponse<String> createOrUpdateSecurityIdentity(String securityProviderId, SecurityIdentityModel securityIdentityModel) throws IOException, InterruptedException {
46+
String[] headers = this.getHeaders(this.getAuthorizationHeader(), this.getContentTypeApplicationJSONHeader());
47+
URI uri = URI.create(this.getBaseProviderURL(securityProviderId) + "/permissions");
48+
49+
String json = new Gson().toJson(securityIdentityModel);
50+
51+
HttpRequest request = HttpRequest.newBuilder()
52+
.headers(headers)
53+
.PUT(HttpRequest.BodyPublishers.ofString(json))
54+
.uri(uri)
55+
.build();
56+
57+
return this.httpClient.send(request, HttpResponse.BodyHandlers.ofString());
4758
}
4859

49-
public void createOrUpdateSecurityIdentityAlias(String securityProviderId, Object securityIdentityAlias) {
50-
// TODO
60+
public HttpResponse<String> createOrUpdateSecurityIdentityAlias(String securityProviderId, SecurityIdentityAliasModel securityIdentityAlias) throws IOException, InterruptedException {
61+
String[] headers = this.getHeaders(this.getAuthorizationHeader(), this.getContentTypeApplicationJSONHeader());
62+
URI uri = URI.create(this.getBaseProviderURL(securityProviderId) + "/mappings");
63+
64+
String json = new Gson().toJson(securityIdentityAlias);
65+
66+
HttpRequest request = HttpRequest.newBuilder()
67+
.headers(headers)
68+
.PUT(HttpRequest.BodyPublishers.ofString(json))
69+
.uri(uri)
70+
.build();
71+
72+
return this.httpClient.send(request, HttpResponse.BodyHandlers.ofString());
5173
}
5274

53-
public void deleteSecurityIdentity(String securityProviderId, Object securityIdentityToDelete) {
54-
// TODO
75+
public HttpResponse<String> deleteSecurityIdentity(String securityProviderId, SecurityIdentityDelete securityIdentityToDelete) throws IOException, InterruptedException {
76+
String[] headers = this.getHeaders(this.getAuthorizationHeader(), this.getContentTypeApplicationJSONHeader());
77+
URI uri = URI.create(this.getBaseProviderURL(securityProviderId) + "/permissions");
78+
79+
String json = new Gson().toJson(securityIdentityToDelete);
80+
81+
HttpRequest request = HttpRequest.newBuilder()
82+
.headers(headers)
83+
.method("DELETE", HttpRequest.BodyPublishers.ofString(json))
84+
.uri(uri)
85+
.build();
86+
87+
return this.httpClient.send(request, HttpResponse.BodyHandlers.ofString());
5588
}
5689

57-
public void deleteOldSecurityIdentities(String securityProviderId, Object batchDelete) {
58-
// TODO
90+
public HttpResponse<String> deleteOldSecurityIdentities(String securityProviderId, SecurityIdentityDeleteOptions batchDelete) throws IOException, InterruptedException {
91+
String[] headers = this.getHeaders(this.getAuthorizationHeader(), this.getContentTypeApplicationJSONHeader());
92+
URI uri = URI.create(this.getBaseProviderURL(securityProviderId) + String.format("/permissions/olderthan?orderingId=%s&queueDelay=%s", batchDelete.orderingId, batchDelete.queueDelay));
93+
94+
HttpRequest request = HttpRequest.newBuilder()
95+
.headers(headers)
96+
.DELETE()
97+
.uri(uri)
98+
.build();
99+
100+
return this.httpClient.send(request, HttpResponse.BodyHandlers.ofString());
59101
}
60102

61-
public void manageSecurityIdentities(String securityProviderId, Object batchConfig) {
62-
// TODO
103+
public HttpResponse<String> manageSecurityIdentities(String securityProviderId, SecurityIdentityBatchConfig batchConfig) throws IOException, InterruptedException {
104+
String[] headers = this.getHeaders(this.getAuthorizationHeader(), this.getContentTypeApplicationJSONHeader());
105+
URI uri = URI.create(this.getBaseProviderURL(securityProviderId) + String.format("/permissions/batch?fileId=%s&orderingId=%s", batchConfig.fileId, batchConfig.orderingId));
106+
107+
HttpRequest request = HttpRequest.newBuilder()
108+
.headers(headers)
109+
.PUT(HttpRequest.BodyPublishers.ofString(""))
110+
.uri(uri)
111+
.build();
112+
113+
return this.httpClient.send(request, HttpResponse.BodyHandlers.ofString());
63114
}
64115

65116
public void pushDocument(String sourceId, Document doc) {
@@ -90,6 +141,14 @@ private String getBasePlatformURL() {
90141
return String.format("https://platform.cloud.coveo.com/rest/organizations/%s", this.organizationId);
91142
}
92143

144+
private String getBasePushURL() {
145+
return String.format("https://api.cloud.coveo.com/push/v1/organizations/%s", this.organizationId);
146+
}
147+
148+
private String getBaseProviderURL(String providerId) {
149+
return String.format("%s/providers/%s", this.getBasePushURL(), providerId);
150+
}
151+
93152
private String[] getHeaders(String[]... headers) {
94153
String[] out = new String[]{};
95154
for (String[] header : headers) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.coveo.pushapiclient;
2+
3+
public class SecurityIdentityAliasModel extends SecurityIdentityModelBase {
4+
public AliasMapping[] mappings;
5+
6+
public SecurityIdentityAliasModel(AliasMapping[] mappings, IdentityModel identity, IdentityModel[] wellKnowns) {
7+
super(identity, wellKnowns);
8+
this.mappings = mappings;
9+
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.coveo.pushapiclient;
2+
3+
public class SecurityIdentityBatchConfig {
4+
public String fileId;
5+
public Long orderingId;
6+
7+
public SecurityIdentityBatchConfig(String fileId, Long orderingId) {
8+
this.fileId = fileId;
9+
this.orderingId = orderingId;
10+
}
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.coveo.pushapiclient;
2+
3+
public class SecurityIdentityDelete {
4+
public IdentityModel identity;
5+
6+
public SecurityIdentityDelete(IdentityModel identity) {
7+
this.identity = identity;
8+
}
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.coveo.pushapiclient;
2+
3+
public class SecurityIdentityDeleteOptions {
4+
public Integer queueDelay;
5+
public Long orderingId;
6+
7+
public SecurityIdentityDeleteOptions(Integer queueDelay, Long orderingId) {
8+
this.queueDelay = queueDelay;
9+
this.orderingId = orderingId;
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.coveo.pushapiclient;
2+
3+
public class SecurityIdentityModel extends SecurityIdentityModelBase {
4+
public IdentityModel[] members;
5+
6+
public SecurityIdentityModel(IdentityModel[] members, IdentityModel identity, IdentityModel[] wellKnowns) {
7+
super(identity, wellKnowns);
8+
this.members = members;
9+
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.coveo.pushapiclient;
2+
3+
public class SecurityIdentityModelBase {
4+
public IdentityModel identity;
5+
public IdentityModel[] wellKnowns;
6+
7+
public SecurityIdentityModelBase(IdentityModel identity, IdentityModel[] wellKnowns) {
8+
this.identity = identity;
9+
this.wellKnowns = wellKnowns;
10+
}
11+
}

src/main/java/com/coveo/pushapiclient/Source.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,24 @@ public Source(String apiKey, String organizationId) {
1313
public HttpResponse<String> create(String name, SourceVisibility sourceVisibility) throws IOException, InterruptedException {
1414
return this.platformClient.createSource(name, sourceVisibility);
1515
}
16+
17+
public HttpResponse<String> createOrUpdateSecurityIdentity(String securityProviderId, SecurityIdentityModel securityIdentityModel) throws IOException, InterruptedException {
18+
return this.platformClient.createOrUpdateSecurityIdentity(securityProviderId, securityIdentityModel);
19+
}
20+
21+
public HttpResponse<String> createOrUpdateSecurityIdentityAlias(String securityProviderId, SecurityIdentityAliasModel securityIdentityAliasModel) throws IOException, InterruptedException {
22+
return this.platformClient.createOrUpdateSecurityIdentityAlias(securityProviderId, securityIdentityAliasModel);
23+
}
24+
25+
public HttpResponse<String> deleteSecurityIdentity(String securityProviderId, SecurityIdentityDelete securityIdentityDelete) throws IOException, InterruptedException {
26+
return this.platformClient.deleteSecurityIdentity(securityProviderId, securityIdentityDelete);
27+
}
28+
29+
public HttpResponse<String> deleteOldSecurityIdentities(String securityProviderId, SecurityIdentityDeleteOptions batchDelete) throws IOException, InterruptedException {
30+
return this.platformClient.deleteOldSecurityIdentities(securityProviderId, batchDelete);
31+
}
32+
33+
public HttpResponse<String> manageSecurityIdentities(String securityProviderId, SecurityIdentityBatchConfig batchConfig) throws IOException, InterruptedException {
34+
return this.platformClient.manageSecurityIdentities(securityProviderId, batchConfig);
35+
}
1636
}

0 commit comments

Comments
 (0)