portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roger...@apache.org
Subject cvs commit: jakarta-jetspeed-2/applications/gems/src/java/org/apache/portals/gems/browser BrowserPortlet.java DatabaseBrowserPortlet.java
Date Wed, 02 Feb 2005 00:49:33 GMT
rogerrut    2005/02/01 16:49:33

  Modified:    applications/gems/src/java/org/apache/portals/gems/browser
                        BrowserPortlet.java DatabaseBrowserPortlet.java
  Log:
  SSO -- Added SSO support to Database Browser
  
  Revision  Changes    Path
  1.6       +15 -0     jakarta-jetspeed-2/applications/gems/src/java/org/apache/portals/gems/browser/BrowserPortlet.java
  
  Index: BrowserPortlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/gems/src/java/org/apache/portals/gems/browser/BrowserPortlet.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BrowserPortlet.java	21 Jan 2005 22:10:08 -0000	1.5
  +++ BrowserPortlet.java	2 Feb 2005 00:49:33 -0000	1.6
  @@ -22,6 +22,7 @@
   
   import javax.portlet.ActionRequest;
   import javax.portlet.ActionResponse;
  +import javax.portlet.PortletContext;
   import javax.portlet.PortletException;
   import javax.portlet.PortletMode;
   import javax.portlet.PortletConfig;
  @@ -33,6 +34,7 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.jetspeed.sso.SSOProvider;
   import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
   import org.apache.portals.gems.util.StatusMessage;
   import org.apache.portals.messaging.PortletMessaging;
  @@ -108,6 +110,12 @@
       protected static final String SORT_COLUMN_NAME = "js_dbcolumn";
   
       protected List sqlParameters = new Vector();
  +    
  +    /*
  +     * SSO link
  +     */
  +    protected PortletContext context;
  +    protected SSOProvider sso;
   
       /**
        * Static initialization of the logger for this class
  @@ -117,6 +125,13 @@
       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 getRows(RenderRequest request, String sql, int windowSize)
  
  
  
  1.8       +36 -2     jakarta-jetspeed-2/applications/gems/src/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java
  
  Index: DatabaseBrowserPortlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/gems/src/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DatabaseBrowserPortlet.java	20 Jan 2005 21:14:44 -0000	1.7
  +++ DatabaseBrowserPortlet.java	2 Feb 2005 00:49:33 -0000	1.8
  @@ -16,6 +16,8 @@
   package org.apache.portals.gems.browser;
   
   import java.io.IOException;
  +import java.security.AccessControlContext;
  +import java.security.AccessController;
   import java.sql.Connection;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
  @@ -37,9 +39,12 @@
   import javax.portlet.PortletSession;
   import javax.portlet.RenderRequest;
   import javax.portlet.RenderResponse;
  +import javax.security.auth.Subject;
   import javax.sql.DataSource;
   
   import org.apache.commons.dbcp.BasicDataSource;
  +import org.apache.jetspeed.sso.SSOContext;
  +import org.apache.jetspeed.sso.SSOException;
   import org.apache.portals.bridges.util.PreferencesHelper;
   import org.apache.portals.gems.util.StatusMessage;
   import org.apache.portals.messaging.PortletMessaging;
  @@ -252,7 +257,31 @@
               }
               else if (dsType.equals("sso"))
               {
  -                // TODO: write this
  +                /*
  +                 * For SSO the user has to define the JDBCdriver and JdbcConnection (URL)
  +                 * but the credentials for the db come from the SSO storage
  +                 */
  +                BasicDataSource ds = new BasicDataSource();
  +                ds.setDriverClassName(prefs.getValue("SSOJdbcDriver", ""));
  +                ds.setUrl(prefs.getValue("SSOJdbcConnection", ""));  
  +                String ssoURL = prefs.getValue("SSOSite", "");
  +                
  +                // SSO API lookup
  +                SSOContext credentials = null;
  +                try
  +                {
  +                    credentials = sso.getCredentials(getSubject(), ssoURL);
  +                }
  +                catch(SSOException ssoex)
  +                {
  +                    throw new Exception("SSO credential lookup failed. Error: " + ssoex.getMessage());
  +                }
  +                
  +                String ssoUserName = credentials.getRemotePrincipalName();
  +                String ssoPWD = credentials.getRemoteCredential();
  +                ds.setUsername(ssoUserName);
  +                ds.setPassword( ssoPWD );
  +                con = ds.getConnection();
               }
               else
               {
  @@ -333,4 +362,9 @@
           super.processAction(request, response);
       }
       
  +    private Subject getSubject()
  +    {
  +        AccessControlContext context = AccessController.getContext();
  +        return Subject.getSubject(context);         
  +    }
   }
  
  
  

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