Author: asoldano
Date: 2013-09-26 14:59:00 -0400 (Thu, 26 Sep 2013)
New Revision: 17957
Added:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/HandlerAuthTestCase.java
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpoint.java
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpointImpl.java
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SimpleHandler.java
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/handlers.xml
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/jbossws-roles.properties
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/jbossws-users.properties
Modified:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/ant-import/build-jars-jaxws.xml
Log:
[WFLY-308][JBWS-3378] Adding testcase for ejb3 endpoint jaws handler method level authz
Modified:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/ant-import/build-jars-jaxws.xml
===================================================================
---
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/ant-import/build-jars-jaxws.xml 2013-09-26
18:57:24 UTC (rev 17956)
+++
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/ant-import/build-jars-jaxws.xml 2013-09-26
18:59:00 UTC (rev 17957)
@@ -173,6 +173,15 @@
</classes>
</war>
+ <!-- jaxws-handlerauth -->
+ <jar destfile="${tests.output.dir}/test-libs/jaxws-handlerauth.jar">
+ <fileset dir="${tests.output.dir}/test-classes">
+ <include
name="org/jboss/test/ws/jaxws/handlerauth/SecureEndpoint*.class" />
+ <include name="org/jboss/test/ws/jaxws/handlerauth/SimpleHandler.class"
/>
+ <include name="org/jboss/test/ws/jaxws/handlerauth/handlers.xml" />
+ </fileset>
+ </jar>
+
<!-- jaxws-handlerscope -->
<war warfile="${tests.output.dir}/test-libs/jaxws-handlerscope.war"
webxml="${tests.output.dir}/test-resources/jaxws/handlerscope/WEB-INF/web.xml">
<classes dir="${tests.output.dir}/test-classes">
Added:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/HandlerAuthTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/HandlerAuthTestCase.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/HandlerAuthTestCase.java 2013-09-26
18:59:00 UTC (rev 17957)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.jboss.test.ws.jaxws.handlerauth;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+
+import junit.framework.Test;
+
+import org.jboss.wsf.test.JBossWSTest;
+import org.jboss.wsf.test.JBossWSTestSetup;
+
+/**
+ * Test proper handler auth
+ *
+ * @author Alessio Soldano
+ * @since 24-Sep-2013
+ */
+public class HandlerAuthTestCase extends JBossWSTest
+{
+ public static Test suite()
+ {
+ JBossWSTestSetup testSetup = new JBossWSTestSetup(HandlerAuthTestCase.class,
"jaxws-handlerauth.jar");
+ Map<String, String> authenticationOptions = new HashMap<String,
String>();
+ authenticationOptions.put("usersProperties",
+
getResourceFile("jaxws/handlerauth/jbossws-users.properties").getAbsolutePath());
+ authenticationOptions.put("rolesProperties",
+
getResourceFile("jaxws/handlerauth/jbossws-roles.properties").getAbsolutePath());
+ testSetup.addSecurityDomainRequirement("handlerauth-security-domain",
authenticationOptions);
+ return testSetup;
+ }
+
+ public void testAuth() throws Exception
+ {
+ URL wsdlURL = new URL("http://" + getServerHost() +
":8080/handlerauth?wsdl");
+ Service service = Service.create(wsdlURL, new QName("http://ws/",
"SecureEndpointImplService"));
+ SecureEndpoint port = service.getPort(new QName("http://ws/",
"SecureEndpointPort"), SecureEndpoint.class);
+
+ setUser((BindingProvider)port, "John", "foo");
+ int count = port.getHandlerCounter();
+ int newCount;
+
+ assertEquals("Hello, Mr. John", port.sayHello("John"));
+ newCount = port.getHandlerCounter();
+ assertEquals(++count, newCount);
+
+ assertEquals("Bye, Mr. John", port.sayBye("John"));
+ newCount = port.getHandlerCounter();
+ assertEquals(++count, newCount);
+
+ try {
+ port.deniedMethod();
+ } catch (Exception e) {
+ assertTrue(e.getMessage().contains("JBWS024094"));
+ newCount = port.getHandlerCounter();
+ assertEquals(count, newCount); //verify count is *not* increased
+ }
+
+ port.ping();
+ newCount = port.getHandlerCounter();
+ assertEquals(++count, newCount);
+
+ assertEquals("foo", port.echo("foo"));
+ newCount = port.getHandlerCounter();
+ assertEquals(++count, newCount);
+
+
+ //Change user...
+ setUser((BindingProvider)port, "Bob", "bar");
+
+ assertEquals("Hello, Mr. Bob", port.sayHello("Bob"));
+ newCount = port.getHandlerCounter();
+ assertEquals(++count, newCount);
+
+ try {
+ port.sayBye("Bob");
+ } catch (Exception e) {
+ assertTrue(e.getMessage().contains("JBWS024094"));
+ newCount = port.getHandlerCounter();
+ assertEquals(count, newCount); //verify count is *not* increased
+ }
+
+ try {
+ port.deniedMethod();
+ } catch (Exception e) {
+ assertTrue(e.getMessage().contains("JBWS024094"));
+ newCount = port.getHandlerCounter();
+ assertEquals(count, newCount); //verify count is *not* increased
+ }
+
+ try {
+ port.ping();
+ } catch (Exception e) {
+ assertTrue(e.getMessage().contains("JBWS024094"));
+ newCount = port.getHandlerCounter();
+ assertEquals(count, newCount); //verify count is *not* increased
+ }
+
+ assertEquals("foo2", port.echo("foo2"));
+ newCount = port.getHandlerCounter();
+ assertEquals(++count, newCount);
+ }
+
+ private static void setUser(BindingProvider bp, String username, String password) {
+ bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
+ bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
+ }
+}
Property changes on:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/HandlerAuthTestCase.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Added:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpoint.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpoint.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpoint.java 2013-09-26
18:59:00 UTC (rev 17957)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, 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.jboss.test.ws.jaxws.handlerauth;
+
+import javax.jws.Oneway;
+import javax.jws.WebService;
+
+@WebService(targetNamespace = "http://ws/")
+public interface SecureEndpoint
+{
+ String sayHello(String name);
+
+ String sayBye(String name);
+
+ int getHandlerCounter();
+
+ @Oneway
+ void ping();
+
+ void deniedMethod();
+
+ String echo(String s);
+}
\ No newline at end of file
Property changes on:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpoint.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Added:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpointImpl.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpointImpl.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpointImpl.java 2013-09-26
18:59:00 UTC (rev 17957)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, 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.jboss.test.ws.jaxws.handlerauth;
+
+import javax.jws.Oneway;
+import javax.jws.WebService;
+import javax.ejb.Stateless;
+import javax.annotation.security.DeclareRoles;
+import javax.annotation.security.DenyAll;
+import javax.annotation.security.PermitAll;
+import javax.annotation.security.RolesAllowed;
+
+import javax.jws.WebMethod;
+
+import java.util.Enumeration;
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.jws.HandlerChain;
+import javax.xml.soap.SOAPMessage;
+import javax.annotation.PostConstruct;
+
+import java.io.PrintStream;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.ws.api.annotation.WebContext;
+import org.jboss.ejb3.annotation.SecurityDomain;
+import org.jboss.logging.Logger;
+
+@WebService(name = "SecureEndpoint", targetNamespace = "http://ws/")
+@HandlerChain(file = "handlers.xml")
+@WebContext(contextRoot = "/handlerauth", urlPattern = "/*",
authMethod = "BASIC", transportGuarantee = "NONE", secureWSDLAccess =
false)
+@Stateless
+@SecurityDomain("handlerauth-security-domain")
+@RolesAllowed({"user", "friend"})
+@DeclareRoles({"user", "friend"})
+public class SecureEndpointImpl implements SecureEndpoint
+{
+ private Logger log = Logger.getLogger(this.getClass());
+
+ @Resource
+ WebServiceContext context;
+
+ @RolesAllowed("user")
+ public String sayHello(String name)
+ {
+ String principalName = context.getUserPrincipal().getName();
+ if (principalName.equals(name)) {
+ log.info("sayHello() invoked : Hello, Mr. " + name);
+ return "Hello, Mr. " + name;
+ } else {
+ return "Mr. " + name + ", you authenticated as \'" +
principalName + "\'";
+ }
+ }
+
+ @RolesAllowed("friend")
+ public String sayBye(String name)
+ {
+ String principalName = context.getUserPrincipal().getName();
+ if (principalName.equals(name)) {
+ log.info("sayBye() invoked : Bye, Mr. " + name);
+ return "Bye, Mr. " + name;
+ } else {
+ return "Mr. " + name + ", you authenticated as \'" +
principalName + "\'";
+ }
+ }
+
+ public int getHandlerCounter() {
+ return SimpleHandler.counter;
+ }
+
+
+ @Oneway
+ @RolesAllowed("friend")
+ public void ping() {
+ //NOOP
+ }
+
+ @DenyAll
+ public void deniedMethod() {
+ //NOOP
+ }
+
+ @PermitAll
+ public String echo(String s) {
+ return s;
+ }
+}
Property changes on:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpointImpl.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Added:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SimpleHandler.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SimpleHandler.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SimpleHandler.java 2013-09-26
18:59:00 UTC (rev 17957)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, 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.jboss.test.ws.jaxws.handlerauth;
+
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+public class SimpleHandler implements SOAPHandler<SOAPMessageContext>
+{
+ public static volatile int counter = 0;
+
+ @Override
+ public boolean handleMessage(SOAPMessageContext context)
+ {
+ Boolean isOutbound = (Boolean)
context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ String operation = ((QName)
context.get(MessageContext.WSDL_OPERATION)).getLocalPart();
+ if (!isOutbound && !operation.equals("getHandlerCounter")) {
+ counter++;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean handleFault(SOAPMessageContext context)
+ {
+ return true;
+ }
+
+ @Override
+ public void close(MessageContext context)
+ {
+ //NOOP
+ }
+
+ @Override
+ public Set<QName> getHeaders()
+ {
+ return null;
+ }
+
+}
Property changes on:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SimpleHandler.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Added:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/handlers.xml
===================================================================
---
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/handlers.xml
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/handlers.xml 2013-09-26
18:59:00 UTC (rev 17957)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<handler-chains
xmlns="http://java.sun.com/xml/ns/javaee">
+ <handler-chain>
+ <handler>
+ <handler-name>SimpleHandler</handler-name>
+
<handler-class>org.jboss.test.ws.jaxws.handlerauth.SimpleHandler</handler-class>
+ </handler>
+ </handler-chain>
+</handler-chains>
\ No newline at end of file
Property changes on:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/handlers.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Added:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/jbossws-roles.properties
===================================================================
---
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/jbossws-roles.properties
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/jbossws-roles.properties 2013-09-26
18:59:00 UTC (rev 17957)
@@ -0,0 +1,3 @@
+# A sample roles.properties file for use with the UsersRolesLoginModule
+Bob=user
+John=user,friend
\ No newline at end of file
Property changes on:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/jbossws-roles.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Added:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/jbossws-users.properties
===================================================================
---
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/jbossws-users.properties
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/jbossws-users.properties 2013-09-26
18:59:00 UTC (rev 17957)
@@ -0,0 +1,3 @@
+# A sample users.properties file for use with the UsersRolesLoginModule
+John=foo
+Bob=bar
\ No newline at end of file
Property changes on:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/jbossws-users.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native