-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[resolves #2605] Test CXF RS endpoints with Elytron
- Loading branch information
Showing
14 changed files
with
712 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
...st/java/org/wildfly/camel/test/cxf/rs/secure/CXFRSBasicSecureProducerIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* #%L | ||
* Wildfly Camel :: Testsuite | ||
* %% | ||
* Copyright (C) 2013 - 2014 RedHat | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
package org.wildfly.camel.test.cxf.rs.secure; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.as.arquillian.api.ServerSetup; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.wildfly.camel.test.common.security.BasicSecurityDomainASetup; | ||
import org.wildfly.camel.test.common.security.SecurityUtils; | ||
import org.wildfly.camel.test.common.utils.EnvironmentUtils; | ||
import org.wildfly.camel.test.cxf.rs.secure.subA.Application; | ||
import org.wildfly.camel.test.cxf.rs.secure.subA.CxfRsRouteBuilder; | ||
import org.wildfly.extension.camel.CamelAware; | ||
|
||
/** | ||
* @author <a href="https://github.com/ppalaga">Peter Palaga</a> | ||
*/ | ||
@CamelAware | ||
@RunAsClient | ||
@RunWith(Arquillian.class) | ||
@ServerSetup(BasicSecurityDomainASetup.class) | ||
public class CXFRSBasicSecureProducerIntegrationTest { | ||
public static final String APP_NAME = "CXFRSBasicSecureProducerIntegrationTest"; | ||
private static final Map<String, String> PATH_ROLE_MAP = new LinkedHashMap<String, String>() { | ||
private static final long serialVersionUID = 1L; | ||
{ | ||
try { | ||
put("//" + new URI(Application.CXF_ENDPOINT_URI).getPath(), | ||
BasicSecurityDomainASetup.APPLICATION_ROLE); | ||
put("//" + new URI(Application.CXF_ENDPOINT_SUB_URI).getPath(), | ||
BasicSecurityDomainASetup.APPLICATION_ROLE_SUB); | ||
put(new URI(Application.CXF_ENDPOINT_REL_URI).getPath().substring(("/"+APP_NAME).length()), | ||
BasicSecurityDomainASetup.APPLICATION_ROLE_REL); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}; | ||
|
||
@Deployment | ||
public static Archive<?> deployment() { | ||
final WebArchive archive = ShrinkWrap | ||
.create(WebArchive.class, APP_NAME + ".war") | ||
.addClasses(BasicSecurityDomainASetup.class, CXFRSSecureUtils.class) | ||
.addPackage(CxfRsRouteBuilder.class.getPackage()) | ||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") | ||
; | ||
SecurityUtils.enhanceArchive(archive, BasicSecurityDomainASetup.SECURITY_DOMAIN, | ||
BasicSecurityDomainASetup.AUTH_METHOD, PATH_ROLE_MAP); | ||
return archive; | ||
} | ||
|
||
@Test | ||
public void greetAnonymous() throws Exception { | ||
CXFRSSecureUtils.assertGreet(EnvironmentUtils.getWildFlyHome(), Application.CXF_ENDPOINT_URI, null, null, 401, null); | ||
} | ||
|
||
|
||
@Test | ||
public void greetAnonymousSub() throws Exception { | ||
CXFRSSecureUtils.assertGreet(EnvironmentUtils.getWildFlyHome(), Application.CXF_ENDPOINT_SUB_URI, null, null, 401, | ||
null); | ||
} | ||
|
||
@Test | ||
public void greetBasicBadUser() throws Exception { | ||
CXFRSSecureUtils.assertGreet(EnvironmentUtils.getWildFlyHome(), Application.CXF_ENDPOINT_URI, | ||
BasicSecurityDomainASetup.APPLICATION_USER_SUB, BasicSecurityDomainASetup.APPLICATION_PASSWORD_SUB, 403, | ||
null); | ||
} | ||
|
||
@Test | ||
public void greetBasicGoodUser() throws Exception { | ||
CXFRSSecureUtils.assertGreet(EnvironmentUtils.getWildFlyHome(), Application.CXF_ENDPOINT_URI, | ||
BasicSecurityDomainASetup.APPLICATION_USER, BasicSecurityDomainASetup.APPLICATION_PASSWORD, 200, | ||
"Hi Joe"); | ||
} | ||
|
||
@Test | ||
public void greetBasicSubBadUser() throws Exception { | ||
CXFRSSecureUtils.assertGreet(EnvironmentUtils.getWildFlyHome(), Application.CXF_ENDPOINT_SUB_URI, | ||
BasicSecurityDomainASetup.APPLICATION_USER, BasicSecurityDomainASetup.APPLICATION_PASSWORD, 403, null); | ||
} | ||
|
||
@Test | ||
public void greetBasicSubGoodUser() throws Exception { | ||
CXFRSSecureUtils.assertGreet(EnvironmentUtils.getWildFlyHome(), Application.CXF_ENDPOINT_SUB_URI, | ||
BasicSecurityDomainASetup.APPLICATION_USER_SUB, BasicSecurityDomainASetup.APPLICATION_PASSWORD_SUB, 200, | ||
"Hi Joe"); | ||
} | ||
|
||
@Test | ||
public void greetBasicRelBadUser() throws Exception { | ||
CXFRSSecureUtils.assertGreet(EnvironmentUtils.getWildFlyHome(), Application.CXF_ENDPOINT_REL_URI, | ||
BasicSecurityDomainASetup.APPLICATION_USER_SUB, BasicSecurityDomainASetup.APPLICATION_PASSWORD_SUB, 403, null); | ||
} | ||
|
||
@Test | ||
public void greetBasicRelGoodUser() throws Exception { | ||
CXFRSSecureUtils.assertGreet(EnvironmentUtils.getWildFlyHome(), Application.CXF_ENDPOINT_REL_URI, | ||
BasicSecurityDomainASetup.APPLICATION_USER_REL, BasicSecurityDomainASetup.APPLICATION_PASSWORD_REL, 200, | ||
"Hi Joe"); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...standalone/basic/src/test/java/org/wildfly/camel/test/cxf/rs/secure/CXFRSSecureUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.wildfly.camel.test.cxf.rs.secure; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Path; | ||
import java.security.KeyManagementException; | ||
import java.security.KeyStoreException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.UnrecoverableKeyException; | ||
import java.security.cert.CertificateException; | ||
import java.util.Base64; | ||
|
||
import org.apache.http.HttpEntity; | ||
import org.apache.http.HttpHeaders; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.util.EntityUtils; | ||
import org.junit.Assert; | ||
import org.wildfly.camel.test.common.security.SecurityUtils; | ||
|
||
/** | ||
* @author <a href="https://github.com/ppalaga">Peter Palaga</a> | ||
*/ | ||
public class CXFRSSecureUtils { | ||
public static final String SPRING_CONSUMER_ENDPOINT_BASE_ADDRESS = "https://localhost:8443/rest/greeting-secure-spring"; | ||
public static final String SPRING_CONSUMER_ENDPOINT_ADDRESS = SPRING_CONSUMER_ENDPOINT_BASE_ADDRESS + "/greet/hi"; | ||
|
||
static void assertGreet(Path wildFlyHome, String uri, String user, String password, int responseCode, | ||
String responseBody) throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, | ||
KeyStoreException, CertificateException, IOException { | ||
try (CloseableHttpClient httpclient = HttpClients.custom() | ||
.setSSLSocketFactory(SecurityUtils.createBasicSocketFactory(wildFlyHome)).build()) { | ||
HttpPost request = new HttpPost(uri); | ||
request.setHeader("Content-Type", "text/plain"); | ||
|
||
if (user != null) { | ||
String auth = user + ":" + password; | ||
String authHeader = "Basic " | ||
+ Base64.getEncoder().encodeToString(auth.getBytes(StandardCharsets.ISO_8859_1)); | ||
request.setHeader(HttpHeaders.AUTHORIZATION, authHeader); | ||
} | ||
|
||
request.setEntity(new StringEntity("Joe", StandardCharsets.UTF_8)); | ||
try (CloseableHttpResponse response = httpclient.execute(request)) { | ||
final int actualCode = response.getStatusLine().getStatusCode(); | ||
Assert.assertEquals(responseCode, actualCode); | ||
if (actualCode == 200) { | ||
HttpEntity entity = response.getEntity(); | ||
String body = EntityUtils.toString(entity, StandardCharsets.UTF_8); | ||
Assert.assertEquals(responseBody, body); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private CXFRSSecureUtils() {} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
...a/org/wildfly/camel/test/cxf/rs/secure/CXFRSSpringBasicSecureProducerIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* #%L | ||
* Wildfly Camel :: Testsuite | ||
* %% | ||
* Copyright (C) 2013 - 2014 RedHat | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
package org.wildfly.camel.test.cxf.rs.secure; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.as.arquillian.api.ServerSetup; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.wildfly.camel.test.common.security.BasicSecurityDomainASetup; | ||
import org.wildfly.camel.test.common.security.SecurityUtils; | ||
import org.wildfly.camel.test.common.utils.EnvironmentUtils; | ||
import org.wildfly.camel.test.cxf.rs.secure.subA.GreetingsProcessor; | ||
import org.wildfly.camel.test.cxf.rs.secure.subA.GreetingsService; | ||
import org.wildfly.extension.camel.CamelAware; | ||
|
||
/** | ||
* @author <a href="https://github.com/ppalaga">Peter Palaga</a> | ||
*/ | ||
@CamelAware | ||
@RunAsClient | ||
@RunWith(Arquillian.class) | ||
@ServerSetup(BasicSecurityDomainASetup.class) | ||
public class CXFRSSpringBasicSecureProducerIntegrationTest { | ||
private static final Map<String, String> PATH_ROLE_MAP = new LinkedHashMap<String, String>() {{ | ||
try { | ||
put("//" + new URI(CXFRSSecureUtils.SPRING_CONSUMER_ENDPOINT_ADDRESS).getPath(), BasicSecurityDomainASetup.APPLICATION_ROLE); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}}; | ||
|
||
@Deployment | ||
public static Archive<?> deployment() { | ||
final WebArchive archive = ShrinkWrap | ||
.create(WebArchive.class, CXFRSSpringBasicSecureProducerIntegrationTest.class.getSimpleName() + ".war") | ||
.addClasses(BasicSecurityDomainASetup.class, CXFRSSecureUtils.class, GreetingsService.class, | ||
GreetingsProcessor.class); | ||
SecurityUtils.addSpringXmlRs(archive, CXFRSSecureUtils.SPRING_CONSUMER_ENDPOINT_BASE_ADDRESS); | ||
SecurityUtils.enhanceArchive(archive, BasicSecurityDomainASetup.SECURITY_DOMAIN, | ||
BasicSecurityDomainASetup.AUTH_METHOD, PATH_ROLE_MAP); | ||
return archive; | ||
} | ||
|
||
@Test | ||
public void greetAnonymous() throws Exception { | ||
CXFRSSecureUtils.assertGreet(EnvironmentUtils.getWildFlyHome(), CXFRSSecureUtils.SPRING_CONSUMER_ENDPOINT_ADDRESS, null, null, 401, null); | ||
} | ||
|
||
@Test | ||
public void greetBasicGoodUser() throws Exception { | ||
CXFRSSecureUtils.assertGreet(EnvironmentUtils.getWildFlyHome(), CXFRSSecureUtils.SPRING_CONSUMER_ENDPOINT_ADDRESS, | ||
BasicSecurityDomainASetup.APPLICATION_USER, BasicSecurityDomainASetup.APPLICATION_PASSWORD, 200, | ||
"Hi Joe"); | ||
} | ||
|
||
@Test | ||
public void greetBasicBadUser() throws Exception { | ||
CXFRSSecureUtils.assertGreet(EnvironmentUtils.getWildFlyHome(), CXFRSSecureUtils.SPRING_CONSUMER_ENDPOINT_ADDRESS, | ||
BasicSecurityDomainASetup.APPLICATION_USER_SUB, BasicSecurityDomainASetup.APPLICATION_PASSWORD_SUB, 403, | ||
null); | ||
} | ||
|
||
} |
Oops, something went wrong.