portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r350013 - in /portals/jetspeed-2/trunk: components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java jetspeed-api/src/java/org/apache/jetspeed/administration/PortalAdministration.java
Date Wed, 30 Nov 2005 18:56:30 GMT
Author: taylor
Date: Wed Nov 30 10:56:27 2005
New Revision: 350013

URL: http://svn.apache.org/viewcvs?rev=350013&view=rev
Log:
add api to make it easy for admin portlets to generate portal URLs

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

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java?rev=350013&r1=350012&r2=350013&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
Wed Nov 30 10:56:27 2005
@@ -19,7 +19,6 @@
 import java.io.StringWriter;
 import java.security.Principal;
 import java.security.PrivilegedAction;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -27,11 +26,13 @@
 import java.util.Map;
 
 import javax.portlet.PortletConfig;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
 import javax.security.auth.Subject;
-import javax.servlet.jsp.JspException;
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.jetspeed.Jetspeed;
+import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.exception.JetspeedException;
 import org.apache.jetspeed.om.folder.Folder;
 import org.apache.jetspeed.om.folder.FolderNotFoundException;
@@ -39,11 +40,11 @@
 import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.page.PageNotUpdatedException;
 import org.apache.jetspeed.page.document.NodeException;
-import org.apache.jetspeed.pipeline.PipelineException;
 import org.apache.jetspeed.prefs.PreferencesProvider;
 import org.apache.jetspeed.prefs.om.Node;
 import org.apache.jetspeed.profiler.Profiler;
 import org.apache.jetspeed.profiler.rules.ProfilingRule;
+import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.security.GroupManager;
 import org.apache.jetspeed.security.RoleManager;
 import org.apache.jetspeed.security.SecurityHelper;
@@ -55,7 +56,6 @@
 import org.springframework.mail.MailException;
 import org.springframework.mail.SimpleMailMessage;
 import org.springframework.mail.javamail.JavaMailSender;
-import org.apache.taglibs.random.RandomStrg;
 
 /**
  * PortalAdministrationImpl
@@ -82,6 +82,7 @@
     protected Profiler profiler;
     protected JavaMailSender mailSender;
     protected VelocityEngine velocityEngine;
+    protected AdminUtil adminUtil;
     
     /** list of default roles for a registered user */
     protected List defaultRoles;
@@ -91,18 +92,7 @@
     protected Map defaultRules;
     /** name of PSML Folder Template to clone from when registering new user */
     protected String folderTemplate;
-    
-    /** the list of characters from which a password can be generatored. */
-    protected static final char[] PASS_CHARS = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm',
-        'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
-        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
-        'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
-        '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
-        // removed these for aesthetic purposes
-        //'!', '&',  '-', '_', '=',
-        // '*','@', '#', '$', '%', '^',
-        //'+',
-    
+        
     public PortalAdministrationImpl( UserManager userManager,
                                      RoleManager roleManager,
                                      GroupManager groupManager, 
@@ -118,7 +108,8 @@
         this.pageManager = pageManager;
         this.preferences = preferences;
         this.mailSender = mailSender;
-        this.velocityEngine = velocityEngine;                        
+        this.velocityEngine = velocityEngine;
+        this.adminUtil = new AdminUtil();
     }
 
     public void start()
@@ -299,30 +290,7 @@
      */
     public String generatePassword()
     {
-        RandomStrg rs = new RandomStrg();
-        
-        //TODO put in a more secure random number provider
-        //rs.setAlgorithm();   -- ideally call this for super security.  need rnd provider
-        
-        try
-        {
-            rs.generateRandomObject();
-        } catch (JspException e)
-        {
-            // this would only get thrown if we tried a secure random and the provider
-            // was not available.
-            e.printStackTrace();
-        }
-        rs.setLength(new Integer(12));
-        rs.setSingle(PASS_CHARS,PASS_CHARS.length);
-        ArrayList upper = new ArrayList();
-        ArrayList lower = new ArrayList();
-        //upper.add(new Character('A'));
-        //lower.add(new Character('B'));
-        rs.setRanges(upper,lower);
-        String retval = rs.getRandom();
-        
-        return retval;
+        return adminUtil.generatePassword();
     }
 
     /* (non-Javadoc)
@@ -435,4 +403,19 @@
         }
     }
 
+    /**
+     * Helper for admin portlets to generate portal urls
+     */
+    public String getPortalURL(PortletRequest request, PortletResponse response, String path)
+    {
+        // get internal request context
+        RequestContext context = (RequestContext)
+            request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
+        String baseUrl = context.getPortalURL().getBaseURL();
+        String jetspeedPath = adminUtil.concatenatePaths(baseUrl, context.getPortalURL().getBasePath());
+        if (path == null)
+            return jetspeedPath;
+        return adminUtil.concatenatePaths(jetspeedPath, response.encodeURL(path));
+    }
+        
 }

Modified: portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/administration/PortalAdministration.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/administration/PortalAdministration.java?rev=350013&r1=350012&r2=350013&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/administration/PortalAdministration.java
(original)
+++ portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/administration/PortalAdministration.java
Wed Nov 30 10:56:27 2005
@@ -19,6 +19,9 @@
 import java.util.Map;
 
 import javax.portlet.PortletConfig;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+
 import org.apache.jetspeed.security.User;
 
 /**
@@ -100,6 +103,22 @@
     public User lookupUserFromEmail(String email)
     throws AdministrationEmailException;
     
-    
+    /**
+     * Provide a common way to get portal URLs
+     * Necessary for generating return URLs for features such as 
+     * forgotten password. The URL generated will be a combination
+     * of the Jetspeed base URL plus the path parameter appended 
+     * Example:
+     *  base URL = http://www.apache.org/jetspeed/portal
+     *      path = /system/forgotten-password.psml
+     *  Returns: 
+     *     http://www.apache.org/jetspeed/portal/system/forgotten-password.psml
+     *     
+     * @param request The portlet request.
+     * @param response The portlet response, used to encode the path
+     * @param path The relative path to a portal resource
+     * @return the base Jetspeed portal URL plus the appended path parameter
+     */
+    String getPortalURL(PortletRequest request, PortletResponse response, String path);
 }
 



---------------------------------------------------------------------
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