Search in sources :

Example 46 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class PoolResourceTest method testConsumerCannotListPoolsForAnotherOwnersConsumer.

@Test(expected = NotFoundException.class)
public void testConsumerCannotListPoolsForAnotherOwnersConsumer() {
    Principal p = setupPrincipal(new ConsumerPrincipal(foreignConsumer, owner2));
    securityInterceptor.enable();
    poolResource.list(null, passConsumer.getUuid(), null, false, null, p, null);
}
Also used : ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Principal(org.candlepin.auth.Principal) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 47 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class PoolResourceTest method testListForOrg.

@Test
public void testListForOrg() {
    List<PoolDTO> pools = poolResource.list(owner1.getId(), null, null, false, null, adminPrincipal, null);
    assertEquals(2, pools.size());
    Principal p = setupPrincipal(owner2, Access.ALL);
    pools = poolResource.list(owner2.getId(), null, null, false, null, p, null);
    assertEquals(1, pools.size());
}
Also used : PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Principal(org.candlepin.auth.Principal) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 48 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class PoolResourceTest method consumerCanListOwnersPools.

@Test
public void consumerCanListOwnersPools() {
    Principal p = setupPrincipal(new ConsumerPrincipal(passConsumer, owner1));
    securityInterceptor.enable();
    poolResource.list(owner1.getId(), null, null, false, null, p, null);
}
Also used : ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Principal(org.candlepin.auth.Principal) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 49 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class UserResourceTest method testListAllOwners.

@Test
public void testListAllOwners() {
    User user = new User();
    user.setUsername("dummyuser" + TestUtil.randomInt());
    user.setPassword("password");
    userResource.createUser(user);
    Owner owner1 = createOwner();
    Owner owner2 = createOwner();
    Role owner1Role = new Role(owner1.getKey() + " role");
    Role owner2Role = new Role(owner2.getKey() + " role");
    owner1Role.addPermission(new PermissionBlueprint(PermissionType.OWNER, owner1, Access.ALL));
    owner1Role.addPermission(new PermissionBlueprint(PermissionType.OWNER, owner2, Access.READ_ONLY));
    owner1Role.addUser(user);
    owner2Role.addUser(user);
    roleCurator.create(owner1Role);
    roleCurator.create(owner2Role);
    Set<Permission> perms = new HashSet<>();
    perms.add(new OwnerPermission(owner1, Access.ALL));
    perms.add(new OwnerPermission(owner2, Access.READ_ONLY));
    Principal userPrincipal = new UserPrincipal(user.getUsername(), perms, false);
    // Requesting the list of owners for this user should assume ALL, and not
    // return owner2:
    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) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) 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 50 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class PinsetterAsyncFilterTest method noJobMapPrincipal.

@Test
public void noJobMapPrincipal() {
    List<Permission> permissions = Arrays.asList(new Permission[] { new OwnerPermission(new Owner("test_owner"), Access.ALL) });
    Principal principal = new UserPrincipal("testing", permissions, false);
    when(this.principalProvider.get()).thenReturn(principal);
    JobDetail detail = newJob(RefreshPoolsJob.class).build();
    when(response.getEntity()).thenReturn(detail);
    this.interceptor.postProcess(response);
    Assert.assertEquals(principal, detail.getJobDataMap().get(PinsetterJobListener.PRINCIPAL_KEY));
}
Also used : RefreshPoolsJob(org.candlepin.pinsetter.tasks.RefreshPoolsJob) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Owner(org.candlepin.model.Owner) JobDetail(org.quartz.JobDetail) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Aggregations

Principal (org.candlepin.auth.Principal)74 Test (org.junit.Test)54 UserPrincipal (org.candlepin.auth.UserPrincipal)40 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)20 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)17 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)15 Consumer (org.candlepin.model.Consumer)15 Owner (org.candlepin.model.Owner)15 TrustedUserPrincipal (org.candlepin.auth.TrustedUserPrincipal)14 Date (java.util.Date)12 ConsumerType (org.candlepin.model.ConsumerType)11 HashSet (java.util.HashSet)10 Pool (org.candlepin.model.Pool)10 JobDetail (org.quartz.JobDetail)10 Method (java.lang.reflect.Method)9 Permission (org.candlepin.auth.permissions.Permission)9 JobDataMap (org.quartz.JobDataMap)9 CandlepinQuery (org.candlepin.model.CandlepinQuery)8 File (java.io.File)7 FileInputStream (java.io.FileInputStream)7