【发布时间】:2015-08-21 00:10:28
【问题描述】:
我有一个简单的spring mvc + spring security 应用程序
我声明当用户尝试.../hello 时,来自/WEB-INF/pages/ 路径的hello.jsp 页面正确显示:
@RequestMapping(value = "/hello")
public ModelAndView doLogin() {
return new ModelAndView("hello");
}
dispatcher-servlet.xml:
<mvc:annotation-driven/>
<context:component-scan base-package="com"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
现在我在 Spring Security 中声明,当用户想要 .../hello 它必须成为用户。
但是当我尝试http://localhost:8080/hello/ 时,hello.jsp 页面会显示而不会强制进行身份验证。
当我尝试http://localhost:8080/pages/hello.jsp 时,它会将我重定向到login 页面,但是为什么spring security 没有注意到spring mvc 的prefix path?
更新
security-config.xml
<security:http auto-config="true" use-expressions="true">
<security:intercept-url pattern="/pages/hello.jsp" access="hasRole('ROLE_USER')"/>
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="sajjad" authorities="ROLE_USER" password="200200"/>
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
当我使用pattern="/hello" 并且用户尝试http://localhost:8080/hello/ 时,用户不会重定向到login 页面。
【问题讨论】:
标签: java spring jsp spring-mvc spring-security