Search in sources :

Example 41 with User

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

the class UsernameConsumersPermissionTest method init.

@Before
public void init() {
    User u = new User(username, "dontcare");
    owner = new Owner("ownerkey", "My Org");
    owner.setId(TestUtil.randomString());
    perm = new UsernameConsumersPermission(u, owner);
}
Also used : Owner(org.candlepin.model.Owner) User(org.candlepin.model.User) Before(org.junit.Before)

Example 42 with User

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

the class DefaultUserServiceAdapter method validateUser.

@Override
public boolean validateUser(String username, String password) {
    User user = this.userCurator.findByLogin(username);
    String hashedPassword = Util.hash(password);
    if (user != null && password != null && hashedPassword != null) {
        return hashedPassword.equals(user.getHashedPassword());
    }
    return false;
}
Also used : User(org.candlepin.model.User)

Example 43 with User

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

the class ConsumerCuratorPermissionsTest method testFindByUuidPermissionFiltering.

@Test
public void testFindByUuidPermissionFiltering() {
    User u = setupOnlyMyConsumersPrincipal();
    Consumer c1 = new Consumer("c1", u.getUsername(), owner, consumerType);
    consumerCurator.create(c1);
    Consumer c2 = new Consumer("c2", "anotheruser", owner, consumerType);
    consumerCurator.create(c2);
    assertEquals(c1, consumerCurator.findByUuid(c1.getUuid()));
    assertNull(consumerCurator.findByUuid(c2.getUuid()));
}
Also used : User(org.candlepin.model.User) Consumer(org.candlepin.model.Consumer) Test(org.junit.Test)

Example 44 with User

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

the class ConsumerCuratorPermissionsTest method testListForOwnerEditMineViewAllPermissionFiltering.

@Test
public void testListForOwnerEditMineViewAllPermissionFiltering() {
    User u = setupEditMyConsumersViewAllPrincipal();
    Consumer c1 = new Consumer("c1", u.getUsername(), owner, consumerType);
    consumerCurator.create(c1);
    Consumer c2 = new Consumer("c2", "anotheruser", owner, consumerType);
    consumerCurator.create(c2);
    List<Consumer> results = consumerCurator.listByOwner(owner).list();
    assertEquals(2, results.size());
}
Also used : User(org.candlepin.model.User) Consumer(org.candlepin.model.Consumer) Test(org.junit.Test)

Example 45 with User

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

the class ConsumerResource method verifyPersonConsumer.

private void verifyPersonConsumer(ConsumerDTO consumer, ConsumerType type, Owner owner, String username, Principal principal) {
    User user = null;
    try {
        user = userService.findByLogin(username);
    } catch (UnsupportedOperationException e) {
        log.warn("User service does not allow user lookups, cannot verify person consumer.");
    }
    if (user == null) {
        throw new NotFoundException(i18n.tr("User with ID \"{0}\" could not be found."));
    }
    // has some association with the owner the consumer is destined for:
    if (!principal.canAccess(owner, SubResource.NONE, Access.ALL) && !principal.hasFullAccess()) {
        throw new ForbiddenException(i18n.tr("User \"{0}\" has no roles for organization \"{1}\"", user.getUsername(), owner.getKey()));
    }
    // TODO: Refactor out type specific checks?
    if (type.isType(ConsumerTypeEnum.PERSON)) {
        Consumer existing = consumerCurator.findByUser(user);
        if (existing != null && this.consumerTypeCurator.getConsumerType(existing).isType(ConsumerTypeEnum.PERSON)) {
            // TODO: This is not the correct error code for this situation!
            throw new BadRequestException(i18n.tr("User \"{0}\" has already registered a personal consumer", user.getUsername()));
        }
        consumer.setName(user.getUsername());
    }
}
Also used : ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) User(org.candlepin.model.User) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) NotFoundException(org.candlepin.common.exceptions.NotFoundException) BadRequestException(org.candlepin.common.exceptions.BadRequestException)

Aggregations

User (org.candlepin.model.User)49 Test (org.junit.Test)33 Role (org.candlepin.model.Role)14 Owner (org.candlepin.model.Owner)13 HashSet (java.util.HashSet)11 UserPrincipal (org.candlepin.auth.UserPrincipal)10 Principal (org.candlepin.auth.Principal)7 OwnerPermission (org.candlepin.auth.permissions.OwnerPermission)6 PermissionBlueprint (org.candlepin.model.PermissionBlueprint)6 Consumer (org.candlepin.model.Consumer)5 Before (org.junit.Before)5 ApiOperation (io.swagger.annotations.ApiOperation)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 LinkedList (java.util.LinkedList)3 Permission (org.candlepin.auth.permissions.Permission)3 ConsumerType (org.candlepin.model.ConsumerType)3 Ignore (org.junit.Ignore)3 ApiResponses (io.swagger.annotations.ApiResponses)2 Method (java.lang.reflect.Method)2