-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ShiroUrlHelper and related Spring configuration
and related tests
- Loading branch information
Showing
12 changed files
with
190 additions
and
10 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
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
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
32 changes: 32 additions & 0 deletions
32
...n/java/org/apache/shiro/spring/config/web/autoconfigure/ShiroWebMvcAutoConfiguration.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,32 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.apache.shiro.spring.config.web.autoconfigure; | ||
|
||
import org.apache.shiro.spring.web.config.ShiroRequestMappingConfig; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; | ||
|
||
@Configuration | ||
@ConditionalOnClass(RequestMappingHandlerMapping.class) | ||
@Import(ShiroRequestMappingConfig.class) | ||
@ConditionalOnProperty(name = "shiro.web.enabled", matchIfMissing = true) | ||
public class ShiroWebMvcAutoConfiguration { } |
3 changes: 2 additions & 1 deletion
3
support/spring-boot/spring-boot-web-starter/src/main/resources/META-INF/spring.factories
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration = \ | ||
org.apache.shiro.spring.config.web.autoconfigure.ShiroWebAutoConfiguration,\ | ||
org.apache.shiro.spring.config.web.autoconfigure.ShiroWebFilterConfiguration | ||
org.apache.shiro.spring.config.web.autoconfigure.ShiroWebFilterConfiguration, \ | ||
org.apache.shiro.spring.config.web.autoconfigure.ShiroWebMvcAutoConfiguration |
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
41 changes: 41 additions & 0 deletions
41
support/spring/src/main/java/org/apache/shiro/spring/web/ShiroUrlPathHelper.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,41 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.apache.shiro.spring.web; | ||
|
||
import org.apache.shiro.web.util.WebUtils; | ||
import org.springframework.web.util.UrlPathHelper; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
/** | ||
* A Spring UrlPathHelper that uses Shiro's path resolution logic. | ||
* @since 1.7.0 | ||
*/ | ||
public class ShiroUrlPathHelper extends UrlPathHelper { | ||
|
||
@Override | ||
public String getPathWithinApplication(HttpServletRequest request) { | ||
return WebUtils.getPathWithinApplication(request); | ||
} | ||
|
||
@Override | ||
public String getPathWithinServletMapping(HttpServletRequest request) { | ||
return WebUtils.getPathWithinApplication(request); | ||
} | ||
} |
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
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
31 changes: 31 additions & 0 deletions
31
...rt/spring/src/main/java/org/apache/shiro/spring/web/config/ShiroRequestMappingConfig.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,31 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.apache.shiro.spring.web.config; | ||
|
||
import org.apache.shiro.spring.web.ShiroUrlPathHelper; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; | ||
|
||
@Configuration | ||
public class ShiroRequestMappingConfig { | ||
|
||
public ShiroRequestMappingConfig(RequestMappingHandlerMapping requestMappingHandlerMapping) { | ||
requestMappingHandlerMapping.setUrlPathHelper(new ShiroUrlPathHelper()); | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
support/spring/src/test/groovy/org/apache/shiro/spring/web/ShiroUrlPathHelperTest.groovy
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 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.apache.shiro.spring.web | ||
|
||
import org.junit.Test | ||
import org.springframework.mock.web.MockHttpServletRequest | ||
import org.springframework.web.util.UrlPathHelper | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat | ||
import static org.hamcrest.Matchers.equalTo | ||
|
||
/** | ||
* Tests a couple known differences between the stock and the ShiroUrlPathHelper | ||
*/ | ||
class ShiroUrlPathHelperTest { | ||
|
||
@Test | ||
void testGetPathWithinApplication() { | ||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo/%2e%2e") | ||
assertThat new UrlPathHelper().getPathWithinApplication(request), equalTo("/foo/..") | ||
assertThat new ShiroUrlPathHelper().getPathWithinApplication(request), equalTo("/") | ||
} | ||
|
||
@Test | ||
void testGetPathWithinServletMapping() { | ||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo/%2e%2e") | ||
assertThat new UrlPathHelper().getPathWithinServletMapping(request), equalTo("/foo/..") | ||
assertThat new ShiroUrlPathHelper().getPathWithinServletMapping(request), equalTo("/") | ||
} | ||
} |