portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed-2/components/web-content/src/java/org/apache/jetspeed/portlet/webcontent WebContentResource.java
Date Fri, 03 Dec 2004 02:06:05 GMT
taylor      2004/12/02 18:06:05

  Modified:    components/web-content/src/java/org/apache/jetspeed/portlet
                        WebContentPortlet.java
  Added:       components/web-content/src/java/org/apache/jetspeed/portlet
                        SSOWebContentPortlet.java
               components/web-content/src/java/org/apache/jetspeed/portlet/webcontent
                        WebContentResource.java
  Log:
  SSO + WebContent
  still working on a cache
  
  Revision  Changes    Path
  1.6       +9 -3      jakarta-jetspeed-2/components/web-content/src/java/org/apache/jetspeed/portlet/WebContentPortlet.java
  
  Index: WebContentPortlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/web-content/src/java/org/apache/jetspeed/portlet/WebContentPortlet.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WebContentPortlet.java	2 Dec 2004 22:57:33 -0000	1.5
  +++ WebContentPortlet.java	3 Dec 2004 02:06:05 -0000	1.6
  @@ -294,8 +294,9 @@
               String baseurl = baseURL.getProtocol() + "://" + baseURL.getHost();
   
               rewriter.setBaseUrl(baseurl);
  -
  -            rewriter.rewrite(rewriteController.createParserAdaptor("text/html"), getRemoteReader(sourceAttr),
htmlWriter);
  +            String source = getURLSource(sourceAttr, request, response);
  +            System.out.println("Rewriting SOURCE: " + source);
  +            rewriter.rewrite(rewriteController.createParserAdaptor("text/html"), getRemoteReader(source),
htmlWriter);
               htmlWriter.flush();
               
           }
  @@ -317,6 +318,11 @@
           return byteOutputStream.toByteArray();
       }
   
  +    public String getURLSource(String source, RenderRequest request, RenderResponse response)
  +    {
  +        return source;    
  +    }
  +    
       /*
        * Get WebContent source preference value
        */
  
  
  
  1.1                  jakarta-jetspeed-2/components/web-content/src/java/org/apache/jetspeed/portlet/SSOWebContentPortlet.java
  
  Index: SSOWebContentPortlet.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.portlet;
  
  import java.io.IOException;
  import java.security.AccessControlContext;
  import java.security.AccessController;
  
  import javax.portlet.ActionRequest;
  import javax.portlet.ActionResponse;
  import javax.portlet.PortletConfig;
  import javax.portlet.PortletContext;
  import javax.portlet.PortletException;
  import javax.portlet.PortletMode;
  import javax.portlet.PortletPreferences;
  import javax.portlet.RenderRequest;
  import javax.portlet.RenderResponse;
  import javax.security.auth.Subject;
  
  import org.apache.jetspeed.sso.SSOContext;
  import org.apache.jetspeed.sso.SSOException;
  import org.apache.jetspeed.sso.SSOProvider;
  
  
  /**
   * SSOWebContentPortlet
   * 
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: SSOWebContentPortlet.java,v 1.1 2004/12/03 02:06:05 taylor Exp $
   */
  public class SSOWebContentPortlet extends WebContentPortlet
  {
      public static final String SSO_TYPE = "sso.type";
      public static final String SSO_TYPE_URL = "url";
      public static final String SSO_TYPE_URL_BASE64 = "url.base64";
      public static final String SSO_TYPE_HTTP = "http";
      public static final String SSO_TYPE_CERTIFICATE = "certificate";
      
      public static final String SSO_TYPE_URL_USERNAME = "sso.url.Principal";
      public static final String SSO_TYPE_URL_PASSWORD = "sso.url.Credential";
      
      public static final String SSO_REQUEST_ATTRIBUTE_USERNAME = "sso.ra.username";
      public static final String SSO_REQUEST_ATTRIBUTE_PASSWORD = "sso.ra.password";
  
      /*
       * The constants must be used in your HTML form for the SSO principal and credential
       */
      public static final String SSO_FORM_PRINCIPAL = "ssoPrincipal";
      public static final String SSO_FORM_CREDENTIAL = "ssoCredential";
      
      private PortletContext context;
      private SSOProvider sso;
  
      public void init(PortletConfig config) throws PortletException
      {
          super.init(config);
          context = getPortletContext();
          sso = (SSOProvider)context.getAttribute("cps:SSO");
          if (null == sso)
          {
             throw new PortletException("Failed to find SSO Provider on portlet initialization");
          }        
      }
      
      public void processAction(ActionRequest request, ActionResponse actionResponse)
      throws PortletException, IOException
      {
          // save the prefs
          super.processAction(request, actionResponse);
          
          if (request.getPortletMode() == PortletMode.EDIT)
          {
          
              // get the POST params -- requires HTML post params named
              // ssoUserName 
              String ssoPrincipal = request.getParameter(SSO_FORM_PRINCIPAL);
              String ssoCredential = request.getParameter(SSO_FORM_CREDENTIAL);        
              /*
              if (ssoPrincipal == null || ssoCredential == null)
              {
                  
                  actionResponse.setPortletMode(PortletMode.EDIT); // stay on edit
              }
              */
              String site = request.getPreferences().getValue("SRC", "");
              try
              {
                  Subject subject = getSubject();
                  if (sso.hasSSOCredentials(subject, site))
                  {
                      sso.updateCredentialsForSite(getSubject(), ssoPrincipal, site, ssoCredential);
                  }
                  else
                  {
                      sso.addCredentialsForSite(getSubject(), ssoPrincipal, site, ssoCredential);
                  }
              }
              catch (SSOException e)
              {
                  throw new PortletException(e);
              }
          }
      }
      
      public void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException
      {
          String site = request.getPreferences().getValue("SRC", null);
          if (site == null)
          {
              // no credentials configured in SSO store
              // switch to SSO Configure View
              request.setAttribute(PARAM_VIEW_PAGE, this.getPortletConfig().getInitParameter(PARAM_EDIT_PAGE));
              setupPreferencesEdit(request, response);
              super.doView(request, response);
              return;
          }
          
          try
          {
              Subject subject = getSubject();                 
              SSOContext context = sso.getCredentials(subject, site);
              request.setAttribute(SSO_REQUEST_ATTRIBUTE_USERNAME, context.getUserName());
              request.setAttribute(SSO_REQUEST_ATTRIBUTE_PASSWORD, context.getPassword());
          }
          catch (SSOException e)
          {
              if (e.getMessage().equals(SSOException.NO_CREDENTIALS_FOR_SITE))
              {
                  // no credentials configured in SSO store
                  // switch to SSO Configure View
                  request.setAttribute(PARAM_VIEW_PAGE, this.getPortletConfig().getInitParameter(PARAM_EDIT_PAGE));
                  setupPreferencesEdit(request, response);                
              }
              else
              {
                  throw new PortletException(e);
              }
          }        
          
          super.doView(request, response);
      }
      
  
      public void doEdit(RenderRequest request, RenderResponse response)
      throws PortletException, IOException
      {
          try
          {
              Subject subject = getSubject();                 
              String site = request.getPreferences().getValue("SRC", "");
              SSOContext context = sso.getCredentials(subject, site);
              getContext(request).put(SSO_FORM_PRINCIPAL, context.getUserName());
              getContext(request).put(SSO_FORM_CREDENTIAL, context.getPassword());
          }
          catch (SSOException e)
          {
              if (e.getMessage().equals(SSOException.NO_CREDENTIALS_FOR_SITE))
              {
                  // no credentials configured in SSO store
                  // switch to SSO Configure View
                  getContext(request).put(SSO_FORM_PRINCIPAL, "");
                  getContext(request).put(SSO_FORM_CREDENTIAL, "");
              }
              else
              {
                  throw new PortletException(e);
              }
          }        
          
          super.doEdit(request, response);
      }
  
      private Subject getSubject()
      {
          AccessControlContext context = AccessController.getContext();
          return Subject.getSubject(context);         
      }
      
      public String getURLSource(String src, RenderRequest request, RenderResponse response)
      {
          PortletPreferences prefs = request.getPreferences();
          String baseSource = super.getURLSource(src, request, response);
          String type = prefs.getValue(SSO_TYPE, SSO_TYPE_URL);
          if (type.equals(SSO_TYPE_URL))
          {
              String userNameParam = prefs.getValue(SSO_TYPE_URL_USERNAME, "user");
              String passwordParam = prefs.getValue(SSO_TYPE_URL_PASSWORD, "password");
              StringBuffer source = new StringBuffer(baseSource);
              if (baseSource.indexOf("?") == -1)
              {
                  source.append("?");
              }            
              else
              {
                  source.append("&");
              }
              source.append(userNameParam);
              source.append("=");
              
              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 = "";
              
              source.append(userName);
              source.append("&");
              source.append(passwordParam);
              source.append("=");
              source.append(password);
              
              return response.encodeURL(source.toString());
          }
          else
          {
              return baseSource;
          }
      }
      
  }
  
  
  
  1.1                  jakarta-jetspeed-2/components/web-content/src/java/org/apache/jetspeed/portlet/webcontent/WebContentResource.java
  
  Index: WebContentResource.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.jetspeed.portlet.webcontent;
  
  import java.io.Serializable;
  
  import org.apache.commons.httpclient.Cookie;
  
  /**
   * A cached resource object, stored in memory to optimize access to static resources
   * such as images and style sheets.
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: WebContentResource.java,v 1.1 2004/12/03 02:06:05 taylor Exp $ 
   */
  
  public class WebContentResource implements Serializable
  {
      private transient byte[] content = null;
      private transient Cookie cookie = null;
      private String url = null;
      private String lastUrl = null;
  
      /**
       * Constructor for a cached resource. 
       *
       * @param contentType The HTTP content type for a cached resource as defined 
       *        in WebPageHelper, i.e. WebPageHelper.CT_HTML, WebPageHelper.CT_IMAGE....
       * @param content The byte array of content this cached. This content can be
       *         binary images, or static text such as scripts and style sheets.
       *         
       */
      public WebContentResource(String url, byte[] content)
      {
          this.url = url;
          if (content != null)
          {
              this.content = new byte[content.length];
              System.arraycopy(content, 0, this.content, 0, this.content.length);
          }
      }
  
      /**
       * Gets the content of this resource in a byte array.
       *
       * @return A byte array of the resource's content.
       */
      public byte[] getContent()
      {
          return content;
      }
  
  
      /**
       * @return Returns the lastUrl.
       */
      public String getLastUrl()
      {
          return lastUrl;
      }
      /**
       * @param lastUrl The lastUrl to set.
       */
      public void setLastUrl(String lastUrl)
      {
          this.lastUrl = lastUrl;
      }
      /**
       * @return Returns the url.
       */
      public String getUrl()
      {
          return url;
      }
      /**
       * @param url The url to set.
       */
      public void setUrl(String url)
      {
          this.url = url;
      }
  }
  
  
  

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


Mime
View raw message