[gatein-commits] gatein SVN: r5078 - in components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent: cas and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Nov 12 18:59:48 EST 2010


Author: sohil.shah at jboss.com
Date: 2010-11-12 18:59:48 -0500 (Fri, 12 Nov 2010)
New Revision: 5078

Added:
   components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/filter/InitiateLoginFilter.java
Removed:
   components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/GenericSSOAgent.java
Modified:
   components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/cas/CASAgent.java
   components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/josso/JOSSOAgent.java
   components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/opensso/OpenSSOAgent.java
Log:
removing dependency on the InitiateLoginServlet from the portal

Deleted: components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/GenericSSOAgent.java
===================================================================
--- components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/GenericSSOAgent.java	2010-11-12 21:16:39 UTC (rev 5077)
+++ components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/GenericSSOAgent.java	2010-11-12 23:59:48 UTC (rev 5078)
@@ -1,129 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.gatein.sso.agent;
-
-import java.io.IOException;
-
-import org.apache.log4j.Logger;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.exoplatform.web.login.InitiateLoginServlet;
-
-import org.gatein.sso.agent.cas.CASAgent;
-import org.gatein.sso.agent.josso.JOSSOAgent;
-import org.gatein.sso.agent.opensso.OpenSSOAgent;
-
-/**
- * @author <a href="mailto:sshah at redhat.com">Sohil Shah</a>
- */
-public class GenericSSOAgent extends InitiateLoginServlet
-{
-	private static final long serialVersionUID = 6330639010812906309L;
-
-	private static Logger log = Logger.getLogger(GenericSSOAgent.class);
-	
-	private String ssoServerUrl;
-	private String ssoCookieName;
-	private boolean casRenewTicket;
-	
-	
-	@Override
-	public void init() throws ServletException
-	{
-		super.init();
-		
-		this.ssoServerUrl = this.getServletConfig().getInitParameter("ssoServerUrl");
-		this.ssoCookieName = this.getServletConfig().getInitParameter("ssoCookieName");
-		
-		String casRenewTicketConfig = this.getServletConfig().getInitParameter("casRenewTicket");
-		if(casRenewTicketConfig != null)
-		{
-			this.casRenewTicket = Boolean.parseBoolean(casRenewTicketConfig);
-		}
-	}
-
-	@Override
-	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
-			throws ServletException, IOException
-	{
-		try
-		{
-			this.processSSOToken(req,resp);	
-			
-			String portalContext = req.getContextPath();
-			if(req.getAttribute("abort") != null)
-			{
-				String ssoRedirect = portalContext + "/sso";
-				resp.sendRedirect(ssoRedirect);
-				return;
-			}
-			
-			super.doGet(req, resp);
-		}
-		catch(Exception e)
-		{
-			log.error(this, e);
-			throw new ServletException(e);
-		}
-	}
-
-	@Override
-	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
-			throws ServletException, IOException
-	{
-		this.doGet(req, resp);
-	}
-
-	private void processSSOToken(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws Exception
-	{
-		String ticket = httpRequest.getParameter("ticket");
-		String jossoAssertion = httpRequest.getParameter("josso_assertion_id");
-
-		if (ticket != null && ticket.trim().length() > 0)
-		{
-			CASAgent casagent = CASAgent.getInstance(this.ssoServerUrl);
-			casagent.setRenewTicket(this.casRenewTicket);
-			casagent.validateTicket(httpRequest, ticket);
-		}
-		else if (jossoAssertion != null && jossoAssertion.trim().length() > 0)
-		{
-			//the JOSSO Agent. This will need to the new client side JOSSO stack that can run on 5.1.0.GA
-			JOSSOAgent.getInstance().validateTicket(httpRequest,httpResponse);
-		}
-		else
-		{
-			try
-			{
-				//See if an OpenSSO Token was used
-				OpenSSOAgent.getInstance(this.ssoServerUrl, this.ssoCookieName).validateTicket(httpRequest);
-			}
-			catch(IllegalStateException ilse)
-			{
-				//somehow cookie failed validation, retry by starting the opensso login process again
-				httpRequest.setAttribute("abort", Boolean.TRUE);
-			}
-		}
-	}		
-}

Modified: components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/cas/CASAgent.java
===================================================================
--- components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/cas/CASAgent.java	2010-11-12 21:16:39 UTC (rev 5077)
+++ components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/cas/CASAgent.java	2010-11-12 23:59:48 UTC (rev 5078)
@@ -25,7 +25,6 @@
 
 import javax.servlet.http.HttpServletRequest;
 
-import org.gatein.sso.agent.GenericSSOAgent;
 import org.gatein.wci.security.Credentials;
 import org.jasig.cas.client.validation.Cas20ProxyTicketValidator;
 import org.jasig.cas.client.validation.Assertion;
@@ -92,7 +91,7 @@
 	    //better security
 	    String principal = assertion.getPrincipal().getName();
 	    Credentials credentials = new Credentials(principal, "");
-        httpRequest.getSession().setAttribute(GenericSSOAgent.CREDENTIALS, credentials);
+        httpRequest.getSession().setAttribute(Credentials.CREDENTIALS, credentials);
 	    httpRequest.getSession().setAttribute("username", principal);
 	}		
 }

