Package org.apache.roller.pojos

Examples of org.apache.roller.pojos.UserData


       
        // check cache first
        // NOTE: if we ever allow changing usernames then this needs updating
        if(this.userNameToIdMap.containsKey(userName)) {
           
            UserData user = this.getUser((String) this.userNameToIdMap.get(userName));
            if(user != null) {
                // only return the user if the enabled status matches
                if(enabled == null || enabled.equals(user.getEnabled())) {
                    log.debug("userNameToIdMap CACHE HIT - "+userName);
                    return user;
                }
            } else {
                // mapping hit with lookup miss?  mapping must be old, remove it
                this.userNameToIdMap.remove(userName);
            }
        }
       
        // cache failed, do lookup
        try {
            Session session = ((HibernatePersistenceStrategy)this.strategy).getSession();
            Criteria criteria = session.createCriteria(UserData.class);
           
            if (enabled != null) {
                criteria.add(
                        Expression.conjunction()
                        .add(Expression.eq("userName", userName))
                        .add(Expression.eq("enabled", enabled)));
            } else {
                criteria.add(
                        Expression.conjunction()
                        .add(Expression.eq("userName", userName)));
            }
           
            UserData user = (UserData) criteria.uniqueResult();
           
            // add mapping to cache
            if(user != null) {
                log.debug("userNameToIdMap CACHE MISS - "+userName);
                this.userNameToIdMap.put(user.getUserName(), user.getId());
            }
           
            return user;
        } catch (HibernateException e) {
            throw new RollerException(e);
View Full Code Here


        }
        int pos = 0;
        int count = 0;
        Iterator iter = rawresults.iterator();
        while (iter.hasNext() && count < length) {
            UserData user = (UserData)iter.next();
            if (pos++ >= offset) {
                results.add(user);
                count++;
            }
        }
