Search in sources :

Example 6 with OwnerPermission

use of org.candlepin.auth.permissions.OwnerPermission 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 7 with OwnerPermission

use of org.candlepin.auth.permissions.OwnerPermission 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)

Example 8 with OwnerPermission

use of org.candlepin.auth.permissions.OwnerPermission in project candlepin by candlepin.

the class BasicAuthViaUserServiceTest method correctPrincipalColonPassword.

@Test
public void correctPrincipalColonPassword() throws Exception {
    Owner owner = new Owner("user", "user");
    setUserAndPassword("user", "1:2");
    when(userService.validateUser("user", "1:2")).thenReturn(true);
    Set<OwnerPermission> permissions = new HashSet<>();
    permissions.add(new OwnerPermission(owner, Access.ALL));
    when(userService.findByLogin("user")).thenReturn(new User());
    UserPrincipal expected = new UserPrincipal("user", new ArrayList<>(permissions), false);
    assertEquals(expected, this.auth.getPrincipal(request));
}
Also used : Owner(org.candlepin.model.Owner) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) User(org.candlepin.model.User) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with OwnerPermission

use of org.candlepin.auth.permissions.OwnerPermission in project candlepin by candlepin.

the class ConsumerResourceCreationTest method createConsumer.

protected ConsumerDTO createConsumer(String consumerName) {
    Collection<Permission> perms = new HashSet<>();
    perms.add(new OwnerPermission(owner, Access.ALL));
    Principal principal = new UserPrincipal(USER, perms, false);
    List<String> empty = Collections.emptyList();
    return createConsumer(consumerName, principal, empty);
}
Also used : OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) HashSet(java.util.HashSet)

Example 10 with OwnerPermission

use of org.candlepin.auth.permissions.OwnerPermission in project candlepin by candlepin.

the class ConsumerResourceIntegrationTest method testCreateConsumerVsDefaultServiceLevelForOwner.

@Test
@SuppressWarnings("checkstyle:indentation")
public void testCreateConsumerVsDefaultServiceLevelForOwner() {
    ConsumerDTO toSubmit = createConsumerDTO(CONSUMER_NAME, USER_NAME, null, standardSystemTypeDTO);
    ConsumerDTO submitted = consumerResource.create(toSubmit, new UserPrincipal(someuser.getUsername(), Arrays.asList(new Permission[] { new OwnerPermission(owner, Access.ALL) }), false), someuser.getUsername(), owner.getKey(), null, true);
    assertEquals(DEFAULT_SERVICE_LEVEL, submitted.getServiceLevel());
}
Also used : OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TestUtil.createConsumerDTO(org.candlepin.test.TestUtil.createConsumerDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Aggregations

OwnerPermission (org.candlepin.auth.permissions.OwnerPermission)11 UserPrincipal (org.candlepin.auth.UserPrincipal)8 Test (org.junit.Test)8 Owner (org.candlepin.model.Owner)7 Principal (org.candlepin.auth.Principal)6 Permission (org.candlepin.auth.permissions.Permission)6 HashSet (java.util.HashSet)5 User (org.candlepin.model.User)4 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)2 TestUtil.createConsumerDTO (org.candlepin.test.TestUtil.createConsumerDTO)2 JobDetail (org.quartz.JobDetail)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)1 TrustedUserPrincipal (org.candlepin.auth.TrustedUserPrincipal)1 UsernameConsumersPermission (org.candlepin.auth.permissions.UsernameConsumersPermission)1 PermissionBlueprint (org.candlepin.model.PermissionBlueprint)1 Role (org.candlepin.model.Role)1 RefreshPoolsJob (org.candlepin.pinsetter.tasks.RefreshPoolsJob)1 JobDataMap (org.quartz.JobDataMap)1