use of org.candlepin.model.Role in project candlepin by candlepin.
the class UserResourceTest method testListAllOwners.
@Test
public void testListAllOwners() {
User user = new User();
user.setUsername("dummyuser" + TestUtil.randomInt());
user.setPassword("password");
userResource.createUser(user);
Owner owner1 = createOwner();
Owner owner2 = createOwner();
Role owner1Role = new Role(owner1.getKey() + " role");
Role owner2Role = new Role(owner2.getKey() + " role");
owner1Role.addPermission(new PermissionBlueprint(PermissionType.OWNER, owner1, Access.ALL));
owner1Role.addPermission(new PermissionBlueprint(PermissionType.OWNER, owner2, Access.READ_ONLY));
owner1Role.addUser(user);
owner2Role.addUser(user);
roleCurator.create(owner1Role);
roleCurator.create(owner2Role);
Set<Permission> perms = new HashSet<>();
perms.add(new OwnerPermission(owner1, Access.ALL));
perms.add(new OwnerPermission(owner2, Access.READ_ONLY));
Principal userPrincipal = new UserPrincipal(user.getUsername(), perms, false);
// Requesting the list of owners for this user should assume ALL, and not
// return owner2:
Iterable<Owner> response = userResource.listUsersOwners(user.getUsername(), userPrincipal);
List<Owner> owners = new LinkedList<>();
for (Object entity : response) {
owners.add((Owner) entity);
}
assertEquals(1, owners.size());
assertEquals(owner1.getKey(), owners.get(0).getKey());
}
use of org.candlepin.model.Role in project candlepin by candlepin.
the class DefaultUserServiceAdapterTest method addUserToRole.
@Test
public void addUserToRole() {
Role adminRole = createAdminRole(owner);
roleCurator.create(adminRole);
User user = new User("testuser", "password");
service.createUser(user);
service.addUserToRole(adminRole, user);
adminRole = service.getRole(adminRole.getId());
assertEquals(1, adminRole.getUsers().size());
}
use of org.candlepin.model.Role in project candlepin by candlepin.
the class DatabaseTestFixture method createAdminRole.
public Role createAdminRole(Owner owner) {
PermissionBlueprint p = new PermissionBlueprint(PermissionType.OWNER, owner, Access.ALL);
Role role = new Role("testrole" + TestUtil.randomInt());
role.addPermission(p);
return role;
}
use of org.candlepin.model.Role in project candlepin by candlepin.
the class DefaultUserServiceAdapter method deleteRole.
@Override
public void deleteRole(String roleId) {
Role r = roleCurator.find(roleId);
roleCurator.delete(r);
}
use of org.candlepin.model.Role in project candlepin by candlepin.
the class RoleResource method deleteUser.
@ApiOperation(notes = "Removes a User from a Role", value = "deleteUser")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@DELETE
@Path("/{role_id}/users/{username}")
@Produces(MediaType.APPLICATION_JSON)
public Role deleteUser(@PathParam("role_id") String roleId, @PathParam("username") String username) {
Role role = lookupRole(roleId);
User user = lookupUser(username);
userService.removeUserFromRole(role, user);
return role;
}
Aggregations