0

正如标题所暗示的那样,我在简单的 Spring Security 测试中遇到了一些小问题。这是我的项目结构(maven webapp 2.5):

main
 java
   de
     cochu
       spring
         controller
           HomeController
webapp
  WEB-INF
    jsp
      home.jsp
      index.jsp
    security-context.xml
    spring-servlet.xml
    web.xml

web.xml:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/security-context.xml
    </param-value>
</context-param>

<filter>
    <filter-name>filterChainProxy</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>filterChainProxy</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/spring/*</url-pattern>
</servlet-mapping>

spring-servlet.xml

<context:annotation-config/>
<context:component-scan base-package="de.cochu.spring.controller"/>

<bean id="internalViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

安全上下文.xml

<security:http auto-config="true" use-expressions="true">
    <security:intercept-url pattern="/**" access="ROLE_USER"/>
</security:http>

<security:authentication-manager>
    <security:authentication-provider>
        <security:user-service>
            <security:user name="test" password="test" authorities="ROLE_USER"/>
        </security:user-service>
    </security:authentication-provider>
</security:authentication-manager>

家庭控制器.java

@Controller
@RequestMapping( "/" )
public class HomeController {

    @RequestMapping( method = RequestMethod.GET )
    public String show() {
        return "index";
    }

    @RequestMapping( value = "/secure", method = RequestMethod.GET )
    public String secure() {
        return "home";
    }
}

确切的问题:没有登录表单或任何正在打开的表单。它只是显示页面。我尝试了几乎所有 url-pattern 组合/intercept-url 组合,但没有任何反应。怎么了?

4

1 回答 1

7

FilterChainProxybean 已使用别名注册,因此springSecurityFilterChain请尝试修改您的 web.xml 并更改它

<filter>
    <filter-name>filterChainProxy</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

对此

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

这是我通常使用的配置(使用spring security 3.1.0.RELEASE)

于 2012-05-03T07:51:14.567 回答