1

まず、これが重複している場合は、誰かが指摘してください。しかし、現在、この質問をした人を見つけることができません。私はこの春のセキュリティ構成を持っています:

<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans-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="/admin/**" access="ROLE_ADMIN" />
        <form-login login-page="/login.htm" default-target-url="/admin/adminDashboard.htm"
            authentication-failure-url="/loginfailed" />
        <logout logout-success-url="/logout.htm" />
    </http>

    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="admin" password="123" authorities="ROLE_ADMIN" />
            </user-service>
        </authentication-provider>
    </authentication-manager>

</beans:beans>

つまり、このコントローラー:

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class AdministrationController {
    @RequestMapping(value = "/login.htm", method = RequestMethod.GET)
    public String login() {
        return "login";

    }

    @RequestMapping(value = "/admin/banAppealsList.htm", method = RequestMethod.GET)
    public String banAppealsList() {
        return "banAppealsList";

    }

    @RequestMapping(value = "/admin/adminDashboard.htm", method = RequestMethod.GET)
    public String adminDashboard() {
        return "adminDashboard";

    }
}

ご覧のとおり、/admin/**URL をインターセプトします。ログに記録すると、ページにリダイレクトされadminDashboard.jspます。しかし、私が直面している問題はadminDashboard.jsp、資格情報を求められずに自分のページから他の保護されたページにリダイレクトする方法ですか? 基本的に、続行したい場合はbanAppealsList.htm、資格情報を再度要求されます。

編集:

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

    <!-- The definition of the Root Spring Container shared by all Servlets 
        and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        /WEB-INF/spring/root-context.xml
        /WEB-INF/security-context.xml
        </param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <!-- Define a filter to enable Spring Security, be sure to use the suggested 
        name 'springSecurityFilterChain' -->
    <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>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>banAppeal.htm</welcome-file>
    </welcome-file-list>

    <session-config>
        <session-timeout>60</session-timeout>
            <!-- Obviously, problem was here -->
        <cookie-config>
            <secure>true</secure>
        </cookie-config>
    </session-config>

</web-app>
4

2 に答える 2

1

ログイン中のステータスは、セッションに保存する必要があります。これはあなたには起こらないので、SpringSecurityFilterChain をセッションに格納するコンポーネントであるため、SpringSecurityFilterChain を正しく構成していないと思われます。

これについて web.xml に記載する必要があります

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

編集:後から考えると、問題は実際にはSpring Securityに関連していませんでしたが、セッションCookieをセキュアに設定したという事実に関連しています。つまり、セキュアでないURLでは機能しません-> http URLが使用されるたびに新しいセッション使用済み。しかし、答えがweb.xmlから問題をチェックする際に正しい方向に進んでくれたことをうれしく思います。

于 2013-11-10T15:28:45.607 に答える
0

同じセッションからページが要求されたときに、ある種のセッションを使用する必要があると思います。魔女は資格情報を保存し、サーバーはそれらをチェックします。私はこのフレームワークを使用していませんが、play フレームワークを使用しました。witch にはセッションがありませんが、cookie を処理できます。witch を使用してこれらのセッションを作成できます。

于 2013-11-10T13:45:10.753 に答える