portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r1621403 - in /portals/jetspeed-2/applications/j2-admin/trunk: ./ src/main/java/org/apache/jetspeed/portlets/content/ src/main/java/org/apache/jetspeed/portlets/openid/ src/main/java/org/apache/jetspeed/portlets/sso/ src/test/java/org/apach...
Date Sat, 30 Aug 2014 00:27:31 GMT
Author: woonsan
Date: Sat Aug 30 00:27:30 2014
New Revision: 1621403

URL: http://svn.apache.org/r1621403
Log:
JS2-1302: dependency to webcontent2; making it compilable (removing old api usages; not working
 yet)

Removed:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/DefaultSSOSiteCredentialsProviderImpl.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOTicketPortlet.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/test/java/org/apache/jetspeed/portlets/sso/TestSSOSiteCredentialsProvider.java
Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/pom.xml
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/content/DynamicWebContentPortlet.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/content/DynamicWebContentRewriter.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/openid/OpenIDIFramePortlet.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOIFramePortlet.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOReverseProxyIFramePortlet.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOWebContentPortlet.java

Modified: portals/jetspeed-2/applications/j2-admin/trunk/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/pom.xml?rev=1621403&r1=1621402&r2=1621403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/pom.xml (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/pom.xml Sat Aug 30 00:27:30 2014
@@ -37,7 +37,7 @@
     <org.apache.portals.bridges.frameworks.version>1.0.4</org.apache.portals.bridges.frameworks.version>
     <org.apache.portals.bridges.portletfilter.version>1.0.4</org.apache.portals.bridges.portletfilter.version>
     <org.apache.portals.applications.apa-gems.version>1.2-SNAPSHOT</org.apache.portals.applications.apa-gems.version>
-    <org.apache.portals.applications.apa-webcontent.version>1.4-SNAPSHOT</org.apache.portals.applications.apa-webcontent.version>
+    <org.apache.portals.applications.apa-webcontent2.version>2.0-SNAPSHOT</org.apache.portals.applications.apa-webcontent2.version>
     <commons-digester.version>2.1</commons-digester.version>
     <commons-configuration.version>1.10</commons-configuration.version>
     <commons-lang.version>2.6</commons-lang.version>
@@ -397,14 +397,8 @@
     </dependency>
     <dependency>
       <groupId>org.apache.portals.applications</groupId>
-      <artifactId>apa-webcontent-jar</artifactId>
-      <version>${org.apache.portals.applications.apa-webcontent.version}</version>
-      <exclusions>
-        <exclusion>
-          <groupId>commons-logging</groupId>
-          <artifactId>commons-logging</artifactId>
-        </exclusion>
-      </exclusions>
+      <artifactId>apa-webcontent2-portlets</artifactId>
+      <version>${org.apache.portals.applications.apa-webcontent2.version}</version>
     </dependency>
 	
 	<!-- test dependencies -->

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/content/DynamicWebContentPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/content/DynamicWebContentPortlet.java?rev=1621403&r1=1621402&r2=1621403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/content/DynamicWebContentPortlet.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/content/DynamicWebContentPortlet.java
Sat Aug 30 00:27:30 2014
@@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -27,15 +28,25 @@ import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.PortletException;
 import javax.portlet.PortletMode;
+import javax.portlet.PortletRequest;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.client.methods.HttpGet;
 import org.apache.jetspeed.request.RequestContext;
-import org.apache.portals.applications.webcontent.portlet.WebContentHistoryPage;
-import org.apache.portals.applications.webcontent.portlet.WebContentPortlet;
-import org.apache.portals.applications.webcontent.rewriter.WebContentRewriter;
+import org.apache.portals.applications.webcontent2.portlet.WebContentPortlet;
+import org.apache.portals.applications.webcontent2.portlet.history.WebContentPage;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.MappingRewriterController;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.Rewriter;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.RewriterController;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.RewriterException;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.WebContentRewriter;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.html.neko.NekoParserAdaptor;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Ruleset;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.xml.SaxParserAdaptor;
 import org.apache.portals.messaging.PortletMessaging;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,10 +77,10 @@ public class DynamicWebContentPortlet ex
         // extract rewritten action and save in page
         String webContentURL = actionRequest.getParameter(WebContentRewriter.ACTION_PARAMETER_URL);
         String webContentMethod = actionRequest.getParameter(WebContentRewriter.ACTION_PARAMETER_METHOD);
-        Map webContentParams = new HashMap(actionRequest.getParameterMap()) ;
+        Map<String, String[]> webContentParams = new HashMap(actionRequest.getParameterMap())
;
         webContentParams.remove(WebContentRewriter.ACTION_PARAMETER_URL);
         webContentParams.remove(WebContentRewriter.ACTION_PARAMETER_METHOD);
-        WebContentHistoryPage webContentPage = new WebContentHistoryPage(webContentURL, webContentParams,
webContentMethod);
+        WebContentPage webContentPage = new WebContentPage(webContentURL, webContentMethod,
webContentParams);
         PortletMessaging.publish(actionRequest, getClass().getName(), webContentPage);  
     
     }
     
