@@ -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 ) {
0 commit comments