Package org.apache.roller.pojos

Examples of org.apache.roller.pojos.UserData


     * 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


        // Send commment notifications in locale of server
        ResourceBundle resources = ResourceBundle.getBundle("ApplicationResources");

        WeblogEntryData entry = cd.getWeblogEntry();
        WebsiteData site = entry.getWebsite();
        UserData user = entry.getCreator();
       
        // Send e-mail to owner and subscribed users (if enabled)
        boolean notify = RollerRuntimeConfig.getBooleanProperty("users.comments.emailnotify");
        if (notify && site.getEmailComments().booleanValue()) {
            log.debug("Comment notification enabled ... preparing email");
           
            // Determine message and addressing options from init parameters
            boolean separateMessages =
                    RollerConfig.getBooleanProperty("comment.notification.separateOwnerMessage");
            boolean hideCommenterAddrs =
                    RollerConfig.getBooleanProperty("comment.notification.hideCommenterAddresses");
           
            //------------------------------------------
            // --- Determine the "from" address
            // --- Use either the site configured from address or the user's address
           
            String from =
                    (StringUtils.isEmpty(site.getEmailFromAddress()))
                    ? user.getEmailAddress()
                    : site.getEmailFromAddress();
           
            //------------------------------------------
            // --- Build list of email addresses to send notification to
           
            List comments = null;
            try {
                WeblogManager wMgr = RollerFactory.getRoller().getWeblogManager();
                // get only approved, non spam comments
                comments = entry.getComments(true, true);
            } catch(RollerException re) {
                // should never happen
                comments = new ArrayList();
            }
           
            // Get all the subscribers to this comment thread
            Set subscribers = new TreeSet();
            for (Iterator it = comments.iterator(); it.hasNext();) {
                CommentData comment = (CommentData) it.next();
                if (!StringUtils.isEmpty(comment.getEmail())) {
                    // If user has commented twice,
                    // count the most recent notify setting
                    if (comment.getNotify().booleanValue()) {
                        // only add those with valid email
                        if (comment.getEmail().matches(EMAIL_ADDR_REGEXP)) {
                            subscribers.add(comment.getEmail());
                        }
                    } else {
                        // remove user who doesn't want to be notified
                        subscribers.remove(comment.getEmail());
                    }
                }
            }
           
            // Form array of commenter addrs
            String[] commenterAddrs = (String[])subscribers.toArray(new String[0]);
           
            //------------------------------------------
            // --- Form the messages to be sent -
            // For simplicity we always build separate owner and commenter messages even if sending a single one
           
            // Determine with mime type to use for e-mail
            StringBuffer msg = new StringBuffer();
            StringBuffer ownermsg = new StringBuffer();
            boolean escapeHtml = RollerRuntimeConfig.getBooleanProperty("users.comments.escapehtml");
           
            if (!escapeHtml) {
                msg.append("<html><body style=\"background: white; ");
                msg.append(" color: black; font-size: 12px\">");
            }
           
            if (!StringUtils.isEmpty(cd.getName())) {
                msg.append(cd.getName() + " "
                        + resources.getString("email.comment.wrote")+": ");
            } else {
                msg.append(resources.getString("email.comment.anonymous")+": ");
            }
           
            msg.append((escapeHtml) ? "\n\n" : "<br /><br />");
                       
            msg.append((escapeHtml) ? Utilities.escapeHTML(cd.getContent())
                : UtilitiesModel.transformToHTMLSubset(Utilities.escapeHTML(cd.getContent())));
           
            msg.append((escapeHtml) ? "\n\n----\n"
                    : "<br /><br /><hr /><span style=\"font-size: 11px\">");
            msg.append(resources.getString("email.comment.respond") + ": ");
            msg.append((escapeHtml) ? "\n" : "<br />");

            // Build link back to comment
            StringBuffer commentURL = new StringBuffer(rootURL);
            commentURL.append(entry.getPermaLink());
            commentURL.append("#comments");
           
            if (escapeHtml) {
                msg.append(commentURL.toString());
            } else {
                msg.append("<a href=\""+commentURL+"\">"+commentURL+"</a></span>");
            }
           
            ownermsg.append(msg);
           
            // add link to weblog edit page so user can login to manage comments
            ownermsg.append((escapeHtml) ? "\n\n----\n" :
                "<br /><br /><hr /><span style=\"font-size: 11px\">");
            ownermsg.append("Link to comment management page:");
            ownermsg.append((escapeHtml) ? "\n" : "<br />");
           
            StringBuffer deleteURL = new StringBuffer(rootURL);
            deleteURL.append("/roller-ui/authoring/commentManagement.do?method=query&entryId=" + entry.getId());
           
            if (escapeHtml) {
                ownermsg.append(deleteURL.toString());
            } else {
                ownermsg.append(
                        "<a href=\"" + deleteURL + "\">" + deleteURL + "</a></span>");
                msg.append("</Body></html>");
                ownermsg.append("</Body></html>");
            }
           
            String subject = null;
            if ((subscribers.size() > 1) ||
                    (StringUtils.equals(cd.getEmail(), user.getEmailAddress()))) {
                subject= "RE: "+resources.getString("email.comment.title")+": ";
            } else {
                subject = resources.getString("email.comment.title") + ": ";
            }
            subject += entry.getTitle();
           
            //------------------------------------------
            // --- Send message to email recipients
            try {
                Context ctx = (Context)
                new InitialContext().lookup("java:comp/env");
                Session session = (Session)ctx.lookup("mail/Session");
                boolean isHtml = !escapeHtml;
                if (separateMessages) {
                    // Send separate messages to owner and commenters
                    sendMessage(session, from,
                            new String[]{user.getEmailAddress()}, null, null, subject, ownermsg.toString(), isHtml);
                            if (commenterAddrs.length > 0) {
                                // If hiding commenter addrs, they go in Bcc: otherwise in the To: of the second message
                                String[] to = hideCommenterAddrs ? null : commenterAddrs;
                                String[] bcc = hideCommenterAddrs ? commenterAddrs : null;
                                sendMessage(session, from, to, null, bcc, subject, msg.toString(), isHtml);
                               
                            }
                } else {
                    // Single message.  User in To: header, commenters in either cc or bcc depending on hiding option
                    String[] cc = hideCommenterAddrs ? null : commenterAddrs;
                    String[] bcc = hideCommenterAddrs ? commenterAddrs : null;
                    sendMessage(session, from, new String[]{user.getEmailAddress()}, cc, bcc, subject,
                            ownermsg.toString(), isHtml);
                }
            } catch (NamingException ne) {
                log.error("Unable to lookup mail session.  Check configuration.  NamingException: " + ne.getMessage());
            } catch (Exception e) {
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

        // Send commment notifications in locale of server
        ResourceBundle resources = ResourceBundle.getBundle("ApplicationResources");
       
        WeblogEntryData entry = cd.getWeblogEntry();
        WebsiteData site = entry.getWebsite();
        UserData user = entry.getCreator();
           
        // Only send email if email notificaiton is enabled
        boolean notify = RollerRuntimeConfig.getBooleanProperty("users.comments.emailnotify");
        if (notify && site.getEmailComments().booleanValue()) {
            log.debug("Comment notification enabled ... preparing email");
           

                               
            //------------------------------------------
            // --- Determine the "from" address
            // --- Use either the site configured from address or the user's address
           
            String from =
                    (StringUtils.isEmpty(site.getEmailFromAddress()))
                    ? user.getEmailAddress()
                    : site.getEmailFromAddress();
                       
            //------------------------------------------
            // --- Form the message to be sent -
           
View Full Code Here

            WeblogEntryFormEx  form = (WeblogEntryFormEx)actionForm;
            Roller           roller = RollerFactory.getRoller();
            RollerSession      rses = RollerSession.getRollerSession(request);
            UserManager     userMgr = roller.getUserManager();
            WeblogManager weblogMgr = roller.getWeblogManager();
            UserData           ud  = userMgr.getUser(form.getCreatorId());
            WebsiteData       site = userMgr.getWebsite(form.getWebsiteId());
            WeblogEntryData  entry = null;
           
            if ( rses.isUserAuthorizedToAuthor(site)
            || (rses.isUserAuthorized(site)
View Full Code Here

                     entry.getWebsite(), Boolean.TRUE, 0, -1);
               
                // build list of reviewers (website users with author permission)
                Iterator websiteUserIter = websiteUsers.iterator();
                while (websiteUserIter.hasNext()) {
                    UserData websiteUser = (UserData)websiteUserIter.next();
                    if (entry.getWebsite().hasUserPermissions(
                            websiteUser, PermissionsData.AUTHOR)
                            && websiteUser.getEmailAddress() != null) {
                        reviewers.add(websiteUser.getEmailAddress());
                    }
                }
                to = (String[])reviewers.toArray(new String[reviewers.size()]);
               
                // Figure URL to entry edit page
View Full Code Here

                    rawUsers.remove(rawUsers.size() - 1);
                }
               
                // wrap the results
                for (Iterator it = rawUsers.iterator(); it.hasNext();) {
                    UserData user = (UserData) it.next();
                    results.add(UserDataWrapper.wrap(user));
                }
               
            } catch (Exception e) {
                log.error("ERROR: fetching user list", e);
View Full Code Here

        mLogger.debug("      Title: " + title);
       
        try {
            Roller roller = RollerFactory.getRoller();
            WeblogManager weblogMgr = roller.getWeblogManager();
            UserData user = roller.getUserManager().getUserByUserName(userid);
            Timestamp current =
                    new Timestamp(System.currentTimeMillis());
           
            WeblogEntryData entry = new WeblogEntryData();
            entry.setTitle(title);
View Full Code Here

        boolean userEnabled = false;
        boolean weblogEnabled = false;
        boolean apiEnabled = false;
        boolean weblogFound = false;
        WebsiteData website = null;
        UserData user = null;
        try {
            UserManager userMgr = RollerFactory.getRoller().getUserManager();
            user = userMgr.getUserByUserName(username);
            userEnabled = user.getEnabled().booleanValue();
           
            website = userMgr.getWebsiteByHandle(blogid);
            if (website != null) {
                weblogFound = true;
                weblogEnabled = website.getEnabled().booleanValue();
                apiEnabled = website.getEnableBloggerApi().booleanValue();
            }
           
            if (user != null) {
                // are passwords encrypted?
                RollerContext rollerContext =
                        RollerContext.getRollerContext();
                String encrypted =
                        RollerConfig.getProperty("passwds.encryption.enabled");
                //System.out.print("password was [" + password + "] ");
                if ("true".equalsIgnoreCase(encrypted)) {
                    password = Utilities.encodePassword(password,
                            RollerConfig.getProperty("passwds.encryption.algorithm"));
                }
                authenticated = password.equals(user.getPassword());
            }
        } catch (Exception e) {
            mLogger.error("ERROR internal error validating user", e);
        }
       
View Full Code Here

     */
    protected boolean validateUser(String username, String password)
    throws Exception {
        boolean authenticated = false;
        boolean enabled = false;
        UserData user = null;
        try {
           
            UserManager userMgr = RollerFactory.getRoller().getUserManager();
            user = userMgr.getUserByUserName(username);
           
            enabled = user.getEnabled().booleanValue();
            if (enabled) {
                // are passwords encrypted?
                RollerContext rollerContext =
                        RollerContext.getRollerContext();
                String encrypted =
                        RollerConfig.getProperty("passwds.encryption.enabled");
                //System.out.print("password was [" + password + "] ");
                if ("true".equalsIgnoreCase(encrypted)) {
                    password = Utilities.encodePassword(password,
                            RollerConfig.getProperty("passwds.encryption.algorithm"));
                }
                //System.out.println("is now [" + password + "]");
                authenticated = user.getPassword().equals(password);
                if (authenticated) {
                    //RollerFactory.getRoller().setUser(user);
                }
            }
        } catch (Exception e) {
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.