[jboss-cvs] Picketlink SVN: r987 - in social/trunk/openid/src/test: java/org/picketlink/test/social/openid/integration and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jun 13 15:00:59 EDT 2011


Author: anil.saldhana at jboss.com
Date: 2011-06-13 15:00:59 -0400 (Mon, 13 Jun 2011)
New Revision: 987

Added:
   social/trunk/openid/src/test/java/org/picketlink/test/social/openid/EmbeddedWebServerBase.java
   social/trunk/openid/src/test/java/org/picketlink/test/social/openid/InMemoryProtocolAdapter.java
   social/trunk/openid/src/test/java/org/picketlink/test/social/openid/integration/
   social/trunk/openid/src/test/java/org/picketlink/test/social/openid/integration/LocalProviderOpenIDUnitTestCase.java
   social/trunk/openid/src/test/java/org/picketlink/test/social/openid/integration/YadisMetadataUnitTestCase.java
   social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/
   social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/OpenIDWorkflowTestConsumerServlet.java
   social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/OpenIDWorkflowUnitTestCase.java
   social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/PrincipalInducingTestServletFilter.java
   social/trunk/openid/src/test/resources/endorsed/
   social/trunk/openid/src/test/resources/endorsed/resolver.jar
   social/trunk/openid/src/test/resources/endorsed/serializer.jar
   social/trunk/openid/src/test/resources/endorsed/xalan.jar
   social/trunk/openid/src/test/resources/endorsed/xercesImpl.jar
   social/trunk/openid/src/test/resources/endorsed/xml-apis.jar
   social/trunk/openid/src/test/resources/openid/
   social/trunk/openid/src/test/resources/openid/localhost-yadis.xml
   social/trunk/openid/src/test/resources/openid/webapp/
   social/trunk/openid/src/test/resources/openid/webapp/index.jsp
   social/trunk/openid/src/test/resources/openid/webapp/securepage.jsp
Log:
openid code migration

Added: social/trunk/openid/src/test/java/org/picketlink/test/social/openid/EmbeddedWebServerBase.java
===================================================================
--- social/trunk/openid/src/test/java/org/picketlink/test/social/openid/EmbeddedWebServerBase.java	                        (rev 0)
+++ social/trunk/openid/src/test/java/org/picketlink/test/social/openid/EmbeddedWebServerBase.java	2011-06-13 19:00:59 UTC (rev 987)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.picketlink.test.social.openid;
+
+import junit.framework.TestCase;
+
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.bio.SocketConnector;
+
+/**
+ * Base class for embedded web server based tests
+ * @author Anil.Saldhana at redhat.com
+ * @since Jul 8, 2009
+ */
+public abstract class EmbeddedWebServerBase extends TestCase
+{
+   protected Server server = null;
+   
+   public void setUp() throws Exception
+   {
+      super.setUp(); 
+      
+      //Start the Jetty embedded container
+      server = new Server();
+      
+      server.setConnectors(getConnectors());
+      
+      this.establishUserApps(); 
+
+      server.start();        
+   } 
+   
+   public void tearDown() throws Exception
+   {
+      if(server != null)
+      {
+         server.stop();
+         server.destroy();
+         server = null;
+      } 
+      super.tearDown();
+   }
+   
+   /**
+    * Return the connectors that need to be configured
+    * on the server. Subclasses can create as many connectors
+    * as they want
+    * @return
+    */
+   protected Connector[] getConnectors()
+   {
+      Connector connector=new SocketConnector();
+      connector.setPort(11080);
+      return new Connector[]{connector}; 
+   }
+   
+   /**
+    * Establish the user applications - context, servlets etc
+    */
+   protected abstract void establishUserApps(); 
+}
\ No newline at end of file

