Search in sources :

Example 1 with PermissionBlueprint

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

Example 2 with PermissionBlueprint

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;
}
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 3 with PermissionBlueprint

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());
}
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 4 with PermissionBlueprint

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;
}
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 5 with PermissionBlueprint

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;
}
Also used : Role(org.candlepin.model.Role) Owner(org.candlepin.model.Owner) PermissionBlueprint(org.candlepin.model.PermissionBlueprint) NotFoundException(org.candlepin.common.exceptions.NotFoundException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

PermissionBlueprint (org.candlepin.model.PermissionBlueprint)11 Role (org.candlepin.model.Role)9 Owner (org.candlepin.model.Owner)6 User (org.candlepin.model.User)6 HashSet (java.util.HashSet)4 Test (org.junit.Test)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 LinkedList (java.util.LinkedList)2 Produces (javax.ws.rs.Produces)2 Principal (org.candlepin.auth.Principal)2 UserPrincipal (org.candlepin.auth.UserPrincipal)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 Consumer (org.candlepin.model.Consumer)2 ConsumerType (org.candlepin.model.ConsumerType)2 Transactional (com.google.inject.persist.Transactional)1 Date (java.util.Date)1