Search in sources :

Example 16 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class ConsumerCuratorPermissionsTest method testListForOwnerPermissionFiltering.

@Test
public void testListForOwnerPermissionFiltering() {
    User u = setupOnlyMyConsumersPrincipal();
    Consumer c1 = new Consumer("c1", u.getUsername(), owner, consumerType);
    consumerCurator.create(c1);
    Consumer c2 = new Consumer("c2", "anotheruser", owner, consumerType);
    consumerCurator.create(c2);
    List<Consumer> results = consumerCurator.listByOwner(owner).list();
    assertEquals(1, results.size());
    assertEquals(c1.getName(), results.get(0).getName());
}
Also used : User(org.candlepin.model.User) Consumer(org.candlepin.model.Consumer) Test(org.junit.Test)

Example 17 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class ConsumerCuratorPermissionsTest method setupOnlyMyConsumersPrincipal.

private User setupOnlyMyConsumersPrincipal() {
    Set<Permission> perms = new HashSet<>();
    User u = new User("fakeuser", "dontcare");
    perms.add(new UsernameConsumersPermission(u, owner));
    Principal p = new UserPrincipal(u.getUsername(), perms, false);
    setupPrincipal(p);
    return u;
}
Also used : User(org.candlepin.model.User) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) UserPrincipal(org.candlepin.auth.UserPrincipal) HashSet(java.util.HashSet)

Example 18 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class OwnerCuratorPermissionsTest method setUpTestObjects.

@Before
public void setUpTestObjects() {
    owner1 = new Owner("Example Corporation");
    owner2 = new Owner("Example Corporation 2");
    owner3 = new Owner("Example Corporation 3");
    ownerCurator.create(owner1);
    ownerCurator.create(owner2);
    ownerCurator.create(owner3);
    // Setup a principal with access to org 1 and 2, but not 3.
    Set<Permission> perms = new HashSet<>();
    User u = new User("fakeuser", "dontcare");
    perms.add(new UsernameConsumersPermission(u, owner1));
    perms.add(new OwnerPermission(owner1, Access.ALL));
    // just read for org 2
    perms.add(new OwnerPermission(owner2, Access.READ_ONLY));
    principal = new UserPrincipal(u.getUsername(), perms, false);
    setupPrincipal(principal);
}
Also used : Owner(org.candlepin.model.Owner) User(org.candlepin.model.User) UserPrincipal(org.candlepin.auth.UserPrincipal) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 19 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class TrustedUserAuthTest method trustedAuthWithPermissionsLookup.

@Test
public void trustedAuthWithPermissionsLookup() throws Exception {
    headerMap.add(TrustedUserAuth.USER_HEADER, USERNAME);
    // Adding this header should cause the user to be loaded from the adapter:
    headerMap.add(TrustedUserAuth.LOOKUP_PERMISSIONS_HEADER, "true");
    User u = new User(USERNAME, "pass");
    when(userService.findByLogin(eq(USERNAME))).thenReturn(u);
    UserPrincipal p = (UserPrincipal) auth.getPrincipal(request);
    // This shouldn't attempt to verify a password:
    verify(userService, never()).validateUser(any(String.class), any(String.class));
    // It *should* ask for a user object which carries roles and thus, permissions:
    verify(userService).findByLogin(eq(USERNAME));
    assertFalse(p.hasFullAccess());
    assertEquals(USERNAME, p.getUsername());
}
Also used : User(org.candlepin.model.User) Test(org.junit.Test)

Example 20 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class KatelloUserServiceAdapterTest method deleteUser.

@Test(expected = UnsupportedOperationException.class)
public void deleteUser() throws Exception {
    User user = mock(User.class);
    kusa.deleteUser(user);
}
Also used : User(org.candlepin.model.User) Test(org.junit.Test)

Aggregations

User (org.candlepin.model.User)49 Test (org.junit.Test)33 Role (org.candlepin.model.Role)14 Owner (org.candlepin.model.Owner)13 HashSet (java.util.HashSet)11 UserPrincipal (org.candlepin.auth.UserPrincipal)10 Principal (org.candlepin.auth.Principal)7 OwnerPermission (org.candlepin.auth.permissions.OwnerPermission)6 PermissionBlueprint (org.candlepin.model.PermissionBlueprint)6 Consumer (org.candlepin.model.Consumer)5 Before (org.junit.Before)5 ApiOperation (io.swagger.annotations.ApiOperation)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 LinkedList (java.util.LinkedList)3 Permission (org.candlepin.auth.permissions.Permission)3 ConsumerType (org.candlepin.model.ConsumerType)3 Ignore (org.junit.Ignore)3 ApiResponses (io.swagger.annotations.ApiResponses)2 Method (java.lang.reflect.Method)2