Search in sources :

Example 1 with OwnerPermission

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

the class PinsetterAsyncFilterTest method existingJobMapPrincipal.

@Test
public void existingJobMapPrincipal() {
    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);
    JobDataMap map = new JobDataMap();
    map.put("Temp", "something");
    JobDetail detail = newJob(RefreshPoolsJob.class).usingJobData(map).build();
    when(response.getEntity()).thenReturn(detail);
    this.interceptor.postProcess(response);
    Assert.assertSame(principal, detail.getJobDataMap().get(PinsetterJobListener.PRINCIPAL_KEY));
}
Also used : OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Owner(org.candlepin.model.Owner) JobDataMap(org.quartz.JobDataMap) 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 2 with OwnerPermission

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

the class DatabaseTestFixture method setupPrincipal.

protected Principal setupPrincipal(String username, Owner owner, Access verb) {
    OwnerPermission p = new OwnerPermission(owner, verb);
    // Only need a detached owner permission here:
    Principal ownerAdmin = new UserPrincipal(username, Arrays.asList(new Permission[] { p }), false);
    setupPrincipal(ownerAdmin);
    return ownerAdmin;
}
Also used : OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) 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)

Example 3 with OwnerPermission

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

the class BasicAuthViaUserServiceTest method correctPrincipalNoPassword.

@Test
public void correctPrincipalNoPassword() throws Exception {
    Owner owner = new Owner("user", "user");
    setUserNoPassword("user");
    when(userService.validateUser("user", null)).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 4 with OwnerPermission

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

the class BasicAuthViaUserServiceTest method correctPrincipal.

/**
 * Valid credentials are given - checks if the correct principal is created.
 *
 * @throws Exception
 */
@Test
public void correctPrincipal() throws Exception {
    Owner owner = new Owner("user", "user");
    setUserAndPassword("user", "redhat");
    when(userService.validateUser("user", "redhat")).thenReturn(true);
    // TODO: test will fail, need to mock the permissions setup
    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 5 with OwnerPermission

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

the class TestPrincipalProvider method get.

@Override
public Principal get() {
    TestPrincipalProviderSetter principalSingleton = TestPrincipalProviderSetter.get();
    Principal principal = principalSingleton.getPrincipal();
    if (principal == null) {
        List<Permission> permissions = new ArrayList<>();
        permissions.add(new OwnerPermission(new Owner(OWNER_NAME), Access.ALL));
        principal = new UserPrincipal("Default User", permissions, true);
    }
    return principal;
}
Also used : OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Owner(org.candlepin.model.Owner) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) ArrayList(java.util.ArrayList) Principal(org.candlepin.auth.Principal) UserPrincipal(org.candlepin.auth.UserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal)

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