[picketlink-commits] Picketlink SVN: r866 - in integration-tests/trunk/picketlink-trust-tests/src/test: java/org/picketlink/test/trust/ws and 3 other directories.

picketlink-commits at lists.jboss.org picketlink-commits at lists.jboss.org
Wed Apr 6 12:25:14 EDT 2011


Author: anil.saldhana at jboss.com
Date: 2011-04-06 12:25:13 -0400 (Wed, 06 Apr 2011)
New Revision: 866

Added:
   integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/tests/STSWSBinaryTokenTestCase.java
   integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/TestBean.java
   integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/handlers/
   integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/handlers/TestBinaryHandler.java
   integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/http/
   integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/http/TestServletRequest.java
   integration-tests/trunk/picketlink-trust-tests/src/test/resources/test-binary-handlers.xml
Log:
PLFED-162: test for binary token handler

Added: integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/tests/STSWSBinaryTokenTestCase.java
===================================================================
--- integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/tests/STSWSBinaryTokenTestCase.java	                        (rev 0)
+++ integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/tests/STSWSBinaryTokenTestCase.java	2011-04-06 16:25:13 UTC (rev 866)
@@ -0,0 +1,83 @@
+/*
+ * 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.trust.tests;
+
+import java.net.URL;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.MessageContext;
+
+import org.junit.Test;
+import org.picketlink.test.trust.ws.TestBean;
+import org.picketlink.test.trust.ws.WSTest;
+import org.picketlink.test.trust.ws.handlers.TestBinaryHandler;
+import org.picketlink.test.trust.ws.http.TestServletRequest;
+import org.picketlink.trust.jbossws.handler.BinaryTokenHandler;
+
+/**
+ * Unit Test the {@link BinaryTokenHandler}
+ * @author Anil.Saldhana at redhat.com
+ * @since Apr 5, 2011
+ */
+public class STSWSBinaryTokenTestCase
+{   
+   /**
+    * This test case does the following.
+    * - We set a Test HttpServletRequest on the soap message context.
+    * - We then inject the {@link BinaryTokenHandler} as a client side handler.
+    * - On the Server Side, we are hitting the {@link TestBean} which is guarded by the {@link TestBinaryHandler}
+    * 
+    * The WS has no security. The Server side {@link TestBinaryHandler} ensures that the call comes in with a 
+    * BinarySecurityToken
+    * 
+    * @throws Exception
+    */
+   @SuppressWarnings("rawtypes")
+   @Test
+   public void testWSInteraction() throws Exception 
+   { 
+      System.setProperty("binary.http.header", "TEST_HEADER");
+      
+      URL wsdl = new URL("http://localhost:8080/picketlink-wstest-tests/TestBean?wsdl");
+      QName serviceName = new QName("http://ws.trust.test.picketlink.org/", "TestBeanService");
+      Service service = Service.create(wsdl, serviceName);
+      WSTest port = service.getPort(new QName("http://ws.trust.test.picketlink.org/", "TestBeanPort"), WSTest.class);
+
+      TestServletRequest request = new TestServletRequest();
+      request.addHeader("TEST_HEADER", "ABCDEFGH");
+
+      BindingProvider bp = (BindingProvider)port;
+      bp.getRequestContext().put(MessageContext.SERVLET_REQUEST, request);
+      List<Handler> handlers = bp.getBinding().getHandlerChain();
+
+      BinaryTokenHandler binaryTokenHandler = new BinaryTokenHandler();
+  
+      handlers.add(binaryTokenHandler);
+      bp.getBinding().setHandlerChain(handlers); 
+
+      port.echo("Test");
+   }
+}
\ No newline at end of file

Added: integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/TestBean.java
===================================================================
--- integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/TestBean.java	                        (rev 0)
+++ integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/TestBean.java	2011-04-06 16:25:13 UTC (rev 866)
@@ -0,0 +1,48 @@
+/*
+ * 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.trust.ws;
+
+import javax.annotation.Resource;
+import javax.ejb.Stateless;
+import javax.jws.HandlerChain;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.xml.ws.WebServiceContext;
+
+/**
+ * @author Anil.Saldhana at redhat.com
+ * @since Apr 5, 2011
+ */
+ at Stateless
+ at WebService
+ at HandlerChain(file="test-binary-handlers.xml")
+public class TestBean implements WSTest
+{ 
+   @Resource
+   WebServiceContext wsCtx;
+
+   @WebMethod
+   public void echo(String echo)
+   {
+      System.out.println(echo);
+   }
+}

