Skip to content

Commit

Permalink
Implemented feedback from PR auth0#193
Browse files Browse the repository at this point in the history
  • Loading branch information
cs-jackb committed Apr 17, 2019
1 parent eddfd60 commit d788ab1
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 155 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
Expand Down
83 changes: 17 additions & 66 deletions src/main/java/com/auth0/client/mgmt/RolesEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Role>> list() {
String url = baseUrl
.newBuilder()
.addEncodedPathSegments("api/v2/roles").build().toString();
CustomRequest<List<Role>> request = new CustomRequest<>(this.client, url, "GET", new TypeReference<List<Role>>() {});
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
Expand All @@ -68,7 +52,6 @@ public Request<RolesPage> 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.
Expand All @@ -90,7 +73,8 @@ public Request<Role> 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
Expand All @@ -111,7 +95,8 @@ public Request<Role> 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.
Expand All @@ -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
Expand All @@ -157,27 +143,9 @@ public Request<Role> 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<List<User>> listUsers(String roleId) {
Asserts.assertNotNull(roleId, "role id");
String url = baseUrl
.newBuilder()
.addEncodedPathSegments("api/v2/roles")
.addEncodedPathSegments(roleId)
.addEncodedPathSegments("users")
.build().toString();
CustomRequest<List<User>> request = new CustomRequest<>(this.client, url, "GET", new TypeReference<List<User>>() {});
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
Expand All @@ -202,8 +170,9 @@ public Request<UsersPage> 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
Expand All @@ -230,27 +199,8 @@ public Request assignUsers(String roleId, List<String> 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<List<Permission>> listPermissions(String roleId) {
Asserts.assertNotNull(roleId, "role id");

String url = baseUrl
.newBuilder()
.addEncodedPathSegments("api/v2/roles")
.addEncodedPathSegments(roleId)
.addEncodedPathSegments("permissions").build().toString();
CustomRequest<List<Permission>> request = new CustomRequest<>(this.client, url, "GET", new TypeReference<List<Permission>>() {});
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
Expand All @@ -277,8 +227,9 @@ public Request<PermissionsPage> 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
Expand Down Expand Up @@ -308,7 +259,7 @@ public Request removePermissions(String roleId, List<Permission> 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
Expand Down
100 changes: 39 additions & 61 deletions src/main/java/com/auth0/client/mgmt/UsersEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -68,7 +69,8 @@ public Request<List<User>> 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
*
Expand Down Expand Up @@ -96,7 +98,8 @@ public Request<UsersPage> 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
*
Expand Down Expand Up @@ -124,7 +127,8 @@ public Request<User> 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
Expand All @@ -146,7 +150,8 @@ public Request<User> 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
Expand All @@ -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
Expand All @@ -192,7 +199,8 @@ public Request<User> 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.
Expand All @@ -216,7 +224,8 @@ public Request<List<Enrollment>> 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.
Expand Down Expand Up @@ -244,7 +253,8 @@ public Request<LogEventsPage> 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
Expand All @@ -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.
Expand All @@ -293,7 +304,8 @@ public Request<RecoveryCode> 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
Expand Down Expand Up @@ -327,7 +339,8 @@ public Request<List<Identity>> 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
Expand Down Expand Up @@ -356,29 +369,9 @@ public Request<List<Identity>> 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<List<Permission>> listPermissions(String userId) {
Asserts.assertNotNull(userId, "user id");
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/users")
.addPathSegments(userId)
.addPathSegments("permissions").build().toString();
CustomRequest<List<Permission>> request = new CustomRequest<>(client, url, "GET", new TypeReference<List<Permission>>() {
});
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
Expand Down Expand Up @@ -406,7 +399,8 @@ public Request<PermissionsPage> 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
Expand Down Expand Up @@ -434,7 +428,8 @@ public Request removePermissions(String userId, List<Permission> 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
Expand Down Expand Up @@ -463,27 +458,8 @@ public Request addPermissions(String userId, List<Permission> 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<List<Role>> listRoles(String userId) {
Asserts.assertNotNull(userId, "user id");
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/users")
.addPathSegments(userId)
.addPathSegments("roles").build().toString();
CustomRequest<List<Role>> request = new CustomRequest<>(client, url, "GET", new TypeReference<List<Role>>() {
});
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
Expand All @@ -510,8 +486,9 @@ public Request<RolesPage> 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
Expand All @@ -538,8 +515,9 @@ public Request removeRoles(String userId, List<Role> 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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/auth0/client/mgmt/filter/PageFilter.java
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down
Loading

0 comments on commit d788ab1

Please sign in to comment.