From 885d9436a6a84bd876b555cd4b0b4e24359b5eb0 Mon Sep 17 00:00:00 2001 From: neeleshmalpani Date: Sun, 4 Feb 2024 17:48:43 +0530 Subject: [PATCH 1/2] Added SecurityLogs Related APIs --- src/main/java/com/crowdin/client/Client.java | 4 ++ .../client/securitylogs/SecurityLogsApi.java | 66 +++++++++++++++++++ .../model/SecurityLogResource.java | 15 +++++ .../model/SecurityLogResourceObject.java | 8 +++ .../SecurityLogsResourceResponseList.java | 25 +++++++ .../client/securitylogs/SecurityLogsTest.java | 42 ++++++++++++ .../securitylogs/getSecurityLogBylogId.json | 12 ++++ .../api/securitylogs/listSecurityLogs.json | 33 ++++++++++ 8 files changed, 205 insertions(+) create mode 100644 src/main/java/com/crowdin/client/securitylogs/SecurityLogsApi.java create mode 100644 src/main/java/com/crowdin/client/securitylogs/model/SecurityLogResource.java create mode 100644 src/main/java/com/crowdin/client/securitylogs/model/SecurityLogResourceObject.java create mode 100644 src/main/java/com/crowdin/client/securitylogs/model/SecurityLogsResourceResponseList.java create mode 100644 src/test/java/com/crowdin/client/securitylogs/SecurityLogsTest.java create mode 100644 src/test/resources/api/securitylogs/getSecurityLogBylogId.json create mode 100644 src/test/resources/api/securitylogs/listSecurityLogs.json diff --git a/src/main/java/com/crowdin/client/Client.java b/src/main/java/com/crowdin/client/Client.java index 5e73a4c33..f8a1caf82 100644 --- a/src/main/java/com/crowdin/client/Client.java +++ b/src/main/java/com/crowdin/client/Client.java @@ -14,6 +14,7 @@ import com.crowdin.client.projectsgroups.ProjectsGroupsApi; import com.crowdin.client.reports.ReportsApi; import com.crowdin.client.screenshots.ScreenshotsApi; +import com.crowdin.client.securitylogs.SecurityLogsApi; import com.crowdin.client.sourcefiles.SourceFilesApi; import com.crowdin.client.sourcestrings.SourceStringsApi; import com.crowdin.client.storage.StorageApi; @@ -60,6 +61,7 @@ public class Client extends CrowdinApi { private final LabelsApi labelsApi; private final StringCommentsApi stringCommentsApi; private final BundlesApi bundlesApi; + private final SecurityLogsApi securityLogsApi; public Client(Credentials credentials) { super(credentials); @@ -89,6 +91,7 @@ public Client(Credentials credentials) { this.labelsApi = new LabelsApi(credentials); this.stringCommentsApi = new StringCommentsApi(credentials); this.bundlesApi = new BundlesApi(credentials); + this.securityLogsApi = new SecurityLogsApi(credentials); } public Client(Credentials credentials, ClientConfig clientConfig) { @@ -119,6 +122,7 @@ public Client(Credentials credentials, ClientConfig clientConfig) { this.labelsApi = new LabelsApi(credentials, clientConfig); this.stringCommentsApi = new StringCommentsApi(credentials, clientConfig); this.bundlesApi = new BundlesApi(credentials, clientConfig); + this.securityLogsApi = new SecurityLogsApi(credentials, clientConfig); } } diff --git a/src/main/java/com/crowdin/client/securitylogs/SecurityLogsApi.java b/src/main/java/com/crowdin/client/securitylogs/SecurityLogsApi.java new file mode 100644 index 000000000..c58b219c8 --- /dev/null +++ b/src/main/java/com/crowdin/client/securitylogs/SecurityLogsApi.java @@ -0,0 +1,66 @@ +package com.crowdin.client.securitylogs; + +import com.crowdin.client.core.CrowdinApi; +import com.crowdin.client.core.http.HttpRequestConfig; +import com.crowdin.client.core.http.exceptions.HttpBadRequestException; +import com.crowdin.client.core.http.exceptions.HttpException; +import com.crowdin.client.core.model.ClientConfig; +import com.crowdin.client.core.model.Credentials; +import com.crowdin.client.core.model.ResponseList; +import com.crowdin.client.core.model.ResponseObject; +import com.crowdin.client.securitylogs.model.SecurityLogResource; +import com.crowdin.client.securitylogs.model.SecurityLogResourceObject; +import com.crowdin.client.securitylogs.model.SecurityLogsResourceResponseList; + +import java.util.Map; +import java.util.Optional; + +public class SecurityLogsApi extends CrowdinApi { + + public SecurityLogsApi(Credentials credentials) { + super(credentials); + } + + public SecurityLogsApi(Credentials credentials, ClientConfig clientConfig) { + super(credentials, clientConfig); + } + + /** + * @param userId user Identifier + * @param limit maximum number of items to retrieve (default 25) + * @param offset starting offset in the collection (default 0) + * @param event value of event + * @param ipAddress value of ipAddress + * @return list of Security logs + * @see + */ + public ResponseList listSecurityLogs(Long userId, Long limit, Integer offset, String event, String ipAddress) throws HttpException, HttpBadRequestException { + Map> queryParams = HttpRequestConfig.buildUrlParams( + "limit", Optional.ofNullable(limit), + "offset", Optional.ofNullable(offset), + "event", Optional.ofNullable(event), + "ipAddress", Optional.ofNullable(ipAddress) + ); + SecurityLogsResourceResponseList securityLogsResponseList = this.httpClient.get(this.url + "/users/" + userId+ "/security-logs", new HttpRequestConfig(queryParams), SecurityLogsResourceResponseList.class); + return SecurityLogsResourceResponseList.to(securityLogsResponseList); + } + + /** + * @param userId user Identifier + * @param securityLogId log Identifier + * @return Security log + * @see + */ + public ResponseObject getUserSecurityLog(Long userId, Long securityLogId) throws HttpException, HttpBadRequestException { + SecurityLogResourceObject securityLogResourceObject = this.httpClient.get(this.url + "/users/" + userId+ "/security-logs" + securityLogId, new HttpRequestConfig(), SecurityLogResourceObject.class); + return ResponseObject.of(securityLogResourceObject.getData()); + } + + +} diff --git a/src/main/java/com/crowdin/client/securitylogs/model/SecurityLogResource.java b/src/main/java/com/crowdin/client/securitylogs/model/SecurityLogResource.java new file mode 100644 index 000000000..c9d8c7f69 --- /dev/null +++ b/src/main/java/com/crowdin/client/securitylogs/model/SecurityLogResource.java @@ -0,0 +1,15 @@ +package com.crowdin.client.securitylogs.model; + +import lombok.Data; + +@Data +public class SecurityLogResource { + Long id; + String event; + String info; + Long userId; + String location; + String ipAddress; + String deviceName; + String createdAt; +} diff --git a/src/main/java/com/crowdin/client/securitylogs/model/SecurityLogResourceObject.java b/src/main/java/com/crowdin/client/securitylogs/model/SecurityLogResourceObject.java new file mode 100644 index 000000000..8778c3510 --- /dev/null +++ b/src/main/java/com/crowdin/client/securitylogs/model/SecurityLogResourceObject.java @@ -0,0 +1,8 @@ +package com.crowdin.client.securitylogs.model; + +import lombok.Data; + +@Data +public class SecurityLogResourceObject { + private SecurityLogResource data; +} diff --git a/src/main/java/com/crowdin/client/securitylogs/model/SecurityLogsResourceResponseList.java b/src/main/java/com/crowdin/client/securitylogs/model/SecurityLogsResourceResponseList.java new file mode 100644 index 000000000..a9a837410 --- /dev/null +++ b/src/main/java/com/crowdin/client/securitylogs/model/SecurityLogsResourceResponseList.java @@ -0,0 +1,25 @@ +package com.crowdin.client.securitylogs.model; + +import com.crowdin.client.core.model.Pagination; +import com.crowdin.client.core.model.ResponseList; +import com.crowdin.client.core.model.ResponseObject; +import lombok.Data; + +import java.util.List; +import java.util.stream.Collectors; + +@Data +public class SecurityLogsResourceResponseList { + private List data; + private Pagination pagination; + + public static ResponseList to(SecurityLogsResourceResponseList securityLogsResourceResponseList) { + return ResponseList.of( + securityLogsResourceResponseList.getData().stream() + .map(SecurityLogResourceObject::getData) + .map(ResponseObject::of) + .collect(Collectors.toList()), + securityLogsResourceResponseList.getPagination() + ); + } +} diff --git a/src/test/java/com/crowdin/client/securitylogs/SecurityLogsTest.java b/src/test/java/com/crowdin/client/securitylogs/SecurityLogsTest.java new file mode 100644 index 000000000..468b13b1f --- /dev/null +++ b/src/test/java/com/crowdin/client/securitylogs/SecurityLogsTest.java @@ -0,0 +1,42 @@ +package com.crowdin.client.securitylogs; + +import com.crowdin.client.core.model.ResponseList; +import com.crowdin.client.core.model.ResponseObject; +import com.crowdin.client.framework.RequestMock; +import com.crowdin.client.framework.TestClient; +import com.crowdin.client.securitylogs.model.SecurityLogResource; +import org.apache.http.client.methods.HttpGet; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class SecurityLogsTest extends TestClient { + + private final long userId = 4; + private final long securityLogId = 5; + + @Override + public List getMocks() { + return Arrays.asList( + RequestMock.build(this.url + "/users/" + userId + "/security-logs", HttpGet.METHOD_NAME, "api/securitylogs/listSecurityLogs.json"), + RequestMock.build(this.url + "/users/" + userId + "/security-logs" + securityLogId, HttpGet.METHOD_NAME, "api/securitylogs/getSecurityLogBylogId.json") + ); + } + + @Test + public void listSecurityLogs(){ + ResponseList securityLogResourceResponseList = this.getSecurityLogsApi().listSecurityLogs(userId,null, null, null, null); + assertEquals(securityLogResourceResponseList.getData().size(),2); + assertEquals(securityLogResourceResponseList.getData().get(0).getData().getUserId(),userId); + } + + @Test + public void getSecurityLogByLogId(){ + ResponseObject securityLogResourceResponseObject = this.getSecurityLogsApi().getUserSecurityLog(userId,securityLogId); + assertEquals(securityLogResourceResponseObject.getData().getId(), securityLogId); + } + +} diff --git a/src/test/resources/api/securitylogs/getSecurityLogBylogId.json b/src/test/resources/api/securitylogs/getSecurityLogBylogId.json new file mode 100644 index 000000000..6a0b215c0 --- /dev/null +++ b/src/test/resources/api/securitylogs/getSecurityLogBylogId.json @@ -0,0 +1,12 @@ +{ + "data": { + "id": 5, + "event": "Some event", + "info": "Some info", + "userId": 4, + "location": "USA", + "ipAddress": "127.0.0.1", + "deviceName": "MacOs on MacBook", + "createdAt": "2019-09-19T15:10:43+00:00" + } +} \ No newline at end of file diff --git a/src/test/resources/api/securitylogs/listSecurityLogs.json b/src/test/resources/api/securitylogs/listSecurityLogs.json new file mode 100644 index 000000000..76769e3f1 --- /dev/null +++ b/src/test/resources/api/securitylogs/listSecurityLogs.json @@ -0,0 +1,33 @@ +{ + "data": [ + { + "data": { + "id": 2, + "event": "Some event", + "info": "Some info", + "userId": 4, + "location": "USA", + "ipAddress": "127.0.0.1", + "deviceName": "MacOs on MacBook", + "createdAt": "2019-09-19T15:10:43+00:00" + } + }, + { + "data": { + "id": 3, + "event": "Some event", + "info": "Some info", + "userId": 4, + "location": "USA", + "ipAddress": "127.0.0.1", + "deviceName": "MacOs on MacBook", + "createdAt": "2019-09-20T15:10:43+00:00" + } + } + + ], + "pagination": { + "offset": 0, + "limit": 25 + } +} \ No newline at end of file From 949489cc1a8835bb389e9c2244b1f67a2e0d2c8f Mon Sep 17 00:00:00 2001 From: neeleshmalpani Date: Sat, 10 Feb 2024 18:02:38 +0530 Subject: [PATCH 2/2] feat: Added Organization securityLog api --- .../client/securitylogs/SecurityLogsApi.java | 44 ++++++++++++++++++- .../client/securitylogs/SecurityLogsTest.java | 19 +++++++- .../getOrganizationLogBylogId.json | 12 +++++ .../securitylogs/listOrganizationLogs.json | 33 ++++++++++++++ 4 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/api/securitylogs/getOrganizationLogBylogId.json create mode 100644 src/test/resources/api/securitylogs/listOrganizationLogs.json diff --git a/src/main/java/com/crowdin/client/securitylogs/SecurityLogsApi.java b/src/main/java/com/crowdin/client/securitylogs/SecurityLogsApi.java index c58b219c8..565182e5a 100644 --- a/src/main/java/com/crowdin/client/securitylogs/SecurityLogsApi.java +++ b/src/main/java/com/crowdin/client/securitylogs/SecurityLogsApi.java @@ -37,7 +37,7 @@ public SecurityLogsApi(Credentials credentials, ClientConfig clientConfig) { *
  • Enterprise API Documentation
  • * */ - public ResponseList listSecurityLogs(Long userId, Long limit, Integer offset, String event, String ipAddress) throws HttpException, HttpBadRequestException { + public ResponseList listUserSecurityLogs(Long userId, Long limit, Integer offset, String event, String ipAddress) throws HttpException, HttpBadRequestException { Map> queryParams = HttpRequestConfig.buildUrlParams( "limit", Optional.ofNullable(limit), "offset", Optional.ofNullable(offset), @@ -58,9 +58,49 @@ public ResponseList listSecurityLogs(Long userId, Long limi * */ public ResponseObject getUserSecurityLog(Long userId, Long securityLogId) throws HttpException, HttpBadRequestException { - SecurityLogResourceObject securityLogResourceObject = this.httpClient.get(this.url + "/users/" + userId+ "/security-logs" + securityLogId, new HttpRequestConfig(), SecurityLogResourceObject.class); + SecurityLogResourceObject securityLogResourceObject = this.httpClient.get(this.url + "/users/" + userId+ "/security-logs/" + securityLogId, new HttpRequestConfig(), SecurityLogResourceObject.class); return ResponseObject.of(securityLogResourceObject.getData()); } + /** + * @param limit maximum number of items to retrieve (default 25) + * @param offset starting offset in the collection (default 0) + * @param event value of event + * @param createdAfter String Date in UTC format + * @param createdBefore String Date in UTC format + * @param ipAddress value of ipAddress + * @param userId user Identifier + * @return list of Security logs + * @see + */ + public ResponseList listOrganizationSecurityLogs(Long limit, Integer offset, String event, String createdAfter, String createdBefore, String ipAddress,Long userId) throws HttpException, HttpBadRequestException { + Map> queryParams = HttpRequestConfig.buildUrlParams( + "limit", Optional.ofNullable(limit), + "offset", Optional.ofNullable(offset), + "event", Optional.ofNullable(event), + "createdAfter", Optional.ofNullable(createdAfter), + "createdBefore", Optional.ofNullable(createdBefore), + "ipAddress", Optional.ofNullable(ipAddress), + "userId", Optional.ofNullable(userId) + ); + SecurityLogsResourceResponseList securityLogsResponseList = this.httpClient.get(this.url + "/security-logs", new HttpRequestConfig(queryParams), SecurityLogsResourceResponseList.class); + return SecurityLogsResourceResponseList.to(securityLogsResponseList); + } + + /** + * @param securityLogId log Identifier + * @return Security log + * @see + */ + public ResponseObject getOrganizationSecurityLog(Long securityLogId) throws HttpException, HttpBadRequestException { + SecurityLogResourceObject securityLogResourceObject = this.httpClient.get(this.url + "/security-logs/" + securityLogId, new HttpRequestConfig(), SecurityLogResourceObject.class); + return ResponseObject.of(securityLogResourceObject.getData()); + } + + } diff --git a/src/test/java/com/crowdin/client/securitylogs/SecurityLogsTest.java b/src/test/java/com/crowdin/client/securitylogs/SecurityLogsTest.java index 468b13b1f..56dde6e44 100644 --- a/src/test/java/com/crowdin/client/securitylogs/SecurityLogsTest.java +++ b/src/test/java/com/crowdin/client/securitylogs/SecurityLogsTest.java @@ -22,13 +22,16 @@ public class SecurityLogsTest extends TestClient { public List getMocks() { return Arrays.asList( RequestMock.build(this.url + "/users/" + userId + "/security-logs", HttpGet.METHOD_NAME, "api/securitylogs/listSecurityLogs.json"), - RequestMock.build(this.url + "/users/" + userId + "/security-logs" + securityLogId, HttpGet.METHOD_NAME, "api/securitylogs/getSecurityLogBylogId.json") + RequestMock.build(this.url + "/users/" + userId + "/security-logs/" + securityLogId, HttpGet.METHOD_NAME, "api/securitylogs/getSecurityLogBylogId.json"), + RequestMock.build(this.url + "/security-logs", HttpGet.METHOD_NAME, "api/securitylogs/listOrganizationLogs.json"), + RequestMock.build(this.url + "/security-logs/" + securityLogId, HttpGet.METHOD_NAME, "api/securitylogs/getOrganizationLogBylogId.json") + ); } @Test public void listSecurityLogs(){ - ResponseList securityLogResourceResponseList = this.getSecurityLogsApi().listSecurityLogs(userId,null, null, null, null); + ResponseList securityLogResourceResponseList = this.getSecurityLogsApi().listUserSecurityLogs(userId,null, null, null, null); assertEquals(securityLogResourceResponseList.getData().size(),2); assertEquals(securityLogResourceResponseList.getData().get(0).getData().getUserId(),userId); } @@ -38,5 +41,17 @@ public void getSecurityLogByLogId(){ ResponseObject securityLogResourceResponseObject = this.getSecurityLogsApi().getUserSecurityLog(userId,securityLogId); assertEquals(securityLogResourceResponseObject.getData().getId(), securityLogId); } + + @Test + public void listOrganizationLogs(){ + ResponseList securityLogResourceResponseList = this.getSecurityLogsApi().listOrganizationSecurityLogs(null,null,null,null,null,null,null); + assertEquals(securityLogResourceResponseList.getData().size(), 2); + } + + @Test + public void getOrganizationLogbylogId(){ + ResponseObject securityLogResourceResponseObject = this.getSecurityLogsApi().getOrganizationSecurityLog(securityLogId); + assertEquals(securityLogResourceResponseObject.getData().getId(), securityLogId); + } } diff --git a/src/test/resources/api/securitylogs/getOrganizationLogBylogId.json b/src/test/resources/api/securitylogs/getOrganizationLogBylogId.json new file mode 100644 index 000000000..6a0b215c0 --- /dev/null +++ b/src/test/resources/api/securitylogs/getOrganizationLogBylogId.json @@ -0,0 +1,12 @@ +{ + "data": { + "id": 5, + "event": "Some event", + "info": "Some info", + "userId": 4, + "location": "USA", + "ipAddress": "127.0.0.1", + "deviceName": "MacOs on MacBook", + "createdAt": "2019-09-19T15:10:43+00:00" + } +} \ No newline at end of file diff --git a/src/test/resources/api/securitylogs/listOrganizationLogs.json b/src/test/resources/api/securitylogs/listOrganizationLogs.json new file mode 100644 index 000000000..76769e3f1 --- /dev/null +++ b/src/test/resources/api/securitylogs/listOrganizationLogs.json @@ -0,0 +1,33 @@ +{ + "data": [ + { + "data": { + "id": 2, + "event": "Some event", + "info": "Some info", + "userId": 4, + "location": "USA", + "ipAddress": "127.0.0.1", + "deviceName": "MacOs on MacBook", + "createdAt": "2019-09-19T15:10:43+00:00" + } + }, + { + "data": { + "id": 3, + "event": "Some event", + "info": "Some info", + "userId": 4, + "location": "USA", + "ipAddress": "127.0.0.1", + "deviceName": "MacOs on MacBook", + "createdAt": "2019-09-20T15:10:43+00:00" + } + } + + ], + "pagination": { + "offset": 0, + "limit": 25 + } +} \ No newline at end of file