Added: components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/filter/InitiateLoginFilter.java
===================================================================
--- components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/filter/InitiateLoginFilter.java	                        (rev 0)
+++ components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/filter/InitiateLoginFilter.java	2010-11-12 23:59:48 UTC (rev 5078)
@@ -0,0 +1,103 @@
+/**
+ * 
+ */
+package org.gatein.sso.agent.filter;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.gatein.sso.agent.cas.CASAgent;
+import org.gatein.sso.agent.josso.JOSSOAgent;
+import org.gatein.sso.agent.opensso.OpenSSOAgent;
+
+/**
+ * @author soshah
+ *
+ */
+public class InitiateLoginFilter implements Filter 
+{
+    private String ssoServerUrl;
+    private String ssoCookieName;
+    private boolean casRenewTicket;
+    
+    public void init(FilterConfig filterConfig) throws ServletException 
+    {
+        this.ssoServerUrl = filterConfig.getInitParameter("ssoServerUrl");
+        this.ssoCookieName = filterConfig.getInitParameter("ssoCookieName");
+        
+        String casRenewTicketConfig = filterConfig.getInitParameter("casRenewTicket");
+        if(casRenewTicketConfig != null)
+        {
+            this.casRenewTicket = Boolean.parseBoolean(casRenewTicketConfig);
+        }
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response,
+            FilterChain chain) throws IOException, ServletException 
+    {
+        try
+        {
+            HttpServletRequest req = (HttpServletRequest)request;
+            HttpServletResponse resp = (HttpServletResponse)response;
+            
+            this.processSSOToken(req,resp); 
+            
+            String portalContext = req.getContextPath();
+            if(req.getAttribute("abort") != null)
+            {
+                String ssoRedirect = portalContext + "/sso";
+                resp.sendRedirect(ssoRedirect);
+                return;
+            }
+            
+            chain.doFilter(request, response);
+        }
+        catch(Exception e)
+        {
+            throw new ServletException(e);
+        }
+    }
+
+    public void destroy() 
+    {    
+    }
+    
+    private void processSSOToken(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws Exception
+    {
+        String ticket = httpRequest.getParameter("ticket");
+        String jossoAssertion = httpRequest.getParameter("josso_assertion_id");
+
+        if (ticket != null && ticket.trim().length() > 0)
+        {
+            CASAgent casagent = CASAgent.getInstance(this.ssoServerUrl);
+            casagent.setRenewTicket(this.casRenewTicket);
+            casagent.validateTicket(httpRequest, ticket);
+        }
+        else if (jossoAssertion != null && jossoAssertion.trim().length() > 0)
+        {
+            //the JOSSO Agent. This will need to the new client side JOSSO stack that can run on 5.1.0.GA
+            JOSSOAgent.getInstance().validateTicket(httpRequest,httpResponse);
+        }
+        else
+        {
+            try
+            {
+                //See if an OpenSSO Token was used
+                OpenSSOAgent.getInstance(this.ssoServerUrl, this.ssoCookieName).validateTicket(httpRequest);
+            }
+            catch(IllegalStateException ilse)
+            {
+                //somehow cookie failed validation, retry by starting the opensso login process again
+                httpRequest.setAttribute("abort", Boolean.TRUE);
+            }
+        }
+    }       
+}

Modified: components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/josso/JOSSOAgent.java
===================================================================
--- components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/josso/JOSSOAgent.java	2010-11-12 21:16:39 UTC (rev 5077)
+++ components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/josso/JOSSOAgent.java	2010-11-12 23:59:48 UTC (rev 5078)
@@ -27,7 +27,6 @@
 import org.apache.log4j.Logger;
 
 import org.gatein.wci.security.Credentials;
-import org.gatein.sso.agent.GenericSSOAgent;
 
 import org.josso.agent.Lookup;
 import org.josso.agent.SSOAgentRequest;
@@ -101,7 +100,7 @@
 			log.debug("-----------------------------------------------------------");
 			
 			Credentials credentials = new Credentials(principal, "");
-			httpRequest.getSession().setAttribute(GenericSSOAgent.CREDENTIALS, credentials);
+			httpRequest.getSession().setAttribute(Credentials.CREDENTIALS, credentials);
 		}
 	}
 	

Modified: components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/opensso/OpenSSOAgent.java
===================================================================
--- components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/opensso/OpenSSOAgent.java	2010-11-12 21:16:39 UTC (rev 5077)
+++ components/sso/branches/sso-wci/agent/src/main/java/org/gatein/sso/agent/opensso/OpenSSOAgent.java	2010-11-12 23:59:48 UTC (rev 5078)
@@ -33,7 +33,6 @@
 import org.apache.commons.httpclient.methods.PostMethod;
 
 import org.gatein.wci.security.Credentials;
-import org.gatein.sso.agent.GenericSSOAgent;
 
 /**
  * @author <a href="mailto:sshah at redhat.com">Sohil Shah</a>
@@ -98,7 +97,7 @@
 			if(subject != null)
 			{
 				Credentials credentials = new Credentials(subject, "");
-				httpRequest.getSession().setAttribute(GenericSSOAgent.CREDENTIALS, credentials);
+				httpRequest.getSession().setAttribute(Credentials.CREDENTIALS, credentials);
 			}
 		}
 	}	



More information about the gatein-commits mailing list