Added: social/trunk/openid/src/test/java/org/picketlink/test/social/openid/InMemoryProtocolAdapter.java
===================================================================
--- social/trunk/openid/src/test/java/org/picketlink/test/social/openid/InMemoryProtocolAdapter.java	                        (rev 0)
+++ social/trunk/openid/src/test/java/org/picketlink/test/social/openid/InMemoryProtocolAdapter.java	2011-06-13 19:00:59 UTC (rev 987)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.picketlink.test.social.openid;
+
+import java.net.URL;
+import java.util.Map;
+
+import org.picketlink.identity.federation.api.openid.OpenIDAttributeMap;
+import org.picketlink.identity.federation.api.openid.OpenIDLifecycle;
+import org.picketlink.identity.federation.api.openid.OpenIDLifecycleEvent;
+import org.picketlink.identity.federation.api.openid.OpenIDProtocolAdapter;
+import org.picketlink.identity.federation.api.openid.exceptions.OpenIDLifeCycleException;
+import org.picketlink.identity.federation.api.openid.exceptions.OpenIDProtocolException;
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.WebConversation;
+import com.meterware.httpunit.WebForm;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+/**
+ * Adapter that is in memory or the same VM
+ * @author Anil.Saldhana at redhat.com
+ * @since Jul 7, 2009
+ */
+public class InMemoryProtocolAdapter implements OpenIDProtocolAdapter, OpenIDLifecycle
+{ 
+   public OpenIDAttributeMap getAttributeMap()
+   { 
+      return new OpenIDAttributeMap();
+   }
+   
+   public void handle(OpenIDLifecycleEvent event)
+   { 
+   }
+
+   public Object getAttributeValue(String name)
+   {
+      return null;
+   }
+
+   public void handle(OpenIDLifecycleEvent[] eventArr) throws OpenIDLifeCycleException
+   { 
+   } 
+   
+   public String getReturnURL()
+   {
+      return "http://localhost:11080/consumer";
+   }
+
+   public void sendToProvider(int version, String destinationURL, Map<String, String> paramMap)
+         throws OpenIDProtocolException
+   {
+      System.out.println("Version="+ version);
+      System.out.println("destinationURL="+ destinationURL);
+      System.out.println("paramMap="+ paramMap);
+      
+      if(version == 1)
+      {   
+         WebConversation wc = new WebConversation();
+         wc.setAuthorization( "anil", "anil" );
+         WebRequest req = new GetMethodWebRequest( destinationURL );
+         try
+         {
+            WebResponse resp = wc.getResponse( req );
+            URL responseURL = resp.getURL(); 
+            if( responseURL.toString().contains( "securepage.jsp" ))
+            {
+               resp = wc.getResponse( responseURL.toString() );
+               WebForm form = resp.getForms()[0];
+               resp = form.submit();
+            }
+         }
+         catch ( Exception e)
+         { 
+            e.printStackTrace();
+            throw new OpenIDProtocolException();
+         }  
+      }
+      else
+      {
+         throw new RuntimeException("Not implemented");
+      }
+   }
+}
\ No newline at end of file

