From do-not-reply at jboss.org Mon Apr 5 13:59:36 2010 Content-Type: multipart/mixed; boundary="===============8758328558620223469==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: gatein-commits at lists.jboss.org Subject: [gatein-commits] gatein SVN: r2475 - components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/filter. Date: Mon, 05 Apr 2010 13:59:36 -0400 Message-ID: <201004051759.o35Hxa4M028039@svn01.web.mwc.hst.phx2.redhat.com> --===============8758328558620223469== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: sohil.shah(a)jboss.com Date: 2010-04-05 13:59:36 -0400 (Mon, 05 Apr 2010) New Revision: 2475 Added: components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/filter/Abs= tractLogoutFilter.java Modified: components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/filter/JOS= SOLogoutFilter.java components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/filter/Ope= nSSOLogoutFilter.java Log: GTNPORTAL-996 - GateIn+JOSSO integration: Problems with logout Added: components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/filter= /AbstractLogoutFilter.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/filter/Ab= stractLogoutFilter.java (rev 0) +++ components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/filter/Ab= stractLogoutFilter.java 2010-04-05 17:59:36 UTC (rev 2475) @@ -0,0 +1,92 @@ +/* + * 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.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; + +/** + * @author Sohil Shah + */ +public abstract class AbstractLogoutFilter implements Filter +{ + protected String logoutUrl; + + public void init(FilterConfig config) throws ServletException + { + this.logoutUrl =3D config.getInitParameter("LOGOUT_URL"); + } + + public void destroy() + { + } + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException + { + HttpServletRequest httpRequest =3D (HttpServletRequest) request; + HttpServletResponse httpResponse =3D (HttpServletResponse) response; + + boolean isLogoutInProgress =3D this.isLogoutInProgress(httpRequest); + + if (isLogoutInProgress) + { + + if (httpRequest.getSession().getAttribute("SSO_LOGOUT_FLAG") =3D=3D nul= l) + { + httpRequest.getSession().setAttribute("SSO_LOGOUT_FLAG", Boolean.TRUE); + = + httpResponse.sendRedirect(this.getRedirectUrl(httpRequest)); + return; + } + else + { + // clear the LOGOUT flag + httpRequest.getSession().removeAttribute("SSO_LOGOUT_FLAG"); + } + } + + chain.doFilter(request, response); + } + + private boolean isLogoutInProgress(HttpServletRequest request) + { + String action =3D request.getParameter("portal:action"); + + if (action !=3D null && action.equals("Logout")) + { + return true; + } + + return false; + } + = + protected abstract String getRedirectUrl(HttpServletRequest httpRequest); +} Modified: components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/fil= ter/JOSSOLogoutFilter.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/filter/JO= SSOLogoutFilter.java 2010-04-05 16:39:25 UTC (rev 2474) +++ components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/filter/JO= SSOLogoutFilter.java 2010-04-05 17:59:36 UTC (rev 2475) @@ -21,17 +21,8 @@ */ package org.gatein.sso.agent.filter; = -import java.io.IOException; import java.net.URLEncoder; - -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; = //Works for GateIn Portal Logout URL =3D {AnyURL}?portal:componentId=3DUIP= ortal&portal:action=3DLogout = @@ -45,7 +36,7 @@ * org.gatein.sso.agent.filter.JOSSOLogoutFilter = * = * = = = - * JOSSO_LOGOUT_URL = = + * LOGOUT_URL = = * http://localhost:8888/josso/signon/logout.do = = * = = * = @@ -63,56 +54,23 @@ /** * @author Sohil Shah */ -public class JOSSOLogoutFilter implements Filter +public class JOSSOLogoutFilter extends AbstractLogoutFilter { - private String jossoLogoutUrl; - = - public void init(FilterConfig config) throws ServletException + protected String getRedirectUrl(HttpServletRequest httpRequest) { - this.jossoLogoutUrl =3D config.getInitParameter("JOSSO_LOGOUT_URL"); - } - - public void destroy() - { - } - - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException - { - HttpServletRequest httpRequest =3D (HttpServletRequest)request; - HttpServletResponse httpResponse =3D (HttpServletResponse)response; - = - boolean isLogoutInProgress =3D this.isLogoutInProgress(httpRequest); - = - if(isLogoutInProgress) + try { - = - if(httpRequest.getSession().getAttribute("SSO_LOGOUT_FLAG") =3D=3D null) - { - httpRequest.getSession().setAttribute("SSO_LOGOUT_FLAG", Boolean.TRUE); - String parameters =3D URLEncoder.encode("portal:componentId=3DUIPortal= &portal:action=3DLogout", "UTF-8"); - httpResponse.sendRedirect(jossoLogoutUrl+"?josso_back_to=3D"+httpReque= st.getRequestURL()+"?"+parameters); = - return; - } - else - { - //clear the LOGOUT flag - httpRequest.getSession().removeAttribute("SSO_LOGOUT_FLAG"); - } + String parameters =3D URLEncoder.encode( + "portal:componentId=3DUIPortal&portal:action=3DLogout", "UTF-8"); + = + String redirectUrl =3D this.logoutUrl + "?josso_back_to=3D" + + httpRequest.getRequestURL() + "?" + parameters; + = + return redirectUrl; } - = - chain.doFilter(request, response); = - } - = - private boolean isLogoutInProgress(HttpServletRequest request) - { - String action =3D request.getParameter("portal:action"); - = - if(action !=3D null && action.equals("Logout")) + catch(Exception e) { - return true; + throw new RuntimeException(e); } - = - return false; } } Modified: components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/fil= ter/OpenSSOLogoutFilter.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/filter/Op= enSSOLogoutFilter.java 2010-04-05 16:39:25 UTC (rev 2474) +++ components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/filter/Op= enSSOLogoutFilter.java 2010-04-05 17:59:36 UTC (rev 2475) @@ -21,17 +21,8 @@ */ package org.gatein.sso.agent.filter; = -import java.io.IOException; import java.net.URLEncoder; - -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; = //Works for GateIn Portal Logout URL =3D {AnyURL}?portal:componentId=3DUIP= ortal&portal:action=3DLogout = @@ -45,13 +36,13 @@ * org.gatein.sso.agent.filter.OpenSSOLogoutFilter = * = * = = = - * OPENSSO_LOGOUT_URL = = + * LOGOUT_URL = = * http://localhost:8888/opensso/UI/Logout = = * = = * = * = * - * JOSSOLogoutFilter + * OpenSSOLogoutFilter * /* * * @@ -63,56 +54,22 @@ /** * @author Sohil Shah */ -public class OpenSSOLogoutFilter implements Filter -{ - private String logoutUrl; - = - public void init(FilterConfig config) throws ServletException +public class OpenSSOLogoutFilter extends AbstractLogoutFilter +{ = + protected String getRedirectUrl(HttpServletRequest httpRequest) { - this.logoutUrl =3D config.getInitParameter("OPENSSO_LOGOUT_URL"); - } - - public void destroy() - { - } - - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException - { - HttpServletRequest httpRequest =3D (HttpServletRequest)request; - HttpServletResponse httpResponse =3D (HttpServletResponse)response; - = - boolean isLogoutInProgress =3D this.isLogoutInProgress(httpRequest); - = - if(isLogoutInProgress) + try { - = - if(httpRequest.getSession().getAttribute("SSO_LOGOUT_FLAG") =3D=3D null) - { - httpRequest.getSession().setAttribute("SSO_LOGOUT_FLAG", Boolean.TRUE); - String parameters =3D URLEncoder.encode("portal:componentId=3DUIPortal= &portal:action=3DLogout", "UTF-8"); - httpResponse.sendRedirect(this.logoutUrl+"?realm=3Dgatein&goto=3D"+htt= pRequest.getRequestURL()+"?"+parameters); = - return; - } - else - { - //clear the LOGOUT flag - httpRequest.getSession().removeAttribute("SSO_LOGOUT_FLAG"); - } + String parameters =3D URLEncoder.encode( + "portal:componentId=3DUIPortal&portal:action=3DLogout", "UTF-8"); + = + String redirectUrl =3D this.logoutUrl+"?realm=3Dgatein&goto=3D"+httpReq= uest.getRequestURL()+"?"+parameters; + = + return redirectUrl; } - = - chain.doFilter(request, response); = - } - = - private boolean isLogoutInProgress(HttpServletRequest request) - { - String action =3D request.getParameter("portal:action"); - = - if(action !=3D null && action.equals("Logout")) + catch(Exception e) { - return true; + throw new RuntimeException(e); } - = - return false; } } --===============8758328558620223469==--