Author: asoldano
Date: 2013-11-07 12:01:20 -0500 (Thu, 07 Nov 2013)
New Revision: 18068
Added:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpointImpl3.java
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/META-INF/
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/META-INF/jboss-webservices.xml
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/java/org/jboss/test/ws/jaxws/handlerauth/HandlerAuthTestCase.java
Log:
[JBWS-3730] Testcase
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-11-07
17:00:56 UTC (rev 18067)
+++
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/ant-import/build-jars-jaxws.xml 2013-11-07
17:01:20 UTC (rev 18068)
@@ -193,6 +193,19 @@
</fileset>
</jar>
+ <!-- jaxws-handlerauth3 -->
+ <jar destfile="${tests.output.dir}/test-libs/jaxws-handlerauth3.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/SecureEndpointImpl3.class" />
+ <include name="org/jboss/test/ws/jaxws/handlerauth/SimpleHandler.class"
/>
+ <include name="org/jboss/test/ws/jaxws/handlerauth/handlers.xml" />
+ </fileset>
+ <metainf
dir="${tests.output.dir}/test-resources/jaxws/handlerauth/META-INF">
+ <include name="jboss-webservices.xml" />
+ </metainf>
+ </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">
Modified:
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 2013-11-07
17:00:56 UTC (rev 18067)
+++
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/HandlerAuthTestCase.java 2013-11-07
17:01:20 UTC (rev 18068)
@@ -44,7 +44,7 @@
{
public static Test suite()
{
- JBossWSTestSetup testSetup = new JBossWSTestSetup(HandlerAuthTestCase.class,
"jaxws-handlerauth.jar,jaxws-handlerauth2.jar");
+ JBossWSTestSetup testSetup = new JBossWSTestSetup(HandlerAuthTestCase.class,
"jaxws-handlerauth.jar,jaxws-handlerauth2.jar,jaxws-handlerauth3.jar");
Map<String, String> authenticationOptions = new HashMap<String,
String>();
authenticationOptions.put("usersProperties",
getResourceFile("jaxws/handlerauth/jbossws-users.properties").getAbsolutePath());
@@ -68,6 +68,67 @@
testAuth(port);
}
+ public void testNoHandlerAuth() throws Exception {
+ URL wsdlURL = new URL("http://" + getServerHost() +
":8080/handlerauth3?wsdl");
+ Service service = Service.create(wsdlURL, new QName("http://ws/",
"SecureEndpointImpl3Service"));
+ SecureEndpoint port = service.getPort(new QName("http://ws/",
"SecureEndpoint3Port"), 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();
+ fail("Exception expected!");
+ } catch (Exception e) {
+ newCount = port.getHandlerCounter();
+ assertEquals(++count, newCount); //verify count is 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");
+ fail("Exception expected!");
+ } catch (Exception e) {
+ newCount = port.getHandlerCounter();
+ assertEquals(++count, newCount); //verify count is increased
+ }
+
+ try {
+ port.deniedMethod();
+ fail("Exception expected!");
+ } catch (Exception e) {
+ newCount = port.getHandlerCounter();
+ assertEquals(++count, newCount); //verify count is increased
+ }
+
+ assertEquals("foo2", port.echo("foo2"));
+ newCount = port.getHandlerCounter();
+ assertEquals(++count, newCount);
+ }
+
private void testAuth(final SecureEndpoint port) throws Exception
{
setUser((BindingProvider)port, "John", "foo");
@@ -84,6 +145,7 @@
try {
port.deniedMethod();
+ fail("Exception expected!");
} catch (Exception e) {
assertTrue(e.getMessage().contains("JBWS024094"));
newCount = port.getHandlerCounter();
@@ -108,6 +170,7 @@
try {
port.sayBye("Bob");
+ fail("Exception expected!");
} catch (Exception e) {
assertTrue(e.getMessage().contains("JBWS024094"));
newCount = port.getHandlerCounter();
@@ -116,6 +179,7 @@
try {
port.deniedMethod();
+ fail("Exception expected!");
} catch (Exception e) {
assertTrue(e.getMessage().contains("JBWS024094"));
newCount = port.getHandlerCounter();
Added:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpointImpl3.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpointImpl3.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/handlerauth/SecureEndpointImpl3.java 2013-11-07
17:01:20 UTC (rev 18068)
@@ -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 = "SecureEndpoint3", targetNamespace =
"http://ws/")
+@HandlerChain(file = "handlers.xml")
+@WebContext(contextRoot = "/handlerauth3", urlPattern = "/*",
authMethod = "BASIC", transportGuarantee = "NONE", secureWSDLAccess =
false)
+@Stateless
+@SecurityDomain("handlerauth-security-domain")
+@RolesAllowed({"user", "friend"})
+@DeclareRoles({"user", "friend"})
+public class SecureEndpointImpl3 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.get();
+ }
+
+
+ @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/SecureEndpointImpl3.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Added:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/META-INF/jboss-webservices.xml
===================================================================
---
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/META-INF/jboss-webservices.xml
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/META-INF/jboss-webservices.xml 2013-11-07
17:01:20 UTC (rev 18068)
@@ -0,0 +1,13 @@
+<?xml version="1.1" encoding="UTF-8"?>
+<webservices
+
xmlns="http://www.jboss.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ version="1.2"
+
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee">
+
+ <property>
+ <name>org.jboss.ws.cxf.disableHandlerAuthChecks</name>
+ <value>true</value>
+ </property>
+
+</webservices>
\ No newline at end of file
Property changes on:
stack/cxf/trunk/modules/testsuite/shared-tests/src/test/resources/jaxws/handlerauth/META-INF/jboss-webservices.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native