Added: social/trunk/openid/src/test/java/org/picketlink/test/social/openid/integration/LocalProviderOpenIDUnitTestCase.java
===================================================================
--- social/trunk/openid/src/test/java/org/picketlink/test/social/openid/integration/LocalProviderOpenIDUnitTestCase.java	                        (rev 0)
+++ social/trunk/openid/src/test/java/org/picketlink/test/social/openid/integration/LocalProviderOpenIDUnitTestCase.java	2011-06-13 19:00:59 UTC (rev 987)
@@ -0,0 +1,198 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.picketlink.test.social.openid.integration;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.picketlink.identity.federation.api.openid.OpenIDManager;  
+import org.picketlink.identity.federation.api.openid.OpenIDRequest; 
+import org.picketlink.identity.federation.api.openid.OpenIDManager.OpenIDProviderInformation;
+import org.picketlink.identity.federation.api.openid.OpenIDManager.OpenIDProviderList; 
+import org.picketlink.test.social.openid.EmbeddedWebServerBase;
+import org.picketlink.test.social.openid.InMemoryProtocolAdapter;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.openid4java.message.AuthSuccess;
+import org.openid4java.message.DirectError;
+import org.openid4java.message.Message;
+import org.openid4java.message.ParameterList;
+import org.openid4java.server.InMemoryServerAssociationStore;
+import org.openid4java.server.ServerManager;
+
+/**
+ * Test the OpenID functionality within the VM
+ * @author Anil.Saldhana at redhat.com
+ * @since Jul 7, 2009
+ */
+public class LocalProviderOpenIDUnitTestCase extends EmbeddedWebServerBase
+{  
+   protected void establishUserApps()
+   {
+      ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+      InputStream is = tcl.getResourceAsStream("openid/localhost-yadis.xml");
+
+      assertNotNull("Yadis descriptor not null", is);
+
+      Context context = new Context(server,"/",Context.SESSIONS); 
+      context.addServlet(new ServletHolder(new YadisServlet(is)), "/*");
+
+      context.addServlet(new ServletHolder(new ProviderServlet()), "/provider/");
+   }
+
+   public void testOpenIDAuth() throws Exception
+   {
+      //String username = "http://jbosstest.myopenid.com";
+      String username = "http://localhost:11080";
+      InMemoryProtocolAdapter ad = new InMemoryProtocolAdapter();
+      OpenIDRequest openIDRequest = new OpenIDRequest(username);
+      OpenIDManager idm = new OpenIDManager(openIDRequest); 
+      OpenIDProviderList providers = idm.discoverProviders();
+      assertNotNull("List of providers is not null", providers);
+
+      OpenIDProviderInformation providerInfo = idm.associate(ad,providers);
+      boolean auth = idm.authenticate(ad, providerInfo);
+      assertTrue( "OpenID Auth was successful", auth );
+   }
+
+   //A provider servlet that always returns true
+   private static class ProviderServlet extends HttpServlet
+   {
+      private static final long serialVersionUID = 1L; 
+      
+      @Override
+      protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+      {
+         doGet(req, resp);
+      }
+
+      @Override
+      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+      {
+         System.out.println("Inside ProviderServlet::doGet");
+         
+         ParameterList requestP = new ParameterList(req.getParameterMap());
+         
+         ServerManager manager = new ServerManager();
+         manager.setSharedAssociations(new InMemoryServerAssociationStore());
+         manager.setPrivateAssociations(new InMemoryServerAssociationStore());
+         manager.setOPEndpointUrl("http://localhost:11080/provider/");
+         
+         String userSelectedId = "http://test.localhost:11080";
+         String userSelectedClaimedId = userSelectedId;
+         boolean authenticatedAndApproved = true;
+         
+         String responseText = "";
+         
+         String mode = requestP.hasParameter("openid.mode") ?
+               requestP.getParameterValue("openid.mode") : null;
+
+         System.out.println("ProviderServlet::mode="+mode);
+         Message responsem ;
+         if ("associate".equals(mode))
+         {
+                  // --- process an association request ---
+                  responsem = manager.associationResponse(requestP);
+                  responseText = responsem.keyValueFormEncoding().trim();
+         }
+         else if ("checkid_setup".equals(mode)
+               || "checkid_immediate".equals(mode))
+         {
+            responsem = manager.authResponse(requestP,
+                  userSelectedId,
+                  userSelectedClaimedId,
+                  authenticatedAndApproved );
+
+            if (responsem instanceof AuthSuccess)
+            {
+                resp.sendRedirect(((AuthSuccess) responsem).getDestinationUrl(true));
+                return;
+            }
+            else
+            {
+                responseText="<pre>"+responsem.keyValueFormEncoding().trim()+"</pre>";
+            } 
+         }
+         else if ("check_authentication".equals(mode))
+         {
+             // --- processing a verification request ---
+             responsem = manager.verify(requestP);
+             responseText = responsem.keyValueFormEncoding().trim();
+         }
+         else
+         {
+             // --- error response ---
+             responsem = DirectError.createDirectError("Unknown request");
+             responseText = responsem.keyValueFormEncoding().trim();
+         }
+
+         resp.setStatus(HttpServletResponse.SC_OK); 
+         resp.getWriter().print(responseText);
+      }  
+   }
+   
+   //A Yadis servlet that just reads the XML from the Inputstream and passes it back
+   private class YadisServlet extends HttpServlet
+   {
+      private static final long serialVersionUID = 1L; 
+
+      private InputStream yadisDescriptor;
+    
+      public YadisServlet(InputStream yadisDescriptor)
+      {
+         if(yadisDescriptor == null)
+            throw new RuntimeException("input stream null");
+         this.yadisDescriptor = yadisDescriptor; 
+      } 
+
+      protected void doGet(HttpServletRequest request, HttpServletResponse resp) 
+      throws ServletException, IOException
+      {
+         System.out.println("Inside Yadis Servlet");
+         if("HEAD".equals(request.getMethod()))
+         {
+            resp.setStatus(HttpServletResponse.SC_OK); 
+            return; 
+         } 
+        
+         //Asking for Yadis discovery
+         byte[] barr = new byte[1024];
+         for (int i = 0; i < barr.length; i++) 
+         {
+            int b = yadisDescriptor.read();
+            if (b  == -1) break;
+            barr[i] = (byte) b;
+          }
+         resp.setContentType("application/xrds+xml");
+         resp.setStatus(HttpServletResponse.SC_OK);  
+         
+         String ycontent = new String(barr);
+         ycontent = ycontent.replace("\n"," ").trim();  
+         resp.getWriter().print(ycontent); 
+      }
+   }
+}
\ No newline at end of file

