我有一个简单的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>现在,我在春季安全性中声明,当用户想要.../hello时,必须是用户。
但是,当我尝试http://localhost:8080/hello/时,hello.jsp页面会显示出来,而不会强制进行身份验证。
当我尝试http://localhost:8080/pages/hello.jsp时,它会将我重定向到login页面,但是为什么spring安全没有注意到spring的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页面。
发布于 2015-06-06 11:30:32
我把intercept-url pattern改成了pattern="/hello/",它起作用了。
发布于 2015-06-06 10:02:07
尝试将此更改为
<security:intercept-url pattern="/pages/hello.jsp" access="hasRole('ROLE_USER')"/>至
<security:intercept-url pattern="/pages/hello*" access="hasRole('ROLE_USER')"/>在您的拦截配置中,您特别要求只检查hello.jsp而不是hello。Security不会根据您的视图解析器自动更改逻辑。
https://stackoverflow.com/questions/30676749
复制相似问题