@@ -92,14 +103,14 @@ public class DynamicWebContentPortlet ex
         // get source web content URL, parameters, and method to view
         String sourceURL = null;
         Map sourceParams = null;
-        boolean sourcePostMethod = false;
-        WebContentHistoryPage webContentPage = (WebContentHistoryPage)PortletMessaging.receive(request,
getClass().getName());
+        String sourceMethod = null;
+        WebContentPage webContentPage = (WebContentPage)PortletMessaging.receive(request,
getClass().getName());
         if (webContentPage != null)
         {
             // view rewritten action URL page
             sourceURL = webContentPage.getUrl();
             sourceParams = webContentPage.getParams();
-            sourcePostMethod = webContentPage.isPost();            
+            sourceMethod = StringUtils.defaultIfBlank(webContentPage.getMethod(), HttpGet.METHOD_NAME);
         }
         else
         {
@@ -135,38 +146,51 @@ public class DynamicWebContentPortlet ex
 
         // get web content
         byte[] content = null;
+
         try
         {
-            // initialize and lock stateful rewriter
-            String basePortalPath = rc.getPortalURL().getPageBasePath();
-            initializeRewriter(DynamicWebContentRewriter.class);
-            ((DynamicWebContentRewriter)getRewriter()).setBasePortalPath(basePortalPath);
-        
             // get and rewrite web content
             if (log.isDebugEnabled())
             {
                 log.debug("Portal request: "+rc.getPath()+", Web content: "+sourceURL);
             }
-            try
-            {
-                content = doWebContent(sourceURL, sourceParams, sourcePostMethod, request,
response);
-            }
-            catch (Throwable t)
-            {
-                throw new PortletException("Error retrieveing web content: "+t, t);
-            }
+
+            content = doWebContent(sourceMethod, sourceURL, sourceParams, request, response);
+
+            // write web content to portlet writer
+            response.setContentType("text/html");
+            PrintWriter writer = response.getWriter();
+            ByteArrayInputStream bais = new ByteArrayInputStream(content);
+            IOUtils.copy(new InputStreamReader(bais, "UTF-8"), writer);
+            bais.close();
         }
-        finally
+        catch (Throwable t)
         {
-            // unlock stateful rewriter
-            freeRewriter();
+            throw new PortletException("Error retrieveing web content: "+t, t);
         }
+    }
+
+    @Override
+    protected RewriterController getRewriterController(String contextPath) throws Exception
+    {
+        Class[] rewriterClasses = new Class[] { DynamicWebContentRewriter.class, DynamicWebContentRewriter.class
};
+        Class[] adaptorClasses = new Class[] { NekoParserAdaptor.class, SaxParserAdaptor.class
};
+        RewriterController rewriterController = 
+                        new MappingRewriterController(contextPath + "conf/rewriter-rules-mapping.xml",

+                                                      Arrays.asList(rewriterClasses),
+                                                      Arrays.asList(adaptorClasses));
+        return rewriterController;
+    }
+
+    @Override
+    protected Rewriter createRewriter(PortletRequest request, RewriterController rewriterController,
Ruleset ruleset) throws RewriterException
+    {
+        RequestContext rc = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV);
+        String basePortalPath = rc.getPortalURL().getPageBasePath();
+
+        DynamicWebContentRewriter rewriter = (DynamicWebContentRewriter) super.createRewriter(request,
rewriterController, ruleset);
+        rewriter.setBasePortalPath(basePortalPath);
 
-        // write web content to portlet writer
-        response.setContentType("text/html");
-        PrintWriter writer = response.getWriter();
-        ByteArrayInputStream bais = new ByteArrayInputStream(content);
-        drain(new InputStreamReader(bais, defaultEncoding), writer);
-        bais.close();
+        return rewriter;
     }
 }

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/content/DynamicWebContentRewriter.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/content/DynamicWebContentRewriter.java?rev=1621403&r1=1621402&r2=1621403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/content/DynamicWebContentRewriter.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/content/DynamicWebContentRewriter.java
Sat Aug 30 00:27:30 2014
@@ -16,14 +16,13 @@
  */
 package org.apache.jetspeed.portlets.content;
 
-import java.util.regex.Pattern;
 import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.portlet.PortletURL;
 
-import org.apache.portals.applications.webcontent.rewriter.MutableAttributes;
-import org.apache.portals.applications.webcontent.rewriter.WebContentRewriter;
-
+import org.apache.portals.applications.webcontent2.portlet.rewriter.MutableAttributes;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.WebContentRewriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/openid/OpenIDIFramePortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/openid/OpenIDIFramePortlet.java?rev=1621403&r1=1621402&r2=1621403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/openid/OpenIDIFramePortlet.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/openid/OpenIDIFramePortlet.java
Sat Aug 30 00:27:30 2014
@@ -27,10 +27,7 @@ import javax.security.auth.Subject;
 
 import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.request.RequestContext;
