0

Spring Web アプリケーションのカスタム ログイン ページを作成しようとすると問題が発生します。

デフォルトのログインフォームは正常に機能します。しかし、追加すると

**<form-login login-page="/login"  />**

アプリはエラーなしで実行されますが、「ページを表示できません」と表示されます。

何かアイデアはありますか?ありがとう

これが私のweb.xmlです

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>testweb</display-name>

    <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>

    <!--
      - Loads the root application context of this web app at startup.
    -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

     <!--
      - Location of the XML file that defines the root application context
      - Applied by ContextLoaderListener.
      -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
           /WEB-INF/applicationContext-security.xml
        </param-value>
    </context-param>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <load-on-startup>1</load-on-startup>
    </servlet>       

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


</web-app>

ここに私の春の設定ファイルがあります

    <?xml version="1.0" encoding="UTF-8"?>
     <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:mvc="http://www.springframework.org/schema/mvc"

    xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Scans within the base package of the application for @Components to configure as beans -->
    <!-- @Controller, @Service, @Configuration, etc. -->
    <context:component-scan base-package="myPACKAGE" />
   <!-- Enables the Spring MVC @Controller programming model -->
    <mvc:annotation-driven />


 <!-- Resolve logical view names to .jsp resources in the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>
 </beans>

これが私の春のセキュリティファイルです

<?xml version="1.0" encoding="UTF-8"?>
 <beans:beans xmlns:beans="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns="http://www.springframework.org/schema/security"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
 http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
">

    <http auto-config="true">
        <intercept-url pattern="/*" access="ROLE_USER" />
        **<form-login login-page="/login"  />**

    </http>

    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="myuser" password="mypwd" authorities="ROLE_USER" />
            </user-service>
        </authentication-provider>
    </authentication-manager>

</beans:beans>

カスタム ログイン ページは、WEB-INF/views/login.jsp 内の login.jsp です。

4

4 に答える 4

1

匿名ユーザーにログイン ページへのアクセスを許可する必要があります。次のスニペットをhttp要素に追加します

<intercept-url pattern="/login*" access="IS_AUTHENTICATED_ANONYMOUSLY" />

編集。順序は問題です。次の行のに挿入する必要があります。

<intercept-url pattern="/*" access="ROLE_USER" />
于 2013-01-14T12:39:35.807 に答える
0
  1. あなたのログイン-それは何ですか?HTML?JSP?/ loginだけでなく、ログインページのURI(例:/login.html)を記述する必要があります。

  2. ログインページを、匿名ユーザーが表示できるようにするサブディレクトリ(例:/ login)に配置してみてください。

<http pattern = "/ login / **" security = "none" />

その後

<security:form-login 
    login-page="/login/login.jsp" 
        ...
于 2013-01-14T12:11:52.337 に答える
0

spring を使用していると言ったので、spring-mvc を使用していると仮定します。

<!-- selects a static view for rendering without the need for an explicit controller -->
<mvc:view-controller path="/login"  view-name="login"/>

webmvc 構成に。

また、追加できるログインページのマッピングを変更するには

<definition extends="default" name="/login">
    <put-attribute name="body" value="/WEB-INF/views/login.jspx"/>
</definition>
于 2013-01-14T12:18:48.330 に答える
0

これでいいと思います。

   <intercept-url pattern="/login.htm" access="permitAll()"/>
   <form-login login-page="/login.htm"                    
               authentication-failure-url = "/positionViewer/login.htm?login_error=1" />
于 2013-04-05T05:13:09.683 に答える