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));
}
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;
}
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));
}
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));
}
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;
}
Aggregations