-import org.apache.portals.applications.webcontent.portlet.IFrameGenericPortlet;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.portals.applications.webcontent2.portlet.IFrameGenericPortlet;
 
 /**
  * IFrame portlet variant that loads content only when the portal
@@ -41,7 +38,6 @@ import org.slf4j.LoggerFactory;
  */
 public class OpenIDIFramePortlet extends IFrameGenericPortlet
 {
-    private static final Logger log = LoggerFactory.getLogger(OpenIDLoginPortlet.class);
 
     public static final String SESSION_OPEN_ID_PROVIDER_ATTR_NAME = "sessionOpenIDProvider";
     public static final String REQUIRED_OPEN_ID_PROVIDER_ATTR_NAME = "requiredOpenIDProvider";

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOIFramePortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOIFramePortlet.java?rev=1621403&r1=1621402&r2=1621403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOIFramePortlet.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOIFramePortlet.java
Sat Aug 30 00:27:30 2014
@@ -38,7 +38,7 @@ import org.apache.jetspeed.sso.SSOManage
 import org.apache.jetspeed.sso.SSOSite;
 import org.apache.jetspeed.sso.SSOUser;
 import org.apache.portals.applications.gems.browser.StatusMessage;
-import org.apache.portals.applications.webcontent.portlet.IFrameGenericPortlet;
+import org.apache.portals.applications.webcontent2.portlet.IFrameGenericPortlet;
 import org.apache.portals.messaging.PortletMessaging;
 
 /**

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOReverseProxyIFramePortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOReverseProxyIFramePortlet.java?rev=1621403&r1=1621402&r2=1621403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOReverseProxyIFramePortlet.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOReverseProxyIFramePortlet.java
Sat Aug 30 00:27:30 2014
@@ -16,30 +16,20 @@
  */
 package org.apache.jetspeed.portlets.sso;
 
-import java.io.IOException;
 import java.net.URI;
 import java.security.AccessController;
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
 
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletException;
-import javax.portlet.PortletSession;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
 import javax.security.auth.Subject;
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.jetspeed.security.JSSubject;
 import org.apache.jetspeed.security.PasswordCredential;
 import org.apache.jetspeed.sso.SSOManager;
 import org.apache.jetspeed.sso.SSOSite;
 import org.apache.jetspeed.sso.SSOUser;
-import org.apache.portals.applications.webcontent.portlet.IFrameGenericPortlet;
-import org.apache.portals.applications.webcontent.proxy.HttpReverseProxyConstants;
-import org.apache.portals.applications.webcontent.proxy.SSOSiteCredentials;
-import org.apache.portals.applications.webcontent.proxy.impl.DefaultSSOSiteCredentials;
+import org.apache.portals.applications.webcontent2.portlet.IFrameGenericPortlet;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -68,60 +58,34 @@ public class SSOReverseProxyIFramePortle
             throw new PortletException("Failed to find SSO Provider on portlet initialization");

         }
     }
-    
-    @Override
-    public void doView(RenderRequest request, RenderResponse response) throws PortletException,
IOException
-    {
-        List<SSOSiteCredentials> ssoSiteCredsOfSubject = (List<SSOSiteCredentials>)
request.getPortletSession().getAttribute(SUBJECT_SSO_SITE_CREDS, PortletSession.APPLICATION_SCOPE);
-        
-        if (ssoSiteCredsOfSubject == null)
-        {
-            request.getPortletSession().setAttribute(SUBJECT_SSO_SITE_CREDS, createSSOSiteCredentialsOfSubject(),
PortletSession.APPLICATION_SCOPE);
-            request.getPortletSession().setAttribute(HttpReverseProxyConstants.SSO_SITE_CREDENTIALS_PROVIDER,
new DefaultSSOSiteCredentialsProviderImpl(), PortletSession.APPLICATION_SCOPE);
-        }
-        
-        super.doView(request, response);
-    }
-    
-    private List<SSOSiteCredentials> createSSOSiteCredentialsOfSubject()
+
+    // TODO
+    private void readSSOSiteCredentialsOfSubject()
     {
-        List<SSOSiteCredentials> ssoSiteCredsOfSubject = new ArrayList<SSOSiteCredentials>();
-            
         try
         {
             Subject subject = JSSubject.getSubject(AccessController.getContext());
             Collection<SSOSite> ssoSites = ssoManager.getSitesForSubject(subject);
-            
+
             if (ssoSites != null)
             {
                 for (SSOSite ssoSite : ssoSites)
                 {
                     URI siteURI = URI.create(ssoSite.getURL());
                     Collection<SSOUser> ssoUsers = ssoManager.getRemoteUsers(ssoSite,
subject);
-                    
+
                     if (ssoUsers != null)
                     {
                         for (SSOUser ssoUser : ssoUsers)
                         {
-                            DefaultSSOSiteCredentials ssoCreds = new DefaultSSOSiteCredentials(ssoSite.getURL(),
siteURI.getHost(), siteURI.getPort());
-                            
-                            if (!StringUtils.isBlank(ssoSite.getRealm()))
-                            {
-                                ssoCreds.setRealm(ssoSite.getRealm());
-                            }
-                            
+                            String realm = ssoSite.getRealm();
                             PasswordCredential pwc = ssoManager.getCredentials(ssoUser);
-                            ssoCreds.setUsername(pwc.getUserName());
-                            ssoCreds.setPassword(pwc.getPassword());
-                            
+                            String username = pwc.getUserName();
+                            String password = pwc.getPassword();
+
                             if (ssoSite.isFormAuthentication())
                             {
-                                ssoCreds.setFormAuthentication(true);
-                                ssoCreds.setFormUserField(ssoSite.getFormUserField());
-                                ssoCreds.setFormPwdField(ssoSite.getFormPwdField());
                             }
-                            
-                            ssoSiteCredsOfSubject.add(ssoCreds);
                         }
                     }
                 }
@@ -134,8 +98,5 @@ public class SSOReverseProxyIFramePortle
                 log.warn("Failed to retrieve sso site credentials. {}", e.toString());
             }
         }
-        
-        return ssoSiteCredsOfSubject;
     }
