roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r570223 - in /roller/branches/roller_4.1_dev/apps/weblogger: src/java/org/apache/roller/weblogger/business/ src/java/org/apache/roller/weblogger/business/hibernate/ src/java/org/apache/roller/weblogger/business/jpa/ src/java/org/apache/roll...
Date Mon, 27 Aug 2007 19:00:45 GMT
Author: snoopdave
Date: Mon Aug 27 12:00:43 2007
New Revision: 570223

URL: http://svn.apache.org/viewvc?rev=570223&view=rev
Log:
First step in removing dependence on User.getRoles(), User.hasRole(), User.grantRole().

Part of Externalizing User Management proposal:
http://opensource.atlassian.com/projects/roller/browse/ROL-1534

Modified:
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/UserManager.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateUserManagerImpl.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/User.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/Weblog.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/core/security/RollerUserDetailsService.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/core/util/menu/MenuHelper.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/model/MenuModel.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/CreateUser.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/CreateUserBean.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/ModifyUser.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/EntryAdd.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/EntryEdit.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/util/UISecurityInterceptor.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/adminprotocol/Authenticator.java
    roller/branches/roller_4.1_dev/apps/weblogger/test/java/org/apache/roller/weblogger/business/UserTest.java

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/UserManager.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/UserManager.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/UserManager.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/UserManager.java
Mon Aug 27 12:00:43 2007
@@ -21,6 +21,7 @@
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.pojos.WeblogUserPermission;
 import org.apache.roller.weblogger.pojos.User;
@@ -260,4 +261,22 @@
      * @throws WebloggerException
      */
     public User getUserByActivationCode(String activationCode) throws WebloggerException;
+    
+        
+    /**
+     * Returns true if user has role specified.
+     */
+    public boolean hasRole(User user, String roleName);
+    
+    
+    /**
+     * Returns set of user's roles.
+     */
+    public Set getRoles(User user);
+    
+    
+    /**
+     * Grant role to user by name.
+     */
+    public void grantRole(User user, String roleName) throws WebloggerException;
 }

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateUserManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateUserManagerImpl.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateUserManagerImpl.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateUserManagerImpl.java
Mon Aug 27 12:00:43 2007
@@ -27,7 +27,7 @@
 import java.util.TreeMap;
 import java.util.Collection;
 
-import org.apache.roller.weblogger.pojos.StatCount;
+import java.util.Set;
 import org.hibernate.Criteria;
 import org.hibernate.HibernateException;
 import org.hibernate.Session;
@@ -38,28 +38,10 @@
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.criterion.SimpleExpression;
 import org.apache.roller.weblogger.WebloggerException;
-import org.apache.roller.weblogger.config.WebloggerConfig;
-import org.apache.roller.weblogger.business.pings.AutoPingManager;
-import org.apache.roller.weblogger.business.BookmarkManager;
-import org.apache.roller.weblogger.business.FileManager;
 import org.apache.roller.weblogger.business.Weblogger;
-import org.apache.roller.weblogger.business.pings.PingTargetManager;
 import org.apache.roller.weblogger.business.UserManager;
-import org.apache.roller.weblogger.business.WeblogEntryManager;
-import org.apache.roller.weblogger.business.WebloggerFactory;
-import org.apache.roller.weblogger.pojos.AutoPing;
-import org.apache.roller.weblogger.pojos.WeblogBookmark;
-import org.apache.roller.weblogger.pojos.WeblogBookmarkFolder;
-import org.apache.roller.weblogger.pojos.TagStat;
-import org.apache.roller.weblogger.pojos.WeblogEntryTag;
-import org.apache.roller.weblogger.pojos.WeblogTemplate;
 import org.apache.roller.weblogger.pojos.WeblogUserPermission;
-import org.apache.roller.weblogger.pojos.PingQueueEntry;
-import org.apache.roller.weblogger.pojos.PingTarget;
-import org.apache.roller.weblogger.pojos.WeblogReferrer;
 import org.apache.roller.weblogger.pojos.User;
