portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r921340 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java jetspeed-api/src/main/java/org/apache/jetspeed/administration/PortalAdministration.java
Date Wed, 10 Mar 2010 13:29:54 GMT
Author: woonsan
Date: Wed Mar 10 13:29:53 2010
New Revision: 921340

URL: http://svn.apache.org/viewvc?rev=921340&view=rev
Log:
JS2-1057: Adding convenient methods to check if the current request context is from admin
user or admin role.

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/administration/PortalAdministration.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java?rev=921340&r1=921339&r2=921340&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
Wed Mar 10 13:29:53 2010
@@ -18,6 +18,7 @@ package org.apache.jetspeed.administrati
 
 import java.io.FileReader;
 import java.io.StringWriter;
+import java.security.Principal;
 import java.security.PrivilegedAction;
 import java.util.Collection;
 import java.util.HashMap;
@@ -30,8 +31,6 @@ import javax.portlet.PortletRequest;
 import javax.portlet.PortletResponse;
 
 import org.apache.commons.configuration.Configuration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.jetspeed.Jetspeed;
 import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.exception.JetspeedException;
@@ -53,6 +52,8 @@ import org.apache.jetspeed.security.User
 import org.apache.jetspeed.security.UserManager;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.mail.MailException;
 import org.springframework.mail.SimpleMailMessage;
 import org.springframework.mail.javamail.JavaMailSender;
@@ -67,9 +68,8 @@ import org.springframework.mail.javamail
  * 
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer</a>
- * @version $Id: $
+ * @version $Id$
  */
-
 public class PortalAdministrationImpl implements PortalAdministration
 {
     private final static Logger log = LoggerFactory.getLogger(PortalAdministrationImpl.class);
@@ -95,6 +95,8 @@ public class PortalAdministrationImpl im
     protected String folderTemplate;
     /** default administrative user */
     protected String adminUser;
+    /** default administrative role */
+    protected String adminRole;
         
     public PortalAdministrationImpl( UserManager userManager,
                                      RoleManager roleManager,
@@ -136,7 +138,7 @@ public class PortalAdministrationImpl im
         this.folderTemplate = 
             config.getString(PortalConfigurationConstants.PSML_TEMPLATE_FOLDER);
         this.adminUser = config.getString(PortalConfigurationConstants.USERS_DEFAULT_ADMIN);
-        
+        this.adminRole = config.getString(PortalConfigurationConstants.ROLES_DEFAULT_ADMIN);
     }
     
     public void registerUser(String userName, String password)
@@ -485,7 +487,7 @@ public class PortalAdministrationImpl im
             forgottenPasswordData.put(guid,info);
         }
     }
-
+    
     /* (non-Javadoc)
      * @see org.apache.jetspeed.administration.PortalAdministration#removeNewLoginInfo(java.lang.String)
      */
@@ -496,8 +498,31 @@ public class PortalAdministrationImpl im
         }
     }
     
+    public boolean isAdminUser(PortletRequest request)
+    {
+        if (adminUser == null)
+        {
+            throw new IllegalStateException("PortalAdministration component is not started
or misconfigured for the default admin user.");
+        }
+        
+        Principal principal = request.getUserPrincipal();
+        
+        if (principal != null)
+        {
+            return adminUser.equals(principal.getName());
+        }
+        
+        return false;
+    }
     
-    
-    
+    public boolean isUserInAdminRole(PortletRequest request)
+    {
+        if (adminRole == null)
+        {
+            throw new IllegalStateException("PortalAdministration component is not started
or misconfigured for the default admin role.");
+        }
+        
+        return request.isUserInRole(adminRole);
+    }
     
 }

Modified: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/administration/PortalAdministration.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/administration/PortalAdministration.java?rev=921340&r1=921339&r2=921340&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/administration/PortalAdministration.java
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/administration/PortalAdministration.java
Wed Mar 10 13:29:53 2010
@@ -22,6 +22,7 @@ import java.util.Map;
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletRequest;
 import javax.portlet.PortletResponse;
+
 import org.apache.jetspeed.security.User;
 
 /**
@@ -162,6 +163,20 @@ public interface PortalAdministration
      * @param guid    the ID which will be removed from the storage when the info is no longer
valid
      */
     public void removeNewLoginInfo(String guid);
-        
+    
+    /**
+     * Returns true if the current request user principal's name is the name of the portal
admin user.
+     * @param request
+     * @return
+     */
+    public boolean isAdminUser(PortletRequest request);
+    
+    /**
+     * Returns true if the current request user principal is in the portal admin role.
+     * @param request
+     * @return
+     */
+    public boolean isUserInAdminRole(PortletRequest request);
+    
 }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message