-    
 }

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOWebContentPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOWebContentPortlet.java?rev=1621403&r1=1621402&r2=1621403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOWebContentPortlet.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/sso/SSOWebContentPortlet.java
Sat Aug 30 00:27:30 2014
@@ -17,12 +17,8 @@
 package org.apache.jetspeed.portlets.sso;
 
 import java.io.IOException;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.StringTokenizer;
 
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
@@ -33,19 +29,9 @@ import javax.portlet.PortletMode;
 import javax.portlet.PortletPreferences;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
-import javax.security.auth.Subject;
 
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.auth.AuthScope;
-import org.apache.commons.httpclient.auth.AuthState;
 import org.apache.commons.httpclient.auth.BasicScheme;
-import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.jetspeed.CommonPortletServices;
-import org.apache.jetspeed.security.JSSubject;
 import org.apache.jetspeed.security.JetspeedPrincipal;
 import org.apache.jetspeed.security.PasswordCredential;
 import org.apache.jetspeed.security.SecurityException;
@@ -55,8 +41,8 @@ import org.apache.jetspeed.sso.SSOExcept
 import org.apache.jetspeed.sso.SSOManager;
 import org.apache.jetspeed.sso.SSOSite;
 import org.apache.portals.applications.gems.browser.StatusMessage;
