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;
}
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());
}
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());
}
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));
}
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;
}
Aggregations