Added: social/trunk/openid/src/test/java/org/picketlink/test/social/openid/integration/YadisMetadataUnitTestCase.java
===================================================================
--- social/trunk/openid/src/test/java/org/picketlink/test/social/openid/integration/YadisMetadataUnitTestCase.java	                        (rev 0)
+++ social/trunk/openid/src/test/java/org/picketlink/test/social/openid/integration/YadisMetadataUnitTestCase.java	2011-06-13 19:00:59 UTC (rev 987)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.picketlink.test.social.openid.integration;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.picketlink.identity.federation.api.openid.OpenIDManager; 
+import org.picketlink.identity.federation.api.openid.OpenIDRequest; 
+import org.picketlink.identity.federation.api.openid.OpenIDManager.OpenIDProviderList; 
+import org.picketlink.social.openid.servlets.OpenIDYadisServlet;
+import org.picketlink.test.social.openid.EmbeddedWebServerBase;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+
+/**
+ * Unit test the OpenID Yadis Servlet
+ * @author Anil.Saldhana at redhat.com
+ * @since Jul 7, 2009
+ */
+public class YadisMetadataUnitTestCase extends EmbeddedWebServerBase
+{    
+   protected void establishUserApps()
+   {
+      Context context = new Context(server,"/",Context.SESSIONS);
+      ServletHolder servletHolder = new ServletHolder(new OpenIDYadisServlet()); 
+      servletHolder.setInitParameter("support_HTTP_HEAD", "true");
+      servletHolder.setInitParameter("yadisResourceURL", "http://localhost:11080/yadis");
+      
+      context.addServlet(servletHolder, "/*");
+      
+      context.addServlet(new ServletHolder( new TestYadisResourceServlet()), "/yadis");
+   }
+   
+   public void testYadisDiscovery() throws Exception
+   {
+      //String username = "http://jbosstest.myopenid.com";
+      String username = "http://localhost:11080"; 
+      
+      OpenIDRequest openIDRequest = new OpenIDRequest(username);
+      OpenIDManager idm = new OpenIDManager(openIDRequest);
+      
+      OpenIDProviderList providers = idm.discoverProviders(); 
+      assertNotNull("Providers list is not null", providers);
+      assertEquals("1 provider", 1, providers.size());
+   }
+   
+   /**
+    * Servlet that just outputs an Yadis resource
+    */
+   private class TestYadisResourceServlet extends HttpServlet
+   {
+      private static final long serialVersionUID = 1L;
+    
+      String yadis = "<xrds:XRDS "+
+                        " xmlns:xrds=\'xri://$xrds\' " +
+                        " xmlns:openid=\'http://openid.net/xmlns/1.0\'" +
+                        " xmlns=\'xri://$xrd*($v*2.0)\'>" +
+                        "<XRD>" +
+                        " <Service priority=\'0\'>" +
+                        " <Type>http://openid.net/signon/1.0</Type>" +
+                        " <URI>http://localhost/provider.jsp</URI>" +
+                        " </Service>"+
+                        "</XRD>" +
+                     "</xrds:XRDS>";
+      @Override
+      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+      {
+         resp.setContentType("application/xrds+xml");
+         resp.setStatus(HttpServletResponse.SC_OK);
+         resp.getWriter().print(yadis); 
+      } 
+   }
+}
\ No newline at end of file

