Package org.candlepin.model

Examples of org.candlepin.model.Role


        owner = new Owner("test_owner");
        user = new User(USER, "");
        PermissionBlueprint p = new PermissionBlueprint(PermissionType.OWNER, owner,
            Access.ALL);
        role = new Role();
        role.addPermission(p);
        role.addUser(user);

        when(consumerCurator.create(any(Consumer.class))).thenAnswer(new Answer() {
            @Override
View Full Code Here


        // 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;
View Full Code Here

                throw new NotFoundException(i18n.tr("No such owner: {0}", temp.getKey()));
            }
            p.setOwner(actual);
        }

        Role r = this.userService.createRole(role);
        return r;
    }
View Full Code Here

        //but if the user passes in an ID in the body of the JSON
        //and that ID is NOT equal to what the ID in the URL is, then throw an error
        if (role.getId() != null && !roleId.equals(role.getId())) {
            throw new BadRequestException(i18n.tr("Role ID does not match path."));
        }
        Role existingRole = lookupRole(roleId);
        existingRole.setName(role.getName());
        return this.userService.updateRole(existingRole);
    }
View Full Code Here

    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Role addRolePermission(@PathParam("role_id") String roleId,
        PermissionBlueprint permission) {

        Role existingRole = lookupRole(roleId);

        // Don't allow NONE permissions to be created, this is currently just for
        // internal use:
        if (permission.getAccess().equals(Access.NONE)) {
            throw new BadRequestException(i18n.tr("Access type NONE not supported."));
        }

        // Attach actual owner objects to each incoming permission:
        Owner temp = permission.getOwner();
        Owner real = ownerCurator.lookupByKey(temp.getKey());
        permission.setOwner(real);
        existingRole.addPermission(permission);

        Role r = this.userService.updateRole(existingRole);
        return r;
    }
View Full Code Here

    @Path("{role_id}/permissions/{perm_id}")
    @Produces(MediaType.APPLICATION_JSON)
    public Role removeRolePermission(@PathParam("role_id") String roleId,
                                      @PathParam("perm_id") String permissionId) {

        Role existingRole = lookupRole(roleId);
        Set<PermissionBlueprint> picks = new HashSet<PermissionBlueprint>();
        boolean found = true;
        PermissionBlueprint toRemove = null;
        for (PermissionBlueprint op : existingRole.getPermissions()) {
            if (!op.getId().equals(permissionId)) {
                picks.add(op);
            }
            else {
                found = true;
                toRemove = op;
            }

        }
        if (!found) {
            throw new NotFoundException(i18n.tr("No such permission: {0} in role: {1}",
                permissionId, roleId));
        }

        existingRole.setPermissions(picks);
        Role r = this.userService.updateRole(existingRole);
        toRemove.setOwner(null);
        permissionCurator.delete(toRemove);
        return r;
    }
View Full Code Here

        permissionCurator.delete(toRemove);
        return r;
    }

    private Role lookupRole(String roleId) {
        Role role = userService.getRole(roleId);
        if (role == null) {
            throw new NotFoundException(i18n.tr("No such role: {0}", roleId));
        }
        return role;
    }
View Full Code Here

    @POST
    @Path("/{role_id}/users/{username}")
    @Produces(MediaType.APPLICATION_JSON)
    public Role addUser(@PathParam("role_id") String roleId,
        @PathParam("username") String username) {
        Role role = lookupRole(roleId);
        User user = lookupUser(username);
        userService.addUserToRole(role, user);
        return role;
    }
View Full Code Here

    @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;
    }
View Full Code Here

TOP

Related Classes of org.candlepin.model.Role

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.