Search in sources :

Example 16 with Role

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());
}
Also used : Owner(org.candlepin.model.Owner) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) User(org.candlepin.model.User) UserPrincipal(org.candlepin.auth.UserPrincipal) LinkedList(java.util.LinkedList) Role(org.candlepin.model.Role) PermissionBlueprint(org.candlepin.model.PermissionBlueprint) UsernameConsumersPermission(org.candlepin.auth.permissions.UsernameConsumersPermission) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with Role

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());
}
Also used : Role(org.candlepin.model.Role) User(org.candlepin.model.User) Test(org.junit.Test)

Example 18 with Role

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;
}
Also used : Role(org.candlepin.model.Role) PermissionBlueprint(org.candlepin.model.PermissionBlueprint)

Example 19 with 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);
}
Also used : Role(org.candlepin.model.Role)

Example 20 with Role

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;
}
Also used : Role(org.candlepin.model.Role) User(org.candlepin.model.User) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Role (org.candlepin.model.Role)23 User (org.candlepin.model.User)14 Test (org.junit.Test)10 PermissionBlueprint (org.candlepin.model.PermissionBlueprint)9 Owner (org.candlepin.model.Owner)8 ApiOperation (io.swagger.annotations.ApiOperation)7 Produces (javax.ws.rs.Produces)7 ApiResponses (io.swagger.annotations.ApiResponses)6 Path (javax.ws.rs.Path)6 HashSet (java.util.HashSet)4 Consumes (javax.ws.rs.Consumes)4 LinkedList (java.util.LinkedList)3 POST (javax.ws.rs.POST)3 UserPrincipal (org.candlepin.auth.UserPrincipal)3 DELETE (javax.ws.rs.DELETE)2 Principal (org.candlepin.auth.Principal)2 OwnerPermission (org.candlepin.auth.permissions.OwnerPermission)2 Permission (org.candlepin.auth.permissions.Permission)2 UsernameConsumersPermission (org.candlepin.auth.permissions.UsernameConsumersPermission)2 NotFoundException (org.candlepin.common.exceptions.NotFoundException)2