Added: social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/OpenIDWorkflowTestConsumerServlet.java
===================================================================
--- social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/OpenIDWorkflowTestConsumerServlet.java	                        (rev 0)
+++ social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/OpenIDWorkflowTestConsumerServlet.java	2011-06-13 19:00:59 UTC (rev 987)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.picketlink.test.social.openid.workflow;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.picketlink.identity.federation.api.openid.OpenIDManager;
+import org.picketlink.identity.federation.web.openid.HTTPOpenIDContext;
+import org.picketlink.identity.federation.web.openid.HTTPProtocolAdaptor;
+
+/**
+ * Test Consumer Servlet
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 19, 2011
+ */
+public class OpenIDWorkflowTestConsumerServlet extends HttpServlet
+{ 
+   private static final long serialVersionUID = 1L;
+   
+   private OpenIDManager manager = null;
+   
+   public OpenIDWorkflowTestConsumerServlet( OpenIDManager mgr )
+   {
+      this.manager = mgr;
+   }
+
+   @SuppressWarnings("unchecked")
+   @Override
+   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+   { 
+      log( "Provider response:" + request.getQueryString() );
+      log( "UserID Chosen=" + request.getParameter( "openid.identity" )); 
+      
+      // extract the receiving URL from the HTTP request
+      StringBuffer receivingURL = request.getRequestURL();
+      String queryString = request.getQueryString();
+      if (queryString != null && queryString.length() > 0)
+          receivingURL.append("?").append(request.getQueryString());
+
+      HTTPProtocolAdaptor adapter = new HTTPProtocolAdaptor(new HTTPOpenIDContext( request,response, getServletContext() ));
+      try
+      { 
+         boolean auth = manager.verify(adapter, request.getParameterMap(), receivingURL.toString() );
+         if( !auth )
+            throw new ServletException( "OpenID information from provider not successfully verified" );
+      }
+      catch ( Exception e)
+      { 
+         e.printStackTrace();
+         throw new IOException();
+      } 
+   } 
+}
\ No newline at end of file

Added: social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/OpenIDWorkflowUnitTestCase.java
===================================================================
--- social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/OpenIDWorkflowUnitTestCase.java	                        (rev 0)
+++ social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/OpenIDWorkflowUnitTestCase.java	2011-06-13 19:00:59 UTC (rev 987)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.picketlink.test.social.openid.workflow;
+
+import java.net.URL;
+
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.webapp.WebAppContext;
+import org.picketlink.identity.federation.api.openid.OpenIDManager;
+import org.picketlink.identity.federation.api.openid.OpenIDManager.OpenIDProviderInformation;
+import org.picketlink.identity.federation.api.openid.OpenIDManager.OpenIDProviderList;
+import org.picketlink.identity.federation.api.openid.OpenIDRequest; 
+import org.picketlink.social.openid.servlets.OpenIDProviderServlet;
+import org.picketlink.test.social.openid.EmbeddedWebServerBase;
+import org.picketlink.test.social.openid.InMemoryProtocolAdapter;
+
+
+/**
+ * Test the workflow of an OpenID Consumer with a provider
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 18, 2011
+ */
+public class OpenIDWorkflowUnitTestCase extends EmbeddedWebServerBase
+{ 
+   private String username = "http://localhost:11080";
+   private OpenIDRequest openIDRequest = new OpenIDRequest( username ); 
+   private OpenIDManager manager = new OpenIDManager( openIDRequest ); 
+   
+   protected void establishUserApps()
+   {
+      ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+      
+      final String WEBAPPDIR = "openid/webapp"; 
+
+      final String CONTEXTPATH = "/";
+
+      // for localhost:port/admin/index.html and whatever else is in the webapp directory
+      final URL warUrl = tcl.getResource(WEBAPPDIR);
+      final String warUrlString = warUrl.toExternalForm();
+      
+      Context context = new WebAppContext( warUrlString, CONTEXTPATH );
+      server.setHandler( context );
+ 
+      context.addServlet(new ServletHolder(new OpenIDProviderServlet()), "/provider/");
+      
+      context.addServlet( new ServletHolder( new OpenIDWorkflowTestConsumerServlet( manager)), "/consumer" );
+      
+      context.addFilter(PrincipalInducingTestServletFilter.class, "/securepage.jsp",  1 );
+   }
+
+   public void testOpenIDAuth() throws Exception
+   {   
+      InMemoryProtocolAdapter ad = new InMemoryProtocolAdapter(); 
+      OpenIDProviderList providers = manager.discoverProviders();
+      assertNotNull("List of providers is not null", providers);
+
+      OpenIDProviderInformation providerInfo = manager.associate( ad,providers );
+      boolean isValid = manager.authenticate( ad, providerInfo );
+      assertTrue( "Authentication is valid" , isValid );
+   } 
+}
\ No newline at end of file