-import org.apache.portals.applications.webcontent.portlet.WebContentPortlet;
-import org.apache.portals.applications.webcontent.rewriter.WebContentRewriter;
+import org.apache.portals.applications.webcontent2.portlet.WebContentPortlet;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.WebContentRewriter;
 import org.apache.portals.messaging.PortletMessaging;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -66,30 +52,29 @@ import org.slf4j.LoggerFactory;
  * SSOWebContentPortlet
  * 
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
- * @version $Id$
  */
 public class SSOWebContentPortlet extends WebContentPortlet
 {
     // sso.type
     public static final String SSO_TYPE = "sso.type";
-    
-    public static final String SSO_TYPE_HTTP = "http";                          // BOZO -
depricate in favor of 'basic'
-    public static final String SSO_TYPE_BASIC = "basic";          
+
+    public static final String SSO_TYPE_HTTP = "http";
+    public static final String SSO_TYPE_BASIC = "basic";
     public static final String SSO_TYPE_BASIC_PREEMPTIVE = "basic.preemptive";
-    
+
     public static final String SSO_TYPE_FORM = "form";
     public static final String SSO_TYPE_FORM_GET = "form.get";
     public static final String SSO_TYPE_FORM_POST = "form.post";
-    
+
     public static final String SSO_TYPE_URL = "url";
     public static final String SSO_TYPE_URL_BASE64 = "url.base64";
-    
+
     public static final String SSO_TYPE_CERTIFICATE = "certificate";
-    
+
     public static final String SSO_TYPE_DEFAULT = SSO_TYPE_BASIC;  // handled well even if
nothing but credentials are set (see: doRequestedAuthentication)
-    
+
     public static final String NO_CREDENTIALS = "<p>No credentials configured for current
user.</p>";
-    		
+
     public static final String[] SSO_TYPES = 
     {
         SSO_TYPE_BASIC,
@@ -101,412 +86,225 @@ public class SSOWebContentPortlet extend
         SSO_TYPE_URL_BASE64,
         SSO_TYPE_CERTIFICATE
     };
-    
+
     // ...standardized auth types
-    
+
     public static final String BASIC_AUTH_SCHEME_NAME = (new BasicScheme()).getSchemeName();
 
     // supporting parameters - for various sso types
-    
+
     // ...names of query args for sso.type=url|url.base64
-    
+
     public static final String SSO_TYPE_URL_USERNAME_PARAM = "sso.url.Principal";
     public static final String SSO_TYPE_URL_PASSWORD_PARAM = "sso.url.Credential";
-    
+
     // ...names of fields for sso.type=form|form.get|form.post
-    
+
     public static final String SSO_TYPE_FORM_ACTION_URL = "sso.form.Action";
     public static final String SSO_TYPE_FORM_ACTION_ARGS = "sso.form.Args";
     public static final String SSO_TYPE_FORM_USERNAME_FIELD = "sso.form.Principal";
     public static final String SSO_TYPE_FORM_PASSWORD_FIELD = "sso.form.Credential";
-    
+
     // ...tags for passing creditials along on the current request object
-    
+
     public static final String SSO_REQUEST_ATTRIBUTE_USERNAME = "sso.ra.username";
     public static final String SSO_REQUEST_ATTRIBUTE_PASSWORD = "sso.ra.password";
-    
+
     // ...field names for EDIT mode
-    
+
     public static final String SSO_EDIT_FIELD_PRINCIPAL = "ssoPrincipal";
     public static final String SSO_EDIT_FIELD_CREDENTIAL = "ssoCredential";
-    
+
     // SSOWebContent session variables 
 
     public static final String FORM_AUTH_STATE = "ssowebcontent.form.authstate" ;
-    
-    
+
     // Class Data
-    
+
     protected final static Logger log = LoggerFactory.getLogger(SSOWebContentPortlet.class);
-    
-    
+
     // Data Members
-    
+
     protected PortletContext context;
     protected SSOManager sso;
     protected UserManager userManager;
     protected List<String> ssoTypesList;
-    
+
     // Methods
 
     public void init(PortletConfig config) throws PortletException
     {
         super.init(config);
+
         context = getPortletContext();
-        sso = (SSOManager)context.getAttribute("cps:SSO");
-        if (null == sso)
+
+        sso = (SSOManager) context.getAttribute("cps:SSO");
+
+        if (sso == null)
         {
            throw new PortletException("Failed to find SSO Manager on portlet initialization");
-        }        
+        }
+
         userManager = (UserManager) context.getAttribute(CommonPortletServices.CPS_USER_MANAGER_COMPONENT);
+
         if (null == userManager)
         {
             throw new PortletException("Failed to find the User Manager on portlet initialization");
         }
+
         ssoTypesList = new LinkedList<String>();
+
         for (String s : SSO_TYPES)
+        {
             ssoTypesList.add(s);
+        }
     }
