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