Added: social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/PrincipalInducingTestServletFilter.java
===================================================================
--- social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/PrincipalInducingTestServletFilter.java	                        (rev 0)
+++ social/trunk/openid/src/test/java/org/picketlink/test/social/openid/workflow/PrincipalInducingTestServletFilter.java	2011-06-13 19:00:59 UTC (rev 987)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.picketlink.test.social.openid.workflow;
+
+import java.io.IOException;
+import java.security.Principal;
+
+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 org.mortbay.jetty.Request;
+
+/**
+ * A servlet filter for testing that adds a principal with name "anil"
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 19, 2011
+ */
+public class PrincipalInducingTestServletFilter implements Filter
+{  
+   public void init(FilterConfig filterConfig) throws ServletException
+   { 
+   }
+
+   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
+         ServletException
+   { 
+      Request jettyRequest = (Request) request;
+      if( jettyRequest.getUserPrincipal() == null )
+      {
+         jettyRequest.setUserPrincipal( new Principal() {
+
+            public String getName()
+            { 
+               return "http://localhost:11080/";
+            }} );
+      }
+      chain.doFilter(request, response); 
+   }
+
+   public void destroy()
+   {
+   } 
+}
\ No newline at end of file

Added: social/trunk/openid/src/test/resources/endorsed/resolver.jar
===================================================================
(Binary files differ)


Property changes on: social/trunk/openid/src/test/resources/endorsed/resolver.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: social/trunk/openid/src/test/resources/endorsed/serializer.jar
===================================================================
(Binary files differ)


Property changes on: social/trunk/openid/src/test/resources/endorsed/serializer.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: social/trunk/openid/src/test/resources/endorsed/xalan.jar
===================================================================
(Binary files differ)


Property changes on: social/trunk/openid/src/test/resources/endorsed/xalan.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: social/trunk/openid/src/test/resources/endorsed/xercesImpl.jar
===================================================================
(Binary files differ)


Property changes on: social/trunk/openid/src/test/resources/endorsed/xercesImpl.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: social/trunk/openid/src/test/resources/endorsed/xml-apis.jar
===================================================================
(Binary files differ)


Property changes on: social/trunk/openid/src/test/resources/endorsed/xml-apis.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: social/trunk/openid/src/test/resources/openid/localhost-yadis.xml
===================================================================
--- social/trunk/openid/src/test/resources/openid/localhost-yadis.xml	                        (rev 0)
+++ social/trunk/openid/src/test/resources/openid/localhost-yadis.xml	2011-06-13 19:00:59 UTC (rev 987)
@@ -0,0 +1,10 @@
+<xrds:XRDS  xmlns:xrds="xri://$xrds"  
+            xmlns:openid="http://openid.net/xmlns/1.0" 
+            xmlns="xri://$xrd*($v*2.0)">
+   <XRD>
+     <Service priority="0">
+       <Type>http://openid.net/signon/1.0</Type>
+       <URI>http://localhost:11080/provider/</URI> 
+     </Service>
+   </XRD>
+</xrds:XRDS>
\ No newline at end of file

Added: social/trunk/openid/src/test/resources/openid/webapp/index.jsp
===================================================================
--- social/trunk/openid/src/test/resources/openid/webapp/index.jsp	                        (rev 0)
+++ social/trunk/openid/src/test/resources/openid/webapp/index.jsp	2011-06-13 19:00:59 UTC (rev 987)
@@ -0,0 +1,18 @@
+<%@ page contentType="application/xrds+xml"%><?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS
+  xmlns:xrds="xri://$xrds"
+  xmlns:openid="http://openid.net/xmlns/1.0"
+  xmlns="xri://$xrd*($v*2.0)">
+  <XRD>
+   <!-- Change the URI for OpenID2 pointing to where the provider is located -->
+    <Service priority="0">
+      <Type>http://specs.openid.net/auth/2.0</Type>
+      <URI>http://localhost:11080/provider/</URI>
+    </Service>
+   <!-- Change the URI for OpenID1 pointing to where the provider is located -->
+    <Service priority="1">
+      <Type>http://openid.net/signon/1.0</Type>
+      <URI>http://localhost:11080/provider/</URI>
+    </Service>
+  </XRD>
+</xrds:XRDS>

Added: social/trunk/openid/src/test/resources/openid/webapp/securepage.jsp
===================================================================
--- social/trunk/openid/src/test/resources/openid/webapp/securepage.jsp	                        (rev 0)
+++ social/trunk/openid/src/test/resources/openid/webapp/securepage.jsp	2011-06-13 19:00:59 UTC (rev 987)
@@ -0,0 +1,10 @@
+<%
+ session.setAttribute("authenticatedAndApproved", Boolean.TRUE); 
+%>
+
+
+You have logged in.
+
+<form method="POST" action="<%=request.getContextPath()%>/provider/?_action=complete">
+<input type="submit" value="Continue"/>
+</form>



More information about the jboss-cvs-commits mailing list