use of org.candlepin.auth.UserPrincipal 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.UserPrincipal in project candlepin by candlepin.
the class AuthenticationFilterTest method securityHoleWithAuth.
@Test
public void securityHoleWithAuth() throws Exception {
Method method = FakeResource.class.getMethod("annotatedMethod", String.class);
mockResourceMethod(method);
mockReq.header("Authorization", "BASIC QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
when(usa.validateUser(eq("Aladdin"), eq("open sesame"))).thenReturn(true);
when(usa.findByLogin(eq("Aladdin"))).thenReturn(new User("Aladdin", "open sesame"));
interceptor.filter(getContext());
Principal p = ResteasyProviderFactory.getContextData(Principal.class);
assertTrue(p instanceof UserPrincipal);
}
use of org.candlepin.auth.UserPrincipal in project candlepin by candlepin.
the class AuthenticationFilterTest method noSecurityHole.
@Test
public void noSecurityHole() throws Exception {
mockReq.header("Authorization", "BASIC QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
when(usa.validateUser(eq("Aladdin"), eq("open sesame"))).thenReturn(true);
when(usa.findByLogin(eq("Aladdin"))).thenReturn(new User("Aladdin", "open sesame", true));
Method method = FakeResource.class.getMethod("someMethod", String.class);
mockResourceMethod(method);
interceptor.filter(getContext());
Principal p = ResteasyProviderFactory.getContextData(Principal.class);
assertTrue(p instanceof UserPrincipal);
}
use of org.candlepin.auth.UserPrincipal in project candlepin by candlepin.
the class OwnerResourceTest method undoImportforOwnerWithNoImports.
@Test(expected = NotFoundException.class)
public void undoImportforOwnerWithNoImports() {
OwnerDTO dto = new OwnerDTO();
dto.setKey("owner-with-no-imports");
dto.setDisplayName("foo");
dto = ownerResource.createOwner(dto);
ownerResource.undoImports(dto.getKey(), new UserPrincipal("JarjarBinks", null, true));
}
use of org.candlepin.auth.UserPrincipal in project candlepin by candlepin.
the class UserResourceTest method testListOwnersForMySystemsAdmin.
@Test
public void testListOwnersForMySystemsAdmin() {
User user = new User();
user.setUsername("dummyuser" + TestUtil.randomInt());
user.setPassword("password");
userResource.createUser(user);
Owner owner1 = createOwner();
Role owner1Role = new Role(owner1.getKey() + " role");
owner1Role.addPermission(new PermissionBlueprint(PermissionType.USERNAME_CONSUMERS, owner1, Access.ALL));
owner1Role.addUser(user);
roleCurator.create(owner1Role);
Set<Permission> perms = new HashSet<>();
perms.add(new UsernameConsumersPermission(user, owner1));
Principal userPrincipal = new UserPrincipal(user.getUsername(), perms, false);
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());
}
Aggregations