-    
-    protected JetspeedPrincipal getLocalPrincipal(String localUserName){
+
+    protected JetspeedPrincipal getLocalPrincipal(String localUserName) {
         JetspeedPrincipal localPrincipal = null;
-        
+
         try{
             localPrincipal = userManager.getUser(localUserName);
         } catch (SecurityException secex){
-            
         }
-        
+
         return localPrincipal;
     }
-    
-    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
-    throws PortletException, IOException
+
+    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
throws PortletException, IOException
     {
         // grab parameters - they will be cleared in processing of edit response
         String webContentParameter = actionRequest.getParameter(WebContentRewriter.ACTION_PARAMETER_URL);
         String ssoPrincipalName = actionRequest.getParameter(SSO_EDIT_FIELD_PRINCIPAL);
-        String ssoPrincipalPassword = actionRequest.getParameter(SSO_EDIT_FIELD_CREDENTIAL);
       
+        String ssoPrincipalPassword = actionRequest.getParameter(SSO_EDIT_FIELD_CREDENTIAL);
 
         // save the prefs
         super.processAction(actionRequest, actionResponse);
-  
+
         // process credentials
-        if (webContentParameter == null || actionRequest.getPortletMode() == PortletMode.EDIT)
           
+        if (webContentParameter == null || actionRequest.getPortletMode() == PortletMode.EDIT)
         {
             // processPreferencesAction(request, actionResponse);
             // get the POST params -- requires HTML post params named above 
             String siteUrl = actionRequest.getPreferences().getValue("SRC", "");
             String localUser = actionRequest.getUserPrincipal().getName();
             SSOSite site = sso.getSiteByUrl(siteUrl);
+
             try
-            {        
+            {
                 if (!SecurityHelper.isEmpty(siteUrl) && !SecurityHelper.isEmpty(ssoPrincipalName)
&& !SecurityHelper.isEmpty(ssoPrincipalPassword))
                 {
                     if (site == null)
                     {
                         site = sso.newSite(siteUrl, siteUrl);
                         sso.addSite(site);
-                        SSOPortletUtil.updateUser(sso, actionRequest, site, ssoPrincipalName,
ssoPrincipalPassword);                                                
+                        SSOPortletUtil.updateUser(sso, actionRequest, site, ssoPrincipalName,
ssoPrincipalPassword);
                     }
                     else
                     {
-                        SSOPortletUtil.updateUser(sso, actionRequest, site, ssoPrincipalName,
ssoPrincipalPassword);                                
+                        SSOPortletUtil.updateUser(sso, actionRequest, site, ssoPrincipalName,
ssoPrincipalPassword);
                     }
                 }
             }
             catch (SSOException e)
             {
                 String errorMessage = "Failed to add remote user for the portal principal,
" + actionRequest.getUserPrincipal().getName() + ".";
+
                 if (e.getCause() != null)
                 {
                     errorMessage += " (" + e.getCause() + ")";
                 }
+
                 StatusMessage statusMessage = new StatusMessage(errorMessage, StatusMessage.ERROR);
-                PortletMessaging.publish(actionRequest, "SSOWebContent", "status", statusMessage);
           
-                actionResponse.setPortletMode(PortletMode.EDIT); // stay on edit        
       
-            }                
+                PortletMessaging.publish(actionRequest, "SSOWebContent", "status", statusMessage);
+                actionResponse.setPortletMode(PortletMode.EDIT); // stay on edit
+            }
         }
     }
-        
-    public void doView(RenderRequest request, RenderResponse response)
-    throws PortletException, IOException
+
+    public void doView(RenderRequest request, RenderResponse response) throws PortletException,
IOException
     {
         String siteName = request.getPreferences().getValue("SRC", null);
         SSOSite site = null;
+
         if (siteName != null)
         {
             site = sso.getSiteByUrl(siteName);
         }
+
         if (site == null)
         {
             response.getWriter().print(NO_CREDENTIALS);
             return;
         }
-        else 
+        else
         {
-        	PasswordCredential pwc = SSOPortletUtil.getCredentialsForSite(sso,siteName,request);
-        	if (pwc != null)
-        	{
+            PasswordCredential pwc = SSOPortletUtil.getCredentialsForSite(sso,siteName,request);
+
+            if (pwc != null)
+            {
                 request.setAttribute(SSO_REQUEST_ATTRIBUTE_USERNAME, pwc.getUserName());
                 request.setAttribute(SSO_REQUEST_ATTRIBUTE_PASSWORD, pwc.getPassword());
-        	} else 
-        	{
+            }
+            else
+            {
                 response.getWriter().print(NO_CREDENTIALS);
                 return;
-        	}
+            }
         }
-        StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, "SSOWebContent",
"status");
+
+        StatusMessage msg = (StatusMessage) PortletMessaging.consume(request, "SSOWebContent",
"status");
+
         if (msg != null)
         {
-            this.getContext(request).put("statusMsg", msg);            
-        }                          
+            this.getContext(request).put("statusMsg", msg);
+        }
+
         super.doView(request, response);
     }
-    
 
-    public void doEdit(RenderRequest request, RenderResponse response)
-    throws PortletException, IOException
+    public void doEdit(RenderRequest request, RenderResponse response) throws PortletException,
IOException
     {
         String site = request.getPreferences().getValue("SRC", "");
-    	PasswordCredential pwc = SSOPortletUtil.getCredentialsForSite(sso,site,request);
-    	if (pwc != null)
-    	{
+        PasswordCredential pwc = SSOPortletUtil.getCredentialsForSite(sso,site,request);
+
+        if (pwc != null)
+        {
             getContext(request).put(SSO_EDIT_FIELD_PRINCIPAL, pwc.getUserName());
             getContext(request).put(SSO_EDIT_FIELD_CREDENTIAL, pwc.getPassword());
-        } 
-    	else 
-    	{
+        }
+        	else
+        {
             // no credentials configured in SSO store
             // switch to SSO Configure View
             getContext(request).put(SSO_EDIT_FIELD_PRINCIPAL, "");
             getContext(request).put(SSO_EDIT_FIELD_CREDENTIAL, "");
         }
+
         StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, "SSOWebContent",
"status");
-        if (msg != null)
-        {
-            this.getContext(request).put("statusMsg", msg);            
-        }     
-        this.getContext(request).put("ssoTypes", SSO_TYPES);
-        this.getContext(request).put("ssoTypeSelected", request.getPreferences().getValue("sso.type",
SSO_TYPE_BASIC));
-        super.doEdit(request, response);
-    }
 