-import org.apache.roller.weblogger.pojos.WeblogCategory;
-import org.apache.roller.weblogger.pojos.WeblogEntry;
 import org.apache.roller.weblogger.pojos.Weblog;
 import org.apache.roller.weblogger.pojos.UserRole;
 import org.hibernate.Query;
@@ -136,9 +118,9 @@
             throw new WebloggerException("error.add.user.userNameInUse");
         }
         
-        newUser.grantRole("editor");
+        grantRole(newUser, "editor");
         if(adminUser) {
-            newUser.grantRole("admin");
+            grantRole(newUser, "admin");
             
             //if user was disabled (because of activation user account with e-mail property),

             //enable it for admin user
@@ -526,11 +508,37 @@
         website.removePermission(target);
         this.strategy.remove(target);
     }
-        
+    
+    
+    /**
+     * Returns true if user has role specified.
+     */
+    public boolean hasRole(User user, String roleName) {
+        Iterator iter = user.getRoles().iterator();
+        while (iter.hasNext()) {
+            UserRole role = (UserRole) iter.next();
+            if (role.getRole().equals(roleName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    
+    public Set getRoles(User user) {
+        return user.getRoles();
+    }
+    
+     
+    /**
+     * Grant to user role specified by role name.
+     */
+    public void grantRole(User user, String roleName) throws WebloggerException {
+        if (!hasRole(user, roleName)) {
+            UserRole role = new UserRole(null, user, roleName);
+            user.getRoles().add(role);
+            role.setUser(user);
+        }
+    }
 }
-
-
-
-
-
 

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
Mon Aug 27 12:00:43 2007
@@ -37,6 +37,7 @@
 import java.util.TreeMap;
 import java.util.Collection;
 import java.util.Comparator;
+import java.util.Set;
 import javax.persistence.Query;
 import org.apache.roller.weblogger.business.Weblogger;
 
@@ -144,9 +145,9 @@
             throw new WebloggerException("error.add.user.userNameInUse");
         }
         
-        newUser.grantRole("editor");
+        grantRole(newUser, "editor");
         if(adminUser) {
-            newUser.grantRole("admin");
+            grantRole(newUser, "admin");
         }
         
         this.strategy.store(newUser);
@@ -577,5 +578,37 @@
         return (WeblogUserPermission)this.strategy.load(
                 WeblogUserPermission.class, inviteId);
     }
+    
+    
+    /**
+     * Returns true if user has role specified.
+     */
+    public boolean hasRole(User user, String roleName) {
+        Iterator iter = user.getRoles().iterator();
+        while (iter.hasNext()) {
+            UserRole role = (UserRole) iter.next();
+            if (role.getRole().equals(roleName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    
+    public Set getRoles(User user) {
+        return user.getRoles();
+    }
+    
+    /**
+     * Grant to user role specified by role name.
+     */
+    public void grantRole(User user, String roleName) throws WebloggerException {
+        if (!hasRole(user, roleName)) {
+            UserRole role = new UserRole(null, user, roleName);
+            user.getRoles().add(role);
+            role.setUser(user);
+        }
+    }
 }
+
 

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/User.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/User.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/User.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/User.java
Mon Aug 27 12:00:43 2007
@@ -295,34 +295,7 @@
      */
     private void setRoles(Set roles) {
         this.roles = roles;
-    }
-    
-    
-    /**
-     * Returns true if user has role specified.
-     */
-    public boolean hasRole(String roleName) {
-        Iterator iter = getRoles().iterator();
-        while (iter.hasNext()) {
-            UserRole role = (UserRole) iter.next();
-            if (role.getRole().equals(roleName)) {
-                return true;
-            }
-        }
-        return false;
-    }
-    
-    /**
-     * Grant to user role specified by role name.
-     */
-    public void grantRole(String roleName) throws WebloggerException {
-        if (!hasRole(roleName)) {
-            UserRole role = new UserRole(null, this, roleName);
-            getRoles().add(role);
-            role.setUser(this);
-        }
-    }
-    
+    }   
     
     
     //------------------------------------------------------- Good citizenship

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/Weblog.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/Weblog.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/Weblog.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/Weblog.java
Mon Aug 27 12:00:43 2007
@@ -666,7 +666,7 @@
             }
         }
         // otherwise, check to see if user is a global admin
-        if (user != null && user.hasRole("admin")) return true;
+        if (user != null && WebloggerFactory.getWeblogger().getUserManager().hasRole(user,
"admin")) return true;
         return false;
     }
     

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogEntry.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
Mon Aug 27 12:00:43 2007
@@ -1114,7 +1114,7 @@
     public boolean hasWritePermissions(User user) throws WebloggerException {
         
         // global admins can hack whatever they want
-        if(user.hasRole("admin")) {
+        if(WebloggerFactory.getWeblogger().getUserManager().hasRole(user, "admin")) {
             return true;
         }
         

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/core/security/RollerUserDetailsService.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/core/security/RollerUserDetailsService.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/core/security/RollerUserDetailsService.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/core/security/RollerUserDetailsService.java
Mon Aug 27 12:00:43 2007
@@ -23,10 +23,10 @@
     public UserDetails loadUserByUsername(String userName) 
         throws UsernameNotFoundException, DataAccessException {
         
+        Weblogger roller = WebloggerFactory.getWeblogger();
+        UserManager umgr = roller.getUserManager();
         User userData = null;
         try {
-            Weblogger roller = WebloggerFactory.getWeblogger();
-            UserManager umgr = roller.getUserManager();
             userData = umgr.getUserByUserName(userName, Boolean.TRUE); 
         } catch (WebloggerException ex) {
             throw new DataRetrievalFailureException("ERROR in user lookup", ex);
@@ -37,9 +37,9 @@
         }
         
         GrantedAuthority[] authorities = 
-            new GrantedAuthorityImpl[userData.getRoles().size()];
+            new GrantedAuthorityImpl[umgr.getRoles(userData).size()];
         int i = 0;
-        for (Iterator it = userData.getRoles().iterator(); it.hasNext();) {
+        for (Iterator it = umgr.getRoles(userData).iterator(); it.hasNext();) {
             UserRole role = (UserRole)it.next();
             authorities[i++] = new GrantedAuthorityImpl(role.getRole());
         }

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/core/util/menu/MenuHelper.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/core/util/menu/MenuHelper.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/core/util/menu/MenuHelper.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/core/util/menu/MenuHelper.java
Mon Aug 27 12:00:43 2007
@@ -25,6 +25,7 @@
 import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.config.WebloggerConfig;
 import org.apache.roller.weblogger.pojos.WeblogUserPermission;
 import org.apache.roller.weblogger.pojos.User;
@@ -106,7 +107,7 @@
             if(includeTab) {
                 // user roles check
                 if(configTab.getRole() != null) {
-                    if(!user.hasRole(configTab.getRole())) {
+                    if(!WebloggerFactory.getWeblogger().getUserManager().hasRole(user, configTab.getRole()))
{
                         includeTab = false;
                     }
                 }
@@ -143,7 +144,7 @@
                     if(includeItem) {
                         // user roles check
                         if(configTabItem.getRole() != null) {
-                            if(!user.hasRole(configTabItem.getRole())) {
+                            if(!WebloggerFactory.getWeblogger().getUserManager().hasRole(user,
configTabItem.getRole())) {
                                 includeItem = false;
                             }
                         }

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/model/MenuModel.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/model/MenuModel.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/model/MenuModel.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/model/MenuModel.java
Mon Aug 27 12:00:43 2007
@@ -22,6 +22,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.weblogger.WebloggerException;
+import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.ui.core.util.menu.Menu;
 import org.apache.roller.weblogger.ui.core.util.menu.MenuHelper;
 import org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest;
@@ -71,7 +72,8 @@
      * currently logged in and is an admin.
      */
     public Menu getAdminMenu() {
-        if(pageRequest.isLoggedIn() && pageRequest.getUser().hasRole("admin")) {
+        if(pageRequest.isLoggedIn() && WebloggerFactory.getWeblogger()
+                .getUserManager().hasRole(pageRequest.getUser(), "admin")) {
             return MenuHelper.getMenu("admin", "noAction", pageRequest.getUser(), pageRequest.getWeblog());
         }
         return null;

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/CreateUser.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/CreateUser.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/CreateUser.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/CreateUser.java
Mon Aug 27 12:00:43 2007
@@ -98,7 +98,7 @@
             
             // are we granting the user admin rights?
             if(((CreateUserBean)getBean()).isAdministrator()) {
-                newUser.grantRole("admin");
+                mgr.grantRole(newUser, "admin");
             }
             
             // save new user

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/CreateUserBean.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/CreateUserBean.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/CreateUserBean.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/CreateUserBean.java
Mon Aug 27 12:00:43 2007
@@ -19,6 +19,7 @@
 package org.apache.roller.weblogger.ui.struts2.admin;
 
 import java.util.Locale;
+import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.pojos.User;
 
 
@@ -155,7 +156,7 @@
         this.enabled = dataHolder.getEnabled();
         this.activationCode = dataHolder.getActivationCode();
         
-        this.administrator = dataHolder.hasRole("admin");
+        this.administrator =  WebloggerFactory.getWeblogger().getUserManager().hasRole(dataHolder,
"admin");
     }
     
 }

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/ModifyUser.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/ModifyUser.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/ModifyUser.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/admin/ModifyUser.java
Mon Aug 27 12:00:43 2007
@@ -130,7 +130,7 @@
                 UserManager mgr = WebloggerFactory.getWeblogger().getUserManager();
                 
                 // grant/revoke admin role if needed
-                if (getUser().hasRole("admin") && !getBean().isAdministrator()) {
+                if (mgr.hasRole(getUser(), "admin") && !getBean().isAdministrator())
{
                     
                     if (!isUserEditingSelf()) {
                         // revoke role
@@ -139,11 +139,11 @@
                         addError("userAdmin.cantChangeOwnRole");
                     }
                     
-                } else if(!getUser().hasRole("admin") && getBean().isAdministrator())
{
+                } else if(!mgr.hasRole(getUser(), "admin") && getBean().isAdministrator())
{
                     
                     if (!isUserEditingSelf()) {
                         // grant role
-                        getUser().grantRole("admin");
+                        mgr.grantRole(getUser(), "admin");
                     } else {
                         addError("userAdmin.cantChangeOwnRole"); 
                     }

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/EntryAdd.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/EntryAdd.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/EntryAdd.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/EntryAdd.java
Mon Aug 27 12:00:43 2007
@@ -33,6 +33,7 @@
 import org.apache.roller.weblogger.util.cache.CacheManager;
 import org.apache.roller.weblogger.util.MailUtil;
 import org.apache.commons.lang.StringUtils;
+import org.apache.roller.weblogger.business.UserManager;
 import org.apache.roller.weblogger.pojos.WeblogCategory;
 import org.apache.roller.weblogger.util.MediacastResource;
 import org.apache.roller.weblogger.util.MediacastUtil;
@@ -102,6 +103,7 @@
     public String save() {
         
         if(!hasActionErrors()) try {
+            UserManager userMgr = WebloggerFactory.getWeblogger().getUserManager();
             WeblogEntryManager weblogMgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
             
             WeblogEntry entry = new WeblogEntry();
@@ -129,7 +131,7 @@
             }
             
             // if user is an admin then apply pinned to main value as well
-            if(getAuthenticatedUser().hasRole("admin")) {
+            if (userMgr.hasRole(getAuthenticatedUser(), "admin")) {
                 entry.setPinnedToMain(getBean().getPinnedToMain());
             }
             

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/EntryEdit.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/EntryEdit.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/EntryEdit.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/EntryEdit.java
Mon Aug 27 12:00:43 2007
@@ -149,7 +149,7 @@
             }
             
             // if user is an admin then apply pinned to main value as well
-            if(getAuthenticatedUser().hasRole("admin")) {
+            if(WebloggerFactory.getWeblogger().getUserManager().hasRole(getAuthenticatedUser(),
"admin")) {
                 entry.setPinnedToMain(getBean().getPinnedToMain());
             }
             

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java
Mon Aug 27 12:00:43 2007
@@ -23,6 +23,7 @@
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.List;
+import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.config.WebloggerConfig;
 import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
 import org.apache.roller.weblogger.pojos.User;
@@ -96,7 +97,7 @@
     
     // convenient way to tell if user being dealt with is an admin
     public boolean isUserIsAdmin() {
-        return getAuthenticatedUser().hasRole("admin");
+        return WebloggerFactory.getWeblogger().getUserManager().hasRole(getAuthenticatedUser(),
"admin");
     }
     
     

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/util/UISecurityInterceptor.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/util/UISecurityInterceptor.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/util/UISecurityInterceptor.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/util/UISecurityInterceptor.java
Mon Aug 27 12:00:43 2007
@@ -22,6 +22,7 @@
 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.pojos.User;
 import org.apache.roller.weblogger.pojos.Weblog;
 
@@ -59,7 +60,7 @@
                 
                 // are we also enforcing a specific role?
                 if(theAction.requiredUserRole() != null) {
-                    if(!authenticatedUser.hasRole(theAction.requiredUserRole())) {
+                    if(!WebloggerFactory.getWeblogger().getUserManager().hasRole(authenticatedUser,
theAction.requiredUserRole())) {
                         log.debug("DENIED: user does not have role = "+theAction.requiredUserRole());
                         return "access-denied";
                     }

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/adminprotocol/Authenticator.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/adminprotocol/Authenticator.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/adminprotocol/Authenticator.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/adminprotocol/Authenticator.java
Mon Aug 27 12:00:43 2007
@@ -55,7 +55,7 @@
             throw new UnauthorizedException("ERROR: User is not authorized: " + userName);
         }
         
-        if (!ud.hasRole("admin")) {
+        if (!WebloggerFactory.getWeblogger().getUserManager().hasRole(ud, "admin")) {
             throw new UnauthorizedException("ERROR: User must have the admin role to use
the RAP endpoint: " + userName);
         }
         if (!ud.getEnabled().booleanValue()) {

Modified: roller/branches/roller_4.1_dev/apps/weblogger/test/java/org/apache/roller/weblogger/business/UserTest.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/test/java/org/apache/roller/weblogger/business/UserTest.java?rev=570223&r1=570222&r2=570223&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/test/java/org/apache/roller/weblogger/business/UserTest.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/test/java/org/apache/roller/weblogger/business/UserTest.java
Mon Aug 27 12:00:43 2007
@@ -186,9 +186,9 @@
         // 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"));
+        assertEquals(2, mgr.getRoles(user).size());
+        assertTrue(mgr.hasRole(user,"editor"));
+        assertTrue(mgr.hasRole(user,"admin"));
         
         // remove role
         mgr.revokeRole("admin",user);
@@ -199,12 +199,12 @@
         user = null;
         user = mgr.getUserByUserName(testUser.getUserName());
         assertNotNull(user);
-        assertEquals(1, user.getRoles().size());
-        assertTrue(user.hasRole("editor"));
-        assertFalse(user.hasRole("admin"));
+        assertEquals(1, mgr.getRoles(user).size());
+        assertTrue(mgr.hasRole(user,"editor"));
+        assertFalse(mgr.hasRole(user,"admin"));
         
         // add role
-        user.grantRole("admin");
+        mgr.grantRole(user, "admin");
         mgr.saveUser(user);
         TestUtils.endSession(true);
         
@@ -212,9 +212,9 @@
         user = null;
         user = mgr.getUserByUserName(testUser.getUserName());
         assertNotNull(user);
-        assertEquals(2, user.getRoles().size());
-        assertTrue(user.hasRole("editor"));
-        assertTrue(user.hasRole("admin"));
+        assertEquals(2, mgr.getRoles(user).size());
+        assertTrue(mgr.hasRole(user,"editor"));
+        assertTrue(mgr.hasRole(user,"admin"));
         
         // remove test user
         TestUtils.teardownUser(testUser.getId());



Mime
View raw message