Added: integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/handlers/TestBinaryHandler.java
===================================================================
--- integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/handlers/TestBinaryHandler.java	                        (rev 0)
+++ integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/handlers/TestBinaryHandler.java	2011-04-06 16:25:13 UTC (rev 866)
@@ -0,0 +1,101 @@
+/*
+ * 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.trust.ws.handlers;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+import org.jboss.wsf.common.handler.GenericSOAPHandler;
+import org.picketlink.trust.jbossws.Constants;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * A Test {@link GenericSOAPHandler} that just verifies that the 
+ * SOAP header has a wsse Binary Security Token before letting the call
+ * go through.
+ * 
+ * @author Anil.Saldhana at redhat.com
+ * @since Apr 5, 2011
+ */
+ at SuppressWarnings("rawtypes")
+public class TestBinaryHandler extends GenericSOAPHandler
+{ 
+   private static Set<QName> headers;
+
+   static
+   {
+      HashSet<QName> set = new HashSet<QName>();
+      set.add(Constants.WSSE_HEADER_QNAME);
+      headers = Collections.unmodifiableSet(set);
+   }
+
+   public Set<QName> getHeaders()
+   {
+      //return a collection with just the wsse:Security header to pass the MustUnderstand check on it
+      return headers;
+   }
+   
+   @Override
+   protected boolean handleInbound(MessageContext msgContext)
+   { 
+      SOAPMessageContext soapMessageContext = (SOAPMessageContext) msgContext;
+      SOAPMessage soap = soapMessageContext.getMessage();
+      try
+      {
+         soap.writeTo(System.out);
+         SOAPHeader header = soap.getSOAPHeader(); 
+         Iterator iter = header.extractAllHeaderElements();
+         if( iter != null)
+         {
+            while(iter.hasNext())
+            {
+               SOAPHeaderElement headerEl = (SOAPHeaderElement) iter.next();
+               if(headerEl.getNodeName().contains(Constants.WSSE_LOCAL))
+               {
+                  NodeList nl = headerEl.getChildNodes();
+                  for( int i = 0; i < nl.getLength(); i++)
+                  {
+                     Node n = nl.item(i);
+                     if( n.getNodeName().contains(Constants.WSSE_BINARY_SECURITY_TOKEN))
+                        return true;
+                  }
+               }
+            }
+         }
+      }
+      catch (Exception e)
+      { 
+         e.printStackTrace();
+      }  
+      return false;
+   }
+}
\ No newline at end of file

