Skip to content

Commit

Permalink
Feat/search roles (#105)
Browse files Browse the repository at this point in the history
* search roles

* bump version
  • Loading branch information
slavikm committed Mar 6, 2024
1 parent 1868cef commit 67a0fa5
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 4 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,16 @@ try {
// Handle the error
}

// Search roles
try {
RoleResponse resp = rs.search(RoleSearchOptions.builder().tenantIds(Arrays.asList(tid)).build());
for (Role r : resp.getRoles()) {
// Do something
}
} catch (DescopeException de) {
// Handle the error
}

```

### Query SSO Groups
Expand Down
2 changes: 1 addition & 1 deletion examples/management-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<dependency>
<groupId>com.descope</groupId>
<artifactId>java-sdk</artifactId>
<version>1.0.15</version>
<version>1.0.16</version>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.descope</groupId>
<artifactId>java-sdk</artifactId>
<modelVersion>4.0.0</modelVersion>
<version>1.0.15</version>
<version>1.0.16</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Java library used to integrate with Descope.</description>
<url>https://github.com/descope/descope-java</url>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/descope/literals/Routes.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public static class ManagementEndPoints {
public static final String MANAGEMENT_ROLES_UPDATE_LINK = "/v1/mgmt/role/update";
public static final String MANAGEMENT_ROLES_DELETE_LINK = "/v1/mgmt/role/delete";
public static final String MANAGEMENT_ROLES_LOAD_ALL_LINK = "/v1/mgmt/role/all";
public static final String MANAGEMENT_ROLES_SEARCH_LINK = "/v1/mgmt/role/search";

// Project
public static final String MANAGEMENT_PROJECT_UPDATE_NAME = "/v1/mgmt/project/update/name";
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/descope/model/roles/RoleSearchOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.descope.model.roles;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RoleSearchOptions {
private List<String> tenantIds;
private List<String> roleNames;
private String roleNameLike; // match role names that contain the given string case insensitive
private List<String> permissionNames;
}
3 changes: 3 additions & 0 deletions src/main/java/com/descope/sdk/mgmt/RolesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.descope.exception.DescopeException;
import com.descope.model.roles.RoleResponse;
import com.descope.model.roles.RoleSearchOptions;
import java.util.List;

public interface RolesService {
Expand All @@ -20,4 +21,6 @@ void update(String name, String tenantId, String newName, String description, Li
void delete(String name, String tenantId) throws DescopeException;

RoleResponse loadAll() throws DescopeException;

RoleResponse search(RoleSearchOptions roleSearchOptions) throws DescopeException;
}
8 changes: 8 additions & 0 deletions src/main/java/com/descope/sdk/mgmt/impl/RolesServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import static com.descope.literals.Routes.ManagementEndPoints.MANAGEMENT_ROLES_CREATE_LINK;
import static com.descope.literals.Routes.ManagementEndPoints.MANAGEMENT_ROLES_DELETE_LINK;
import static com.descope.literals.Routes.ManagementEndPoints.MANAGEMENT_ROLES_LOAD_ALL_LINK;
import static com.descope.literals.Routes.ManagementEndPoints.MANAGEMENT_ROLES_SEARCH_LINK;
import static com.descope.literals.Routes.ManagementEndPoints.MANAGEMENT_ROLES_UPDATE_LINK;
import static com.descope.utils.CollectionUtils.mapOf;

import com.descope.exception.DescopeException;
import com.descope.exception.ServerCommonException;
import com.descope.model.client.Client;
import com.descope.model.roles.RoleResponse;
import com.descope.model.roles.RoleSearchOptions;
import com.descope.proxy.ApiProxy;
import com.descope.sdk.mgmt.RolesService;
import java.util.List;
Expand Down Expand Up @@ -82,4 +84,10 @@ public RoleResponse loadAll() throws DescopeException {
ApiProxy apiProxy = getApiProxy();
return apiProxy.get(getUri(MANAGEMENT_ROLES_LOAD_ALL_LINK), RoleResponse.class);
}

@Override
public RoleResponse search(RoleSearchOptions roleSearchOptions) throws DescopeException {
ApiProxy apiProxy = getApiProxy();
return apiProxy.post(getUri(MANAGEMENT_ROLES_SEARCH_LINK), roleSearchOptions, RoleResponse.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.descope.model.mgmt.ManagementServices;
import com.descope.model.roles.Role;
import com.descope.model.roles.RoleResponse;
import com.descope.model.roles.RoleSearchOptions;
import com.descope.proxy.ApiProxy;
import com.descope.proxy.impl.ApiProxyBuilder;
import com.descope.sdk.TestUtils;
Expand Down Expand Up @@ -152,7 +153,7 @@ void testFunctionalFullCycle() {
}
assertTrue(found);
rolesService.update(r1, r1 + "1", "zzz", Arrays.asList(p1));
roles = rolesService.loadAll();
roles = rolesService.search(RoleSearchOptions.builder().roleNames(Arrays.asList(r1 + "1")).build());
assertThat(roles.getRoles()).isNotEmpty();
found = false;
for (Role r : roles.getRoles()) {
Expand Down Expand Up @@ -190,7 +191,7 @@ void testFunctionalFullCycleWithTenantId() {
}
assertTrue(found);
rolesService.update(r1, tid, r1 + "1", "zzz", Arrays.asList(p1));
roles = rolesService.loadAll();
roles = rolesService.search(RoleSearchOptions.builder().tenantIds(Arrays.asList(tid)).build());
assertThat(roles.getRoles()).isNotEmpty();
found = false;
for (Role r : roles.getRoles()) {
Expand Down

0 comments on commit 67a0fa5

Please sign in to comment.