Package org.candlepin.model

Examples of org.candlepin.model.User


    public static User createUser(String username, String password,
        boolean superAdmin) {
        username = (username == null) ? "user-" + randomInt() : username;
        password = (password == null) ? "pass-" + randomInt() : password;
        return new User(username, password, superAdmin);
    }
View Full Code Here


        headers.getRequestHeaders().add(TrustedUserAuth.USER_HEADER, USERNAME);

        // Adding this header should cause the user to be loaded from the adapter:
        headers.getRequestHeaders().add(TrustedUserAuth.LOOKUP_PERMISSIONS_HEADER, "true");

        User u = new User(USERNAME, "pass");
        when(userService.findByLogin(eq(USERNAME))).thenReturn(u);

        Principal p = auth.getPrincipal(request);
        assertTrue(p instanceof UserPrincipal);
View Full Code Here

        Class clazz = FakeResource.class;
        when(rmethod.getResourceClass()).thenReturn(clazz);

        when(usa.validateUser(eq("Aladdin"), eq("open sesame"))).thenReturn(true);
        when(usa.findByLogin(eq("Aladdin"))).thenReturn(
            new User("Aladdin", "open sesame", true));

        interceptor.preProcess(req, rmethod);

        Principal p = ResteasyProviderFactory.getContextData(Principal.class);
        assertTrue(p instanceof UserPrincipal);
View Full Code Here

        when(rmethod.getMethod()).thenReturn(method);
        Class clazz = FakeResource.class;
        when(rmethod.getResourceClass()).thenReturn(clazz);

        when(usa.validateUser(eq("Aladdin"), eq("open sesame"))).thenReturn(true);
        when(usa.findByLogin(eq("Aladdin"))).thenReturn(new User("Aladdin", "open sesame"));

        interceptor.preProcess(req, rmethod);

        Principal p = ResteasyProviderFactory.getContextData(Principal.class);
        assertTrue(p instanceof UserPrincipal);
View Full Code Here

    }

    @Test
    public void testLookupUser() {

        User user = new User();
        user.setUsername("henri");
        user.setPassword("password");

        userResource.createUser(user);
        User u = userResource.getUserInfo("henri");

        assertEquals(user.getId(), u.getId());
    }
View Full Code Here

    }

    @Test
    public void testDeleteUser() {

        User user = new User();
        user.setUsername("henri");
        user.setPassword("password");

        userResource.createUser(user);

        userResource.deleteUser("henri");
        assertNull(userResource.getUserInfo("henri"));
View Full Code Here

        assertNull(userResource.getUserInfo("henri"));
    }

    @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<Permission>();
        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:
        List<Owner> owners = userResource.listUsersOwners(user.getUsername(),
            userPrincipal);
        assertEquals(1, owners.size());
        assertEquals(owner1.getKey(), owners.get(0).getKey());
    }
View Full Code Here

        assertEquals(owner1.getKey(), owners.get(0).getKey());
    }

    @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<Permission>();
        perms.add(new UsernameConsumersPermission(user, owner1));
        Principal userPrincipal = new UserPrincipal(user.getUsername(), perms, false);

        List<Owner> owners = userResource.listUsersOwners(user.getUsername(),
            userPrincipal);
        assertEquals(1, owners.size());
        assertEquals(owner1.getKey(), owners.get(0).getKey());
    }
View Full Code Here

    }

    @Test
    public void testListAllUsers() {

        User user = new User();
        user.setUsername("henri");
        user.setPassword("password");

        userResource.createUser(user);
        List<User> users = userResource.list();

        assertTrue("length should be 1", users.size() == 1);
View Full Code Here

    }

    @Test
    public void testUpdateUsers() {

        User user = new User();
        user.setUsername("henri");
        user.setPassword("password");

        user = userResource.createUser(user);
        user.setUsername("Luke");
        user.setHashedPassword("Skywalker");
        user.setSuperAdmin(true);
        User updated = userResource.updateUser("henri", user);
        assertEquals("Luke", updated.getUsername());
        assertEquals("Skywalker", updated.getHashedPassword());
        assertTrue(updated.isSuperAdmin());
    }
View Full Code Here

TOP

Related Classes of org.candlepin.model.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.