Search in sources :

Example 1 with UserPrincipal

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));
}
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 2 with UserPrincipal

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);
}
Also used : User(org.candlepin.model.User) Method(java.lang.reflect.Method) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 3 with 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);
}
Also used : User(org.candlepin.model.User) Method(java.lang.reflect.Method) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 4 with 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));
}
Also used : OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 5 with UserPrincipal

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

Aggregations

UserPrincipal (org.candlepin.auth.UserPrincipal)30 Test (org.junit.Test)18 Owner (org.candlepin.model.Owner)16 Principal (org.candlepin.auth.Principal)14 OwnerPermission (org.candlepin.auth.permissions.OwnerPermission)10 User (org.candlepin.model.User)10 Permission (org.candlepin.auth.permissions.Permission)9 HashSet (java.util.HashSet)7 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)7 ConsumerType (org.candlepin.model.ConsumerType)6 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)5 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)4 Consumer (org.candlepin.model.Consumer)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)3 UsernameConsumersPermission (org.candlepin.auth.permissions.UsernameConsumersPermission)3 Role (org.candlepin.model.Role)3 ManifestFile (org.candlepin.sync.file.ManifestFile)3 TestUtil.createConsumerDTO (org.candlepin.test.TestUtil.createConsumerDTO)3