Added: integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/http/TestServletRequest.java
===================================================================
--- integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/http/TestServletRequest.java	                        (rev 0)
+++ integration-tests/trunk/picketlink-trust-tests/src/test/java/org/picketlink/test/trust/ws/http/TestServletRequest.java	2011-04-06 16:25:13 UTC (rev 866)
@@ -0,0 +1,321 @@
+/*
+ * 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.trust.ws.http;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.Principal;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+/**
+ * A Test {@link HttpServletRequest} that just has the headers
+ * that were added via the {@link #addHeader(String, String)} call
+ * 
+ * @author Anil.Saldhana at redhat.com
+ * @since Apr 5, 2011
+ */
+ at SuppressWarnings("rawtypes") 
+public class TestServletRequest implements HttpServletRequest
+{ 
+   private Map<String,String> headers = new HashMap<String,String>();
+    
+   public void addHeader(String key, String value)
+   {
+      headers.put(key, value);
+   }
+   
+   public String getLocalName()
+   {
+      return "localhost";
+   }
+   
+   public String getLocalAddr()
+   {
+      return "localhost";
+   }
+   public int getLocalPort()
+   {
+      return 8080;
+   }
+
+   public Object getAttribute(String name)
+   {   
+      return null;
+   }
+
+   public Enumeration getAttributeNames()
+   { 
+      return null;
+   }
+
+   public String getCharacterEncoding()
+   {   
+      return null;
+   }
+
+   public int getContentLength()
+   {   
+      return 0;
+   }
+
+   public String getContentType()
+   {   
+      return null;
+   }
+
+   public ServletInputStream getInputStream() throws IOException
+   {   
+      return null;
+   }
+
+   public String getParameter(String name)
+   {   
+      return null;
+   }
+
+   public Locale getLocale()
+   {   
+      return null;
+   }
+
+   public Enumeration getLocales()
+   {   
+      return null;
+   }
+
+   public Map getParameterMap()
+   {   
+      return null;
+   }
+
+   public Enumeration getParameterNames()
+   {   
+      return null;
+   }
+
+   public String[] getParameterValues(String name)
+   {   
+      return null;
+   }
+
+   public String getProtocol()
+   {   
+      return null;
+   }
+
+   public String getScheme()
+   {   
+      return null;
+   }
+
+   public String getServerName()
+   {   
+      return null;
+   }
+
+   public int getServerPort()
+   {   
+      return 0;
+   }
+
+   public BufferedReader getReader() throws IOException
+   {   
+      return null;
+   }
+
+   public String getRemoteAddr()
+   {   
+      return null;
+   }
+
+   public String getRemoteHost()
+   {   
+      return null;
+   }
+
+   public void setAttribute(String name, Object o)
+   {   
+   }
+
+   public void removeAttribute(String name)
+   {   
+   }
+
+   public boolean isSecure()
+   {   
+      return false;
+   }
+
+   public RequestDispatcher getRequestDispatcher(String path)
+   {   
+      return null;
+   }
+
+   public String getRealPath(String path)
+   {   
+      return null;
+   }
+
+   public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException
+   {   
+   }
+
+   public String getAuthType()
+   {   
+      return null;
+   }
+
+   public Cookie[] getCookies()
+   {   
+      return null;
+   }
+
+   public long getDateHeader(String name)
+   {   
+      return 0;
+   }
+
+   public String getHeader(String name)
+   {   
+      return headers.get(name);
+   }
+
+   public Enumeration getHeaders(String name)
+   {    
+      return null;
+   }
+
+   public Enumeration getHeaderNames()
+   {   
+      return null;
+   }
+
+   public int getIntHeader(String name)
+   {   
+      return 0;
+   }
+
+   public String getMethod()
+   {   
+      return null;
+   }
+
+   public String getPathInfo()
+   {   
+      return null;
+   }
+
+   public String getPathTranslated()
+   {   
+      return null;
+   }
+
+   public String getContextPath()
+   {   
+      return null;
+   }
+
+   public String getQueryString()
+   {   
+      return null;
+   }
+
+   public String getRemoteUser()
+   {   
+      return null;
+   }
+
+   public boolean isUserInRole(String role)
+   {   
+      return false;
+   }
+
+   public Principal getUserPrincipal()
+   {   
+      return null;
+   }
+
+   public String getRequestURI()
+   {   
+      return null;
+   }
+
+   public StringBuffer getRequestURL()
+   {   
+      return null;
+   }
+
+   public String getRequestedSessionId()
+   {   
+      return null;
+   }
+
+   public String getServletPath()
+   {   
+      return null;
+   }
+
+   public HttpSession getSession(boolean create)
+   {   
+      return null;
+   }
+
+   public HttpSession getSession()
+   {   
+      return null;
+   }
+
+   public boolean isRequestedSessionIdValid()
+   { 
+      return false;
+   }
+
+   public boolean isRequestedSessionIdFromCookie()
+   { 
+      return false;
+   }
+
+   public boolean isRequestedSessionIdFromURL()
+   { 
+      return false;
+   }
+
+   public boolean isRequestedSessionIdFromUrl()
+   { 
+      return false;
+   }
+
+   public int getRemotePort()
+   {
+      return 0;
+   }
+}
\ No newline at end of file

Added: integration-tests/trunk/picketlink-trust-tests/src/test/resources/test-binary-handlers.xml
===================================================================
--- integration-tests/trunk/picketlink-trust-tests/src/test/resources/test-binary-handlers.xml	                        (rev 0)
+++ integration-tests/trunk/picketlink-trust-tests/src/test/resources/test-binary-handlers.xml	2011-04-06 16:25:13 UTC (rev 866)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+
+<handler-chains xmlns="http://java.sun.com/xml/ns/javaee"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:ns1="http://org.jboss.ws/jaxws/samples/logicalhandler"
+  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee javaee_web_services_1_2.xsd">
+
+
+
+  <handler-chain>
+    <handler>
+      <handler-name>TestBinaryHandler</handler-name>
+      <handler-class>org.picketlink.test.trust.ws.handlers.TestBinaryHandler</handler-class>
+    </handler>
+  </handler-chain>
+
+
+</handler-chains>
\ No newline at end of file



More information about the picketlink-commits mailing list