use of org.candlepin.auth.permissions.Permission in project candlepin by candlepin.
the class Principal method canAccess.
public boolean canAccess(Object target, SubResource subResource, Access access) {
log.debug("{} principal checking for {} access to target: {} sub-resource: {}", this.getClass().getName(), access, target, subResource);
if (hasFullAccess()) {
return true;
}
for (Permission permission : permissions) {
log.debug(" checking permission: {}", permission.getClass().getName());
if (permission.canAccess(target, subResource, access)) {
log.debug(" permission granted");
// we are good to go
return true;
}
}
// none of the permissions grants access, so this target is not allowed
String targetType = (target == null) ? "null" : target.getClass().getName();
log.warn("Refused principal: '{}' access to: {}", getName(), targetType);
return false;
}
use of org.candlepin.auth.permissions.Permission 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.Permission 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());
}
use of org.candlepin.auth.permissions.Permission 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.Permission 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