forked from ocpsoft/rewrite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes Issue ocpsoft#111 - Container based security broken when Rewrit…
…e is installed
- Loading branch information
1 parent
11b29fb
commit 92e67ee
Showing
7 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...vlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/container/ContainerSecurityTest.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,68 @@ | ||
/* | ||
* Copyright 2011 <a href="mailto:[email protected]">Lincoln Baxter, III</a> | ||
* | ||
* 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. | ||
*/ | ||
package org.ocpsoft.rewrite.servlet.container; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.apache.http.client.methods.HttpGet; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.ocpsoft.rewrite.config.ConfigurationProvider; | ||
import org.ocpsoft.rewrite.servlet.ServletRoot; | ||
import org.ocpsoft.rewrite.test.HttpAction; | ||
import org.ocpsoft.rewrite.test.RewriteTest; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Lincoln Baxter, III</a> | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class ContainerSecurityTest extends RewriteTest | ||
{ | ||
@Deployment(testable = false) | ||
public static WebArchive getDeployment() | ||
{ | ||
WebArchive deployment = RewriteTest.getDeployment() | ||
.addPackages(true, ServletRoot.class.getPackage()) | ||
.addAsWebInfResource("org/ocpsoft/rewrite/servlet/container/web.xml") | ||
.addAsWebResource("org/ocpsoft/rewrite/servlet/container/login.html") | ||
.addAsWebResource("org/ocpsoft/rewrite/servlet/container/login-fail.html") | ||
.addAsWebResource("org/ocpsoft/rewrite/servlet/container/home.html", "/user/home.html") | ||
.addAsServiceProvider(ConfigurationProvider.class, ContainerSecurityTestProvider.class); | ||
|
||
System.out.println(deployment.toString(true)); | ||
|
||
return deployment; | ||
} | ||
|
||
@Test | ||
public void testContainerSecurityFunctionsWithRewriteJoin() throws Exception | ||
{ | ||
HttpAction<HttpGet> action = get("/user/home"); | ||
Assert.assertEquals(200, action.getResponse().getStatusLine().getStatusCode()); | ||
Assert.assertTrue(action.getResponseContent().contains("LOGIN PAGE")); | ||
} | ||
|
||
@Test | ||
public void testContainerSecurityFunctionsWithRewriteUnHandled() throws Exception | ||
{ | ||
HttpAction<HttpGet> action = get("/user/x"); | ||
Assert.assertEquals(200, action.getResponse().getStatusLine().getStatusCode()); | ||
Assert.assertTrue(action.getResponseContent().contains("LOGIN PAGE")); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ts/src/test/java/org/ocpsoft/rewrite/servlet/container/ContainerSecurityTestProvider.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,46 @@ | ||
/* | ||
* Copyright 2011 <a href="mailto:[email protected]">Lincoln Baxter, III</a> | ||
* | ||
* 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. | ||
*/ | ||
package org.ocpsoft.rewrite.servlet.container; | ||
|
||
import javax.servlet.ServletContext; | ||
|
||
import org.ocpsoft.rewrite.config.Configuration; | ||
import org.ocpsoft.rewrite.config.ConfigurationBuilder; | ||
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider; | ||
import org.ocpsoft.rewrite.servlet.config.rule.Join; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Lincoln Baxter, III</a> | ||
* | ||
*/ | ||
public class ContainerSecurityTestProvider extends HttpConfigurationProvider | ||
{ | ||
@Override | ||
public int priority() | ||
{ | ||
return 0; | ||
} | ||
|
||
@Override | ||
public Configuration getConfiguration(final ServletContext context) | ||
{ | ||
Configuration config = ConfigurationBuilder.begin() | ||
.addRule(Join.path("/user/home").to("/user/home.html")); | ||
|
||
return config; | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
impl-servlet-tests/src/test/resources/org/ocpsoft/rewrite/servlet/container/home.html
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 @@ | ||
USER HOME |
1 change: 1 addition & 0 deletions
1
impl-servlet-tests/src/test/resources/org/ocpsoft/rewrite/servlet/container/login-fail.html
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 @@ | ||
LOGIN FAIL |
1 change: 1 addition & 0 deletions
1
impl-servlet-tests/src/test/resources/org/ocpsoft/rewrite/servlet/container/login.html
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 @@ | ||
LOGIN PAGE |
42 changes: 42 additions & 0 deletions
42
impl-servlet-tests/src/test/resources/org/ocpsoft/rewrite/servlet/container/web.xml
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,42 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | ||
version="3.0"> | ||
|
||
<security-role> | ||
<description>Administrators</description> | ||
<role-name>admin</role-name> | ||
</security-role> | ||
<security-role> | ||
<description>Users</description> | ||
<role-name>user</role-name> | ||
</security-role> | ||
<security-constraint> | ||
<web-resource-collection> | ||
<web-resource-name>General</web-resource-name> | ||
<url-pattern>/user/*</url-pattern> | ||
<http-method>DELETE</http-method> | ||
<http-method>GET</http-method> | ||
<http-method>POST</http-method> | ||
<http-method>PUT</http-method> | ||
<http-method>HEAD</http-method> | ||
<http-method>TRACE</http-method> | ||
<http-method>OPTIONS</http-method> | ||
</web-resource-collection> | ||
<auth-constraint> | ||
<role-name>user</role-name> | ||
</auth-constraint> | ||
<user-data-constraint> | ||
<transport-guarantee>NONE</transport-guarantee> | ||
</user-data-constraint> | ||
</security-constraint> | ||
|
||
<login-config> | ||
<auth-method>FORM</auth-method> | ||
<form-login-config> | ||
<form-login-page>/login.html</form-login-page> | ||
<form-error-page>/login-fail.html</form-error-page> | ||
</form-login-config> | ||
</login-config> | ||
</web-app> |
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