diff --git a/README.md b/README.md index 12f866dc..227051b5 100644 --- a/README.md +++ b/README.md @@ -285,7 +285,7 @@ The Management API is divided into different entities. Each of them have the lis * **Jobs:** See [Docs](https://auth0.com/docs/api/management/v2#!/Jobs/get_jobs_by_id). Access the methods by calling `mgmt.jobs()`. * **Logs:** See [Docs](https://auth0.com/docs/api/management/v2#!/Logs/get_logs). Access the methods by calling `mgmt.logEvents()`. This endpoint supports pagination. * **Resource Servers:** See [Docs](https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers). Access the methods by calling `mgmt.resourceServers()`. This endpoint supports pagination. -* **Roles:** See [Docs](https://auth0.com/docs/api/management/v2#!/Roles/get_roles). Access the methods by calling `mgmt.rules()`. This endpoint supports pagination. +* **Roles:** See [Docs](https://auth0.com/docs/api/management/v2#!/Roles/get_roles). Access the methods by calling `mgmt.roles()`. This endpoint supports pagination. * **Rules:** See [Docs](https://auth0.com/docs/api/management/v2#!/Rules/get_rules). Access the methods by calling `mgmt.rules()`. This endpoint supports pagination. * **Stats:** See [Docs](https://auth0.com/docs/api/management/v2#!/Stats/get_active_users). Access the methods by calling `mgmt.stats()`. * **Tenants:** See [Docs](https://auth0.com/docs/api/management/v2#!/Tenants/get_settings). Access the methods by calling `mgmt.tenants()`. diff --git a/src/main/java/com/auth0/client/mgmt/RolesEntity.java b/src/main/java/com/auth0/client/mgmt/RolesEntity.java index 6a9a325a..be81d581 100644 --- a/src/main/java/com/auth0/client/mgmt/RolesEntity.java +++ b/src/main/java/com/auth0/client/mgmt/RolesEntity.java @@ -26,22 +26,6 @@ public class RolesEntity extends BaseManagementEntity { super(client, baseUrl, apiToken); } - /** - * Request all Roles created by this tenant that can be assigned to a given user or user group. - * A token with read:roles is needed - * See https://auth0.com/docs/api/management/v2#!/Roles/get_roles - * - * @return a Request to execute - */ - public Request> list() { - String url = baseUrl - .newBuilder() - .addEncodedPathSegments("api/v2/roles").build().toString(); - CustomRequest> request = new CustomRequest<>(this.client, url, "GET", new TypeReference>() {}); - request.addHeader("Authorization", "Bearer " + apiToken); - return request; - } - /** * Request all Roles created by this tenant that can be assigned to a given user or user group. * A token with read:roles is needed @@ -68,7 +52,6 @@ public Request list(RolesFilter filter) { /** * Get a single role created by this tenant that can be assigned to a given user or user group. * A token with scope read:roles is needed. - * If you want the identities.access_token property to be included, you will also need the scope read:user_idp_tokens. * See https://auth0.com/docs/api/management/v2#!/Roles/get_roles_by_id * * @param roleId the id of the user to retrieve. @@ -90,7 +73,8 @@ public Request get(String roleId) { /** - * Create a Role. A token with scope create:roles is needed. + * Create a Role. + * A token with scope create:roles is needed. * See https://auth0.com/docs/api/management/v2#!/Roles/post_roles * * @param role the role data to set @@ -111,7 +95,8 @@ public Request create(Role role) { } /** - * Delete an existing Role. A token with scope delete:roles is needed. + * Delete an existing Role. + * A token with scope delete:roles is needed. * See https://auth0.com/docs/api/management/v2#!/Roles/delete_roles_by_id * * @param roleId The id of the role to delete. @@ -132,7 +117,8 @@ public Request delete(String roleId) { } /** - * Update an existing Role. A token with scope update:roles is needed. + * Update an existing Role. + * A token with scope update:roles is needed. * See https://auth0.com/docs/api/management/v2#!/Roles/patch_roles_by_id * * @param roleId the role id @@ -157,27 +143,9 @@ public Request update(String roleId, Role role) { /** * Lists the users that have been associated with a given role. - * See https://auth0.com/docs/api/management/v2#!/Roles/get_users + * A token with scope read:users and read:roles is needed. * - * @param roleId the role id - * @return a Request to execute - */ - public Request> listUsers(String roleId) { - Asserts.assertNotNull(roleId, "role id"); - String url = baseUrl - .newBuilder() - .addEncodedPathSegments("api/v2/roles") - .addEncodedPathSegments(roleId) - .addEncodedPathSegments("users") - .build().toString(); - CustomRequest> request = new CustomRequest<>(this.client, url, "GET", new TypeReference>() {}); - request.addHeader("Authorization", "Bearer " + apiToken); - return request; - } - - /** - * Lists the users that have been associated with a given role. - * See https://auth0.com/docs/api/management/v2#!/Roles/get_users + * See https://auth0.com/docs/api/management/v2#!/Roles/get_role_user * * @param roleId the role id * @param filter an optional pagination filter @@ -202,8 +170,9 @@ public Request listUsers(String roleId, PageFilter filter) { } /** - * Assign users to a role. A token with update:roles is needed. - * See https://auth0.com/docs/api/management/v2#!/Roles/post_users + * Assign users to a role. + * A token with update:roles is needed. + * See https://auth0.com/docs/api/management/v2#!/Roles/post_role_users * * @param roleId the role id * @param userIds a list of user ids to assign to the role @@ -230,27 +199,8 @@ public Request assignUsers(String roleId, List userIds) { } /** - * Get the permissions associated to the role. A token with read:roles is needed. - * See https://auth0.com/docs/api/management/v2#!/Roles/get_permissions - * - * @param roleId the role id - * @return a Request to execute - */ - public Request> listPermissions(String roleId) { - Asserts.assertNotNull(roleId, "role id"); - - String url = baseUrl - .newBuilder() - .addEncodedPathSegments("api/v2/roles") - .addEncodedPathSegments(roleId) - .addEncodedPathSegments("permissions").build().toString(); - CustomRequest> request = new CustomRequest<>(this.client, url, "GET", new TypeReference>() {}); - request.addHeader("Authorization", "Bearer " + apiToken); - return request; - } - - /** - * Get the permissions associated to the role. A token with read:roles is needed. + * Get the permissions associated to the role. + * A token with read:roles is needed. * See https://auth0.com/docs/api/management/v2#!/Roles/get_permissions * * @param roleId the role id @@ -277,8 +227,9 @@ public Request listPermissions(String roleId, PageFilter filter } /** - * Un-associate permissions from a role. A token with update:roles is needed. - * See https://auth0.com/docs/api/management/v2#!/Roles/delete_permissions + * Un-associate permissions from a role. + * A token with update:roles is needed. + * See https://auth0.com/docs/api/management/v2#!/Roles/delete_role_permission_assignment * * @param roleId the role id * @param permissions a list of permission objects to un-associate from the role @@ -308,7 +259,7 @@ public Request removePermissions(String roleId, List permissions) { * Associate permissions with a role. Only the `permission_name` and * `resource_server_identifier` Permission attributes should be specified. * A token with update:roles is needed. - * See https://auth0.com/docs/api/management/v2#!/Roles/post_permissions + * See https://auth0.com/docs/api/management/v2#!/Roles/post_role_permission_assignment * * @param roleId the role id * @param permissions a list of permission objects to associate to the role diff --git a/src/main/java/com/auth0/client/mgmt/UsersEntity.java b/src/main/java/com/auth0/client/mgmt/UsersEntity.java index 50e37688..ced1eebe 100644 --- a/src/main/java/com/auth0/client/mgmt/UsersEntity.java +++ b/src/main/java/com/auth0/client/mgmt/UsersEntity.java @@ -39,7 +39,8 @@ public class UsersEntity extends BaseManagementEntity { } /** - * Request all the Users that match a given email. A token with scope read:users is needed. + * Request all the Users that match a given email. + * A token with scope read:users is needed. * If you want the identities.access_token property to be included, you will also need the scope read:user_idp_tokens. * See https://auth0.com/docs/api/management/v2#!/Users_By_Email/get_users_by_email * @@ -68,7 +69,8 @@ public Request> listByEmail(String email, FieldsFilter filter) { } /** - * Request all the Users. A token with scope read:users is needed. + * Request all the Users. + * A token with scope read:users is needed. * If you want the identities.access_token property to be included, you will also need the scope read:user_idp_tokens. * See https://auth0.com/docs/api/management/v2#!/Users/get_users * @@ -96,7 +98,8 @@ public Request list(UserFilter filter) { } /** - * Request a User. A token with scope read:users is needed. + * Request a User. + * A token with scope read:users is needed. * If you want the identities.access_token property to be included, you will also need the scope read:user_idp_tokens. * See https://auth0.com/docs/api/management/v2#!/Users/get_users_by_id * @@ -124,7 +127,8 @@ public Request get(String userId, UserFilter filter) { } /** - * Create a User. A token with scope create:users is needed. + * Create a User. + * A token with scope create:users is needed. * See https://auth0.com/docs/api/management/v2#!/Users/post_users * * @param user the user data to set @@ -146,7 +150,8 @@ public Request create(User user) { } /** - * Delete an existing User. A token with scope delete:users is needed. + * Delete an existing User. + * A token with scope delete:users is needed. * See https://auth0.com/docs/api/management/v2#!/Users/delete_users_by_id * * @param userId the user id @@ -167,7 +172,9 @@ public Request delete(String userId) { } /** - * Update an existing User. A token with scope update:users is needed. If you're updating app_metadata you'll also need update:users_app_metadata scope. + * Update an existing User. + * A token with scope update:users is needed. + * If you're updating app_metadata you'll also need update:users_app_metadata scope. * See https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id * * @param userId the user id @@ -192,7 +199,8 @@ public Request update(String userId, User user) { } /** - * Request all the Guardian Enrollments for a given User. A token with scope read:users is needed. + * Request all the Guardian Enrollments for a given User. + * A token with scope read:users is needed. * See https://auth0.com/docs/api/management/v2#!/Users/get_enrollments * * @param userId the id of the user to retrieve. @@ -216,7 +224,8 @@ public Request> getEnrollments(String userId) { } /** - * Request all the Events Log for a given User. A token with scope read:logs is needed. + * Request all the Events Log for a given User. + * A token with scope read:logs is needed. * See https://auth0.com/docs/api/management/v2#!/Users/get_logs_by_user * * @param userId the id of the user to retrieve. @@ -244,7 +253,8 @@ public Request getLogEvents(String userId, LogEventFilter filter) } /** - * Delete an existing User's Multifactor Provider. A token with scope update:users is needed. + * Delete an existing User's Multifactor Provider. + * A token with scope update:users is needed. * See https://auth0.com/docs/api/management/v2#!/Users/delete_multifactor_by_provider * * @param userId the user id @@ -269,7 +279,8 @@ public Request deleteMultifactorProvider(String userId, String provider) { } /** - * Rotates a User's Guardian recovery code. A token with scope update:users is needed. + * Rotates a User's Guardian recovery code. + * A token with scope update:users is needed. * * @param userId the user id * @return a Request to execute. @@ -293,7 +304,8 @@ public Request rotateRecoveryCode(String userId) { } /** - * Links two User's Identities. A token with scope update:users is needed. + * Links two User's Identities. + * A token with scope update:users is needed. * See https://auth0.com/docs/api/management/v2#!/Users/post_identities * * @param primaryUserId the primary identity's user id @@ -327,7 +339,8 @@ public Request> linkIdentity(String primaryUserId, String seconda } /** - * Un-links two User's Identities. A token with scope update:users is needed. + * Un-links two User's Identities. + * A token with scope update:users is needed. * See https://auth0.com/docs/api/management/v2#!/Users/delete_provider_by_user_id * * @param primaryUserId the primary identity's user id @@ -356,29 +369,9 @@ public Request> unlinkIdentity(String primaryUserId, String secon return request; } - - /** - * Get the permissions associated to the user. A token with read:users is needed. - * See https://auth0.com/docs/api/management/v2#!/Users/get_permissions - * - * @param userId the role id - * @return a Request to execute - */ - public Request> listPermissions(String userId) { - Asserts.assertNotNull(userId, "user id"); - String url = baseUrl - .newBuilder() - .addPathSegments("api/v2/users") - .addPathSegments(userId) - .addPathSegments("permissions").build().toString(); - CustomRequest> request = new CustomRequest<>(client, url, "GET", new TypeReference>() { - }); - request.addHeader("Authorization", "Bearer " + apiToken); - return request; - } - /** - * Get the permissions associated to the user. A token with read:users is needed. + * Get the permissions associated to the user. + * A token with read:users is needed. * See https://auth0.com/docs/api/management/v2#!/Users/get_permissions * * @param userId the role id @@ -406,7 +399,8 @@ public Request listPermissions(String userId, PageFilter filter /** - * Remove permissions from a user. A token with update:users is needed. + * Remove permissions from a user. + * A token with update:users is needed. * See https://auth0.com/docs/api/management/v2#!/Users/delete_permissions * * @param userId the user id @@ -434,7 +428,8 @@ public Request removePermissions(String userId, List permissions) { } /** - * Assign permissions to a user. A token with update:users is needed. + * Assign permissions to a user. + * A token with update:users is needed. * See https://auth0.com/docs/api/management/v2#!/Users/post_permissions * * @param userId the user id @@ -463,27 +458,8 @@ public Request addPermissions(String userId, List permissions) { /** * Get the roles associated with a user. - * See https://auth0.com/docs/api/management/v2#!/Users/get_roles - * - * @param userId the role id - * @return a Request to execute - */ - public Request> listRoles(String userId) { - Asserts.assertNotNull(userId, "user id"); - String url = baseUrl - .newBuilder() - .addPathSegments("api/v2/users") - .addPathSegments(userId) - .addPathSegments("roles").build().toString(); - CustomRequest> request = new CustomRequest<>(client, url, "GET", new TypeReference>() { - }); - request.addHeader("Authorization", "Bearer " + apiToken); - return request; - } - - /** - * Get the roles associated with a user. - * See https://auth0.com/docs/api/management/v2#!/Users/get_roles + * A token with read:users and read:roles is needed. + * See https://auth0.com/docs/api/management/v2#!/Users/get_user_roles * * @param userId the role id * @param filter an optional pagination filter @@ -510,8 +486,9 @@ public Request listRoles(String userId, PageFilter filter) { /** - * Remove roles from a user. A token with update:users is needed. - * See https://auth0.com/docs/api/management/v2#!/Users/delete_roles + * Remove roles from a user. + * A token with update:users is needed. + * See https://auth0.com/docs/api/management/v2#!/Users/delete_user_roles * * @param userId the user id * @param roles a list of role objects to remove from the user @@ -538,8 +515,9 @@ public Request removeRoles(String userId, List roles) { } /** - * Assign roles to a user. A token with update:users is needed. - * See https://auth0.com/docs/api/management/v2#!/Users/post_roles + * Assign roles to a user. + * A token with update:users is needed. + * See https://auth0.com/docs/api/management/v2#!/Users/post_user_roles * * @param userId the user id * @param roles a list of role objects to assign to the user diff --git a/src/main/java/com/auth0/client/mgmt/filter/PageFilter.java b/src/main/java/com/auth0/client/mgmt/filter/PageFilter.java index b6fe929a..05ee9a29 100644 --- a/src/main/java/com/auth0/client/mgmt/filter/PageFilter.java +++ b/src/main/java/com/auth0/client/mgmt/filter/PageFilter.java @@ -1,7 +1,7 @@ package com.auth0.client.mgmt.filter; /** - * Class used to filter the results received when calling the Grants endpoint. Related to the {@link com.auth0.client.mgmt.RolesEntity} entity. + * Class used to filter the results received when calling an endpoint that supports Pagination. */ public class PageFilter extends BaseFilter { /** diff --git a/src/main/java/com/auth0/client/mgmt/filter/RolesFilter.java b/src/main/java/com/auth0/client/mgmt/filter/RolesFilter.java index bddb92d4..04c37559 100644 --- a/src/main/java/com/auth0/client/mgmt/filter/RolesFilter.java +++ b/src/main/java/com/auth0/client/mgmt/filter/RolesFilter.java @@ -3,7 +3,7 @@ /** * Class used to filter the results received when calling the Grants endpoint. Related to the {@link com.auth0.client.mgmt.RolesEntity} entity. */ -public class RolesFilter extends BaseFilter { +public class RolesFilter extends PageFilter { /** * Filter by name @@ -15,29 +15,4 @@ public RolesFilter withName(String name) { parameters.put("name_filter", name); return this; } - - /** - * Filter by page - * - * @param pageNumber the page number to retrieve. - * @param amountPerPage the amount of items per page to retrieve. - * @return this filter instance - */ - public RolesFilter withPage(int pageNumber, int amountPerPage) { - parameters.put("page", pageNumber); - parameters.put("per_page", amountPerPage); - return this; - } - - /** - * Include the query summary - * - * @param includeTotals whether to include or not the query summary. - * @return this filter instance - */ - public RolesFilter withTotals(boolean includeTotals) { - parameters.put("include_totals", includeTotals); - return this; - } - }