Search in sources :

Example 1 with Permission

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;
}
Also used : Permission(org.candlepin.auth.permissions.Permission)

Example 2 with Permission

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));
}
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 3 with Permission

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());
}
Also used : Owner(org.candlepin.model.Owner) UsernameConsumersPermission(org.candlepin.auth.permissions.UsernameConsumersPermission) User(org.candlepin.model.User) UserPrincipal(org.candlepin.auth.UserPrincipal) LinkedList(java.util.LinkedList) Role(org.candlepin.model.Role) PermissionBlueprint(org.candlepin.model.PermissionBlueprint) UsernameConsumersPermission(org.candlepin.auth.permissions.UsernameConsumersPermission) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with Permission

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;
}
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 5 with Permission

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

Permission (org.candlepin.auth.permissions.Permission)12 Principal (org.candlepin.auth.Principal)9 UserPrincipal (org.candlepin.auth.UserPrincipal)9 OwnerPermission (org.candlepin.auth.permissions.OwnerPermission)8 Owner (org.candlepin.model.Owner)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)4 UsernameConsumersPermission (org.candlepin.auth.permissions.UsernameConsumersPermission)3 User (org.candlepin.model.User)3 LinkedList (java.util.LinkedList)2 PermissionBlueprint (org.candlepin.model.PermissionBlueprint)2 Role (org.candlepin.model.Role)2 JobDetail (org.quartz.JobDetail)2 ArrayList (java.util.ArrayList)1 XmlTransient (javax.xml.bind.annotation.XmlTransient)1 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)1 TrustedUserPrincipal (org.candlepin.auth.TrustedUserPrincipal)1 PermissionFactory (org.candlepin.auth.permissions.PermissionFactory)1 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)1 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)1