View Full Code Here

                WebsiteData website) throws RollerException {
            super(titleKey, request, response, mapping);
            this.website = website;
            Roller roller = RollerFactory.getRoller();
            RollerSession rollerSession = RollerSession.getRollerSession(request);
            UserData user = rollerSession.getAuthenticatedUser();
            permissions = roller.getUserManager().getAllPermissions(website);
            groupBloggingEnabled =
                RollerConfig.getBooleanProperty("groupblogging.enabled");
            emailNotificationEnabled =
                RollerRuntimeConfig.getBooleanProperty("users.comments.emailnotify");
View Full Code Here

            throws Exception
    {
        YourWebsitesForm form = (YourWebsitesForm)actionForm;
       
        RollerSession rses = RollerSession.getRollerSession(request);
        UserData user = rses.getAuthenticatedUser();
        RollerRequest rreq = RollerRequest.getRollerRequest(request);
        WebsiteData website = rreq.getWebsite();
       
        UserManager userMgr = RollerFactory.getRoller().getUserManager();
        PermissionsData perms = userMgr.getPermissions(website, user);
View Full Code Here

          HttpServletResponse response, ActionMapping mapping) throws RollerException
        {
            super("yourWebsites.title", request, response, mapping);
            Roller roller = RollerFactory.getRoller();
            RollerSession rollerSession = RollerSession.getRollerSession(request);
            UserData user = rollerSession.getAuthenticatedUser();
            permissions = roller.getUserManager().getAllPermissions(user);
            userWeblogCount = permissions.size();
            pendings = roller.getUserManager().getPendingPermissions(user);
            groupBloggingEnabled =
                RollerConfig.getBooleanProperty("groupblogging.enabled");
View Full Code Here

        MockHttpServletRequest mockRequest = getMockFactory().getMockRequest();
        mockRequest.setContextPath("/dummy");       
        doFilters();
       
        UserManager umgr = null;
        UserData user = null;
        try
        {
            umgr = getRoller().getUserManager();
            user = (UserData)umgr.getUsers(mWebsite, null).get(0);      
            authenticateUser(user.getUserName(), "editor");
        }
        catch (RollerException e)
        {
            e.printStackTrace();
            fail();
View Full Code Here

     * Test basic persistence operations ... Create, Update, Delete.
     */
    public void testUserCRUD() throws Exception {
       
        UserManager mgr = RollerFactory.getRoller().getUserManager();
        UserData user = null;
       
        UserData testUser = new UserData();
        testUser.setUserName("testUser");
        testUser.setPassword("password");
        testUser.setFullName("Test User");
        testUser.setEmailAddress("TestUser@dev.null");
        testUser.setLocale("en_US");
        testUser.setTimeZone("America/Los_Angeles");
        testUser.setDateCreated(new java.util.Date());
        testUser.setEnabled(Boolean.TRUE);
       
        // make sure test user does not exist
        user = mgr.getUserByUsername(testUser.getUserName());
        assertNull(user);
       
        // add test user
        mgr.addUser(testUser);
        String id = testUser.getId();
        TestUtils.endSession(true);
       
        // make sure test user exists
        user = null;
        user = mgr.getUser(id);
View Full Code Here

     * Test lookup mechanisms.
     */
    public void testUserLookups() throws Exception {
       
        UserManager mgr = RollerFactory.getRoller().getUserManager();
        UserData user = null;
       
        // add test user
        UserData testUser = TestUtils.setupUser("userTestUser");
        TestUtils.endSession(true);
       
        // lookup by username
        user = mgr.getUserByUsername(testUser.getUserName());
        assertNotNull(user);
        assertEquals(testUser.getUserName(), user.getUserName());
       
        // lookup by id
        String id = user.getId();
        user = null;
        user = mgr.getUser(id);
        assertNotNull(user);
        assertEquals(testUser.getUserName(), user.getUserName());
       
        // lookup by UserName (part)
        user = null;
        List users1 = mgr.getUsersStartingWith(testUser.getUserName().substring(0, 3), 0, 1, Boolean.TRUE);
        assertEquals(1, users1.size());
        user = (UserData) users1.get(0);
        assertNotNull(user);
        assertEquals(testUser.getUserName(), user.getUserName());
       
        // lookup by Email (part)
        user = null;
        List users2 = mgr.getUsersStartingWith(testUser.getEmailAddress().substring(0, 3), 0, 1, Boolean.TRUE);
        assertEquals(1, users2.size());
        user = (UserData) users2.get(0);
        assertNotNull(user);
        assertEquals(testUser.getUserName(), user.getUserName());
       
        // make sure disable users are not returned
        user.setEnabled(Boolean.FALSE);
        mgr.saveUser(user);
        user = null;
        user = mgr.getUserByUsername(testUser.getUserName());
        assertNull(user);
       
        // remove test user
        TestUtils.teardownUser(testUser.getId());
        TestUtils.endSession(true);
    }
View Full Code Here

     * Test basic user role persistence ... Add, Remove
     */
    public void testRoleCRUD() throws Exception {
       
        UserManager mgr = RollerFactory.getRoller().getUserManager();
        UserData user = null;
       
        // add test user
        UserData testUser = TestUtils.setupUser("roleTestUser");
        TestUtils.endSession(true);
       
        // verify user has 2 roles, admin & editor
        user = mgr.getUserByUsername(testUser.getUserName());
        assertNotNull(user);
        assertEquals(2, user.getRoles().size());
        assertTrue(user.hasRole("editor"));
        assertTrue(user.hasRole("admin"));
       
        // remove role
        user.revokeRole("admin");
        mgr.saveUser(user);
        TestUtils.endSession(true);
       
        // check that role was removed
        user = null;
        user = mgr.getUserByUsername(testUser.getUserName());
        assertNotNull(user);
        assertEquals(1, user.getRoles().size());
        assertTrue(user.hasRole("editor"));
        assertFalse(user.hasRole("admin"));
       
        // add role
        user.grantRole("admin");
        mgr.saveUser(user);
        TestUtils.endSession(true);
       
        // check that role was added
        user = null;
        user = mgr.getUserByUsername(testUser.getUserName());
        assertNotNull(user);
        assertEquals(2, user.getRoles().size());
        assertTrue(user.hasRole("editor"));
        assertTrue(user.hasRole("admin"));
       
        // remove test user
        TestUtils.teardownUser(testUser.getId());
        TestUtils.endSession(true);
    }
View Full Code Here

     * Test lookup mechanisms.
     */
    public void testPermissionsLookups() throws Exception {
       
        // we need a second user for this test
        UserData user = TestUtils.setupUser("foofoo");
        TestUtils.endSession(true);
       
        UserManager mgr = RollerFactory.getRoller().getUserManager();
        PermissionsData perm = null;
        List perms = null;
       
        // get all permissions for a user
        perms = mgr.getAllPermissions(user);
        assertEquals(0, perms.size());
        perms = mgr.getAllPermissions(testUser);
        assertEquals(1, perms.size());
       
        // get all permissions for a weblog
        perms = mgr.getAllPermissions(testWeblog);
        assertEquals(1, perms.size());
       
        perm = new PermissionsData();
        perm.setUser(user);
        perm.setWebsite(testWeblog);
        perm.setPending(true);
        perm.setPermissionMask(PermissionsData.AUTHOR);
        mgr.savePermissions(perm);
       
        // get pending permissions for a user
        perms = mgr.getPendingPermissions(testUser);
        assertEquals(0, perms.size());
        perms = mgr.getPendingPermissions(user);
        assertEquals(1, perms.size());
       
        // get pending permissions for a weblog
        perms = mgr.getPendingPermissions(testWeblog);
        assertEquals(1, perms.size());
       
        // get permissions by id
        String id = perm.getId();
        perm = null;
        perm = mgr.getPermissions(id);
        assertNotNull(perm);
        assertEquals(id, perm.getId());
       
        // get permissions for a specific user/weblog
        perm = null;
        perm = mgr.getPermissions(testWeblog, testUser);
        assertNotNull(perm);
        assertEquals(PermissionsData.ADMIN, perm.getPermissionMask());
        perm = null;
        perm = mgr.getPermissions(testWeblog, user);
        assertNotNull(perm);
        assertEquals(PermissionsData.AUTHOR, perm.getPermissionMask());
        assertEquals(true, perm.isPending());
       
        // cleanup the extra test user
        TestUtils.teardownUser(user.getId());
        TestUtils.endSession(true);
    }
View Full Code Here

TOP

Related Classes of org.apache.roller.pojos.UserData

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.