Search in sources :

Example 1 with Role

use of org.candlepin.model.Role in project candlepin by candlepin.

the class PersonConsumerResourceCreationLiberalNameRules method initConsumerType.

@Override
public ConsumerType initConsumerType() {
    ConsumerType systemtype = new ConsumerType(ConsumerType.ConsumerTypeEnum.PERSON);
    // create an owner, an ownerperm, and roles for the user we provide
    // as coming from userService
    owner = new Owner("test_owner");
    PermissionBlueprint p = new PermissionBlueprint(PermissionType.OWNER, owner, Access.ALL);
    User user = new User("anyuser", "");
    role = new Role();
    role.addPermission(p);
    role.addUser(user);
    when(userService.findByLogin("anyuser")).thenReturn(user);
    return systemtype;
}
Also used : Role(org.candlepin.model.Role) Owner(org.candlepin.model.Owner) User(org.candlepin.model.User) PermissionBlueprint(org.candlepin.model.PermissionBlueprint) ConsumerType(org.candlepin.model.ConsumerType)

Example 2 with Role

use of org.candlepin.model.Role in project candlepin by candlepin.

the class UserResourceTest method testListOwnersForMySystemsAdmin.

@Test
public void testListOwnersForMySystemsAdmin() {
    User user = new User();
    user.setUsername("dummyuser" + TestUtil.randomInt());
    user.setPassword("password");
    userResource.createUser(user);
    Owner owner1 = createOwner();
    Role owner1Role = new Role(owner1.getKey() + " role");
    owner1Role.addPermission(new PermissionBlueprint(PermissionType.USERNAME_CONSUMERS, owner1, Access.ALL));
    owner1Role.addUser(user);
    roleCurator.create(owner1Role);
    Set<Permission> perms = new HashSet<>();
    perms.add(new UsernameConsumersPermission(user, owner1));
    Principal userPrincipal = new UserPrincipal(user.getUsername(), perms, false);
    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) UsernameConsumersPermission(org.candlepin.auth.permissions.UsernameConsumersPermission) 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 3 with Role

use of org.candlepin.model.Role in project candlepin by candlepin.

the class DefaultUserServiceAdapterTest method deleteUserRemovesUserFromRoles.

@Test
public void deleteUserRemovesUserFromRoles() {
    Role adminRole = createAdminRole(owner);
    roleCurator.create(adminRole);
    User user = new User("testuser", "password");
    service.createUser(user);
    service.addUserToRole(adminRole, user);
    service.deleteUser(user);
    adminRole = service.getRole(adminRole.getId());
    assertEquals(0, adminRole.getUsers().size());
}
Also used : Role(org.candlepin.model.Role) User(org.candlepin.model.User) Test(org.junit.Test)

Example 4 with Role

use of org.candlepin.model.Role in project candlepin by candlepin.

the class DefaultUserServiceAdapterTest method findOwner.

@Test
@Ignore("Find a way to do this with permissions")
public void findOwner() {
    User user = new User("test_name", "password");
    this.service.createUser(user);
    Role adminRole = createAdminRole(owner);
    adminRole.addUser(user);
    roleCurator.create(adminRole);
// List<Owner> owners = this.service.getOwners("test_name");
// Assert.assertEquals(1, owners.size());
// Assert.assertEquals(owner, owners.get(0));
}
Also used : Role(org.candlepin.model.Role) User(org.candlepin.model.User) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Role

use of org.candlepin.model.Role in project candlepin by candlepin.

the class PersonConsumerResourceCreationTest method initConsumerType.

public ConsumerType initConsumerType() {
    ConsumerType ctype = new ConsumerType(ConsumerType.ConsumerTypeEnum.PERSON);
    this.mockConsumerType(ctype);
    // create an owner, a ownerperm, and roles for the user we prodive
    // as coming from userService
    owner = new Owner("test_owner");
    PermissionBlueprint p = new PermissionBlueprint(PermissionType.OWNER, owner, Access.ALL);
    User user = new User("anyuser", "");
    role = new Role();
    role.addPermission(p);
    role.addUser(user);
    when(userService.findByLogin("anyuser")).thenReturn(user);
    return ctype;
}
Also used : Role(org.candlepin.model.Role) Owner(org.candlepin.model.Owner) User(org.candlepin.model.User) PermissionBlueprint(org.candlepin.model.PermissionBlueprint) ConsumerType(org.candlepin.model.ConsumerType)

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