use of org.candlepin.model.PermissionBlueprint in project candlepin by candlepin.
the class DefaultUserServiceAdapter method createRole.
@Override
public Role createRole(Role role) {
Set<User> actualUsers = new HashSet<>();
for (User user : role.getUsers()) {
User actualUser = findByLogin(user.getUsername());
actualUsers.add(actualUser);
}
role.setUsers(actualUsers);
for (PermissionBlueprint permission : role.getPermissions()) {
permission.setRole(role);
}
this.roleCurator.create(role);
return role;
}
use of org.candlepin.model.PermissionBlueprint 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.PermissionBlueprint 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.PermissionBlueprint 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;
}
use of org.candlepin.model.PermissionBlueprint in project candlepin by candlepin.
the class RoleResource method createRole.
@ApiOperation(notes = "Creates a Role", value = "createRole")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Role createRole(@ApiParam(name = "role", required = true) Role role) {
// Attach actual owner objects to each incoming permission:
for (PermissionBlueprint p : role.getPermissions()) {
Owner temp = p.getOwner();
Owner actual = ownerCurator.lookupByKey(temp.getKey());
if (actual == null) {
throw new NotFoundException(i18n.tr("No such owner: {0}", temp.getKey()));
}
p.setOwner(actual);
}
Role r = this.userService.createRole(role);
return r;
}
Aggregations