Spring MVC和Security - 登录后找不到错误404页面

时间:2013-02-08 08:24:12

标签: spring security model-view-controller mapping

我需要一些Spring测试项目的帮助。我有一个简单的登录页面,带有安全检查,Spring检测好或床登录,但在重定向到login-succes页面或login-faild页面时给出404 Page not fount错误。

配置

APPLCATION CONTEXT

    <!--
    Most controllers will use the ControllerClassNameHandlerMapping above, but
    for the index controller we are using ParameterizableViewController, so we must
    define an explicit mapping for it.
    -->
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="login.htm">LoginController</prop>
            </props>
        </property>
    </bean>

    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />

    <!--
    The index controller.
    -->
    <bean name="LoginController"
          class="org.springframework.web.servlet.mvc.ParameterizableViewController"
          p:viewName="login" />

</beans>

安全

    <http auto-config="true">
        <intercept-url pattern="/welcome*" access="ROLE_USER" />
        <form-login login-page="/login" default-target-url="/welcome"
            authentication-failure-url="/loginfailed" />
        <logout logout-success-url="/logout" />
    </http>

    <authentication-manager>
      <authentication-provider>
        <user-service>
            <user name="mkyong" password="123456" authorities="ROLE_USER" />
        </user-service>
      </authentication-provider>
    </authentication-manager>

</beans:beans>

WEB.XML

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

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
<param-value>
        /WEB-INF/dispatcher-servlet.xml,
        /WEB-INF/spring-security.xml 
</param-value>
</context-param>

<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

<welcome-file-list>
    <welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>

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

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

登录控制器

@Controller

public class LoginController {

@RequestMapping(value="/welcome", method = RequestMethod.GET)
public String printWelcome(ModelMap model, Principal principal ) {

    String name = principal.getName();
    model.addAttribute("username", name);
    model.addAttribute("message", "Spring Security Custom Form example");
    return "hello";

}

@RequestMapping(value="/login", method = RequestMethod.GET)
public String login(ModelMap model) {

    return "login";

}

@RequestMapping(value="/loginfailed", method = RequestMethod.GET)
public String loginerror(ModelMap model) {

    model.addAttribute("error", "true");
    return "login";

}

@RequestMapping(value="/logout", method = RequestMethod.GET)
public String logout(ModelMap model) {

    return "login";

}

}

错误在哪里? TK。

0 个答案:

没有答案