-    private Subject getSubject()
-    {
-        AccessControlContext context = AccessController.getContext();
-        return JSSubject.getSubject(context);         
-    }
-    
-    protected byte[] doPreemptiveAuthentication(HttpClient client,HttpMethod method, RenderRequest
request, RenderResponse response)
-    {
-    	byte[] result = super.doPreemptiveAuthentication(client, method, request, response);
-        if ( result != null)
+        if (msg != null)
         {
-            // already handled
-            return result ;
+            this.getContext(request).put("statusMsg", msg);
         }
-        
-        // System.out.println("SSOWebContentPortlet.doPreemptiveAuthentication...");
-        
-        PortletPreferences prefs = request.getPreferences();
-        String type = getSingleSignOnAuthType(prefs);
-
-        if (type.equalsIgnoreCase(SSO_TYPE_BASIC_PREEMPTIVE))
-        {
-            // Preemptive, basic authentication
-            String userName = (String)request.getAttribute(SSO_REQUEST_ATTRIBUTE_USERNAME);
-            if (userName == null) userName = "";
-            String password = (String)request.getAttribute(SSO_REQUEST_ATTRIBUTE_PASSWORD);
-            if (password == null) password = "";
-            
-            // System.out.println("...performing preemptive basic authentication with userName:
"+userName+", and password: "+password);
-            method.setDoAuthentication(true);
-            method.getHostAuthState().setPreemptive();
-            client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName,
password));
-            
-            // handled!
-            return result ;
-            
-        }
-        else if (type.startsWith(SSO_TYPE_FORM))
-        {
-            try
-            {
-                Boolean formAuth = (Boolean)PortletMessaging.receive(request, FORM_AUTH_STATE);
-                if (formAuth != null)
-                {
-                    // already been here, done that
-                    return (formAuth.booleanValue() ? result : null);
-                }
-                else
-                {
-                    // stop recursion, but assume failure, ...for now
-                    PortletMessaging.publish(request, FORM_AUTH_STATE, Boolean.FALSE);
-                }
 
-                String formAction = prefs.getValue(SSO_TYPE_FORM_ACTION_URL, "");
-                if (formAction == null || formAction.length() == 0)
-                {
-                    log.warn("sso.type specified as 'form', but no: "+SSO_TYPE_FORM_ACTION_URL+",
action was specified - unable to preemptively authenticate by form.");
-                    return null ;
-                }
-                String userNameField = prefs.getValue(SSO_TYPE_FORM_USERNAME_FIELD, "");
-                if (userNameField == null || userNameField.length() == 0)
-                {
-                    log.warn("sso.type specified as 'form', but no: "+SSO_TYPE_FORM_USERNAME_FIELD+",
username field was specified - unable to preemptively authenticate by form.");
-                    return null ;
-                }
-                String passwordField = prefs.getValue(SSO_TYPE_FORM_PASSWORD_FIELD, "password");
-                if (passwordField == null || passwordField.length() == 0)
-                {
-                    log.warn("sso.type specified as 'form', but no: "+SSO_TYPE_FORM_PASSWORD_FIELD+",
password field was specified - unable to preemptively authenticate by form.");
-                    return null ;
-                }
-                
-                String userName = (String)request.getAttribute(SSO_REQUEST_ATTRIBUTE_USERNAME);
-                if (userName == null) userName = "";
-                String password = (String)request.getAttribute(SSO_REQUEST_ATTRIBUTE_PASSWORD);
-                if (password == null) password = "";
-
-                // get submit method
-                int i = type.indexOf('.');
-                boolean isPost = i > 0 ? type.substring(i+1).equalsIgnoreCase("post")
: true ;    // default to post, since it is a form 
-            
-                // get parameter map
-                HashMap formParams = new HashMap();
-                formParams.put(userNameField,new String[]{ userName });
-                formParams.put(passwordField,new String[]{ password });
-                String formArgs = prefs.getValue(SSO_TYPE_FORM_ACTION_ARGS, "");
-                if (formArgs != null && formArgs.length() > 0)
-                {
-                    StringTokenizer iter = new StringTokenizer(formArgs, ";");
-                    while (iter.hasMoreTokens())
-                    {
-                        String pair = iter.nextToken();
-                        i = pair.indexOf('=') ;
-                        if (i > 0)
-                            formParams.put(pair.substring(0,i), new String[]{pair.substring(i+1)});
-                    }
-                }
+        this.getContext(request).put("ssoTypes", SSO_TYPES);
+        this.getContext(request).put("ssoTypeSelected", request.getPreferences().getValue("sso.type",
SSO_TYPE_BASIC));
 
-                // resuse client - in case new cookies get set - but create a new method
(for the formAction)
-                String formMethod = (isPost) ? FORM_POST_METHOD : FORM_GET_METHOD;      
         
-                method = getHttpMethod(client, getURLSource(formAction, formParams, request,
response), formParams, formMethod, request);
-                // System.out.println("...posting credentials");
-                result = doHttpWebContent(client, method, 0, request, response) ;
-                // System.out.println("Result of attempted authorization: "+success);
-                PortletMessaging.publish(request, FORM_AUTH_STATE, Boolean.valueOf(result
!= null));
-                return result ;
-            }
-            catch (Exception ex)
-            {
-                // bad
-                log.error("Form-based authentication failed", ex);
-            }
-        }
-        else if (type.equalsIgnoreCase(SSO_TYPE_URL) || type.equalsIgnoreCase(SSO_TYPE_URL_BASE64))
-        {
-            // set user name and password parameters in the HttpMethod
-            String userNameParam = prefs.getValue(SSO_TYPE_URL_USERNAME_PARAM, "");
-            if (userNameParam == null || userNameParam.length() == 0)
-            {
-                log.warn("sso.type specified as 'url', but no: "+SSO_TYPE_URL_USERNAME_PARAM+",
username parameter was specified - unable to preemptively authenticate by URL.");
-                return null ;
-            }
-            String passwordParam = prefs.getValue(SSO_TYPE_URL_PASSWORD_PARAM, "");
-            if (passwordParam == null || passwordParam.length() == 0)
-            {
-                log.warn("sso.type specified as 'url', but no: "+SSO_TYPE_URL_PASSWORD_PARAM+",
password parameter was specified - unable to preemptively authenticate by URL.");
-                return null ;
-            }
-            String userName = (String)request.getAttribute(SSO_REQUEST_ATTRIBUTE_USERNAME);
-            if (userName == null) userName = "";
-            String password = (String)request.getAttribute(SSO_REQUEST_ATTRIBUTE_PASSWORD);
-            if (password == null) password = "";
-            if (type.equalsIgnoreCase(SSO_TYPE_URL_BASE64))
-            {
-                Base64 encoder = new Base64() ;
-                userName = new String(encoder.encode(userName.getBytes()));
-                password = new String(encoder.encode(password.getBytes()));
-            }
-            
-            // GET and POST accept args differently
-            if ( method instanceof PostMethod )
-            {
-                // add POST data
-                PostMethod postMethod = (PostMethod)method ;
-                postMethod.addParameter(userNameParam, userName);
-                postMethod.addParameter(passwordParam, password);
-            }
-            else
-            {
-                // augment GET query string
-                NameValuePair[] authPairs = new NameValuePair[]{ new NameValuePair(userNameParam,
userName), new NameValuePair(passwordParam, password) } ; 
-                String existingQuery = method.getQueryString() ;
-                method.setQueryString(authPairs);
-                if (existingQuery != null && existingQuery.length() > 0)
-                {
-                    // augment existing query with new auth query
-                    existingQuery = existingQuery + '&' + method.getQueryString();
-                    method.setQueryString(existingQuery);
-                }
-            }
-            
-            return result ;
-        }
-        // else System.out.println("...sso.type: "+type+", no pre-emptive authentication");
-        
-        // not handled
-        return null ;
+        super.doEdit(request, response);
     }
 
-    protected boolean doRequestedAuthentication(HttpClient client,HttpMethod method, RenderRequest
request, RenderResponse response)
-    {
-        if ( super.doRequestedAuthentication(client, method, request, response))
-        {
-            // already handled
-            return true ;
-        }
-        
-        // System.out.println("SSOWebContentPortlet.doRequestedAuthentication...");
-        
-        if (method.getHostAuthState().getAuthScheme().getSchemeName().equals(BASIC_AUTH_SCHEME_NAME))
-        {
-            // Basic authentication being requested
-            String userName = (String)request.getAttribute(SSO_REQUEST_ATTRIBUTE_USERNAME);
-            if (userName == null) userName = "";
-            String password = (String)request.getAttribute(SSO_REQUEST_ATTRIBUTE_PASSWORD);
-            if (password == null) password = "";
-            
-            // System.out.println("...providing basic authentication with userName: "+userName+",
and password: "+password);
-            method.setDoAuthentication(true);
-            AuthState state = method.getHostAuthState();
-            AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, state.getRealm(),
state.getAuthScheme().getSchemeName()) ;
-            client.getState().setCredentials(scope, new UsernamePasswordCredentials(userName,
password));
-            
-            // handled!
-            return true ;
-        }
-        else
-        {
-            log.warn("SSOWebContentPortlent.doAuthenticate() - unexpected authentication
scheme: "+method.getHostAuthState().getAuthScheme().getSchemeName());
-        }
-
-        // only know how to handle Basic authentication, in this context
-        return false;
-    }
-    
     protected String getSingleSignOnAuthType(PortletPreferences prefs)
     {
         String type = prefs.getValue(SSO_TYPE,SSO_TYPE_DEFAULT);
-        
+
         if (type != null && type.equalsIgnoreCase(SSO_TYPE_HTTP))
         {
             log.warn("sso.type: "+SSO_TYPE_HTTP+", has been deprecated - use: "+SSO_TYPE_BASIC+",
or: "+SSO_TYPE_BASIC_PREEMPTIVE);
-            type = SSO_TYPE_BASIC ;
+            type = SSO_TYPE_BASIC;
         }
-        
-        return type ;
+
+        return type;
     }
+
 }



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