6

私の要件は、次のものを提供することです。

  1. ユーザー ID パスワード ベースの認証。
  2. オープン ID ベースの認証
  3. URL ベースの認証 (カスタム sso 実装です)

同じプロジェクトで。

Spring セキュリティを次のように既存のプロジェクトにプラグインしようとしました (簡単にするためにコードを削除しました)。

<?xml version="1.0" encoding="UTF-8"?>
<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-2.0.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security-2.0.1.xsd">

    <http auto-config="false">
        <remember-me user-service-ref="rememberMeUserService" key="some custom key" /> <!-- TODO: Key made for testing reasons.... -->
        <intercept-url pattern='/mainApplication/Main screen.html' access="ROLE_ADMIN"/>
        <intercept-url pattern='/**' filters="none"/> <!-- Allow entry to login screen -->
        <openid-login authentication-failure-url="/Login.html?error=true" default-target-url="/mainApplication/Main screen.html" user-service-ref="openIdUserService"/>
        <form-login login-page="/Login.html" authentication-failure-url="/Login.html?error=true" always-use-default-target="true" default-target-url="/mainApplication/Main screen.html"/>
    </http>

    <beans:bean id="rememberMeUserService" class="mypackage.CustomUserService">
        <beans:property name="usersService" ref="usersService"></beans:property>
    </beans:bean>

    <!-- Common login shared entry-point for both Form and OpenID based logins -->    
    <beans:bean id="entryPoint" class="org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint">
        <beans:property name="loginFormUrl" value="/Login.html" />
    </beans:bean>
    <authentication-manager alias="authenticationManager"/>

    <beans:bean id="MyCustomAuthenticationProvider" class="mypackage.CustomAuthenticationProvider">
        <custom-authentication-provider />
        <beans:property name="usersService" ref="usersService"></beans:property>
    </beans:bean>

    <beans:bean id="openIdAuthenticationProvider" class="org.springframework.security.providers.openid.OpenIDAuthenticationProvider">
        <custom-authentication-provider />
        <beans:property name="userDetailsService" ref="openIdUserService"/>
    </beans:bean>

    <beans:bean id="openIdUserService" class="mypackage.OpenIDUserDetailsService">
        <beans:property name="usersService" ref="usersService"/>
    </beans:bean>

    <!-- Great, now i want to include SSO based sign on -->
    <!-- need to intercept a url of the form :   /myApp/customLogin/<key> where <key> is my token key   -->

</beans:beans>

上記のように、次の形式の URL を追跡する必要があります: /myApp/customLogin/12345 ここで、1235 はトークン キーです。最初に使用していたものです (簡単にするためにコードを省略しています)。

<servlet-mapping>
    <servlet-name>mySSOCapture</servlet-name>
    <url-pattern>/myApp/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/MyServlet</url-pattern>
</servlet-mapping>

この 3 番目の認証スキームの管理に役立つように、Spring Security を有効にするには、ここで何をすべきですか?

当然のことながら、同じプロジェクトに多くの認証プロバイダーを含めることはできますか? はいの場合、それらをさまざまな機能 (たとえば、URL ベースの認証を提供するもの、匿名認証を提供するものなど) とどのように一致させることができますか?

4

3 に答える 3

1

これを行うには、おそらくいくつかの方法があります。非常によく似た機能、つまり事前認証を行う機能がいくつかあります。これは、ユーザーを認証するカスタムフィルターを追加する方法の良い例です。その後、フレームワークの残りの部分が引き継ぐ必要があります。

What an AuthenticationProvider does is examine the Authentication object that is loaded into the session by a previous filter. You can register as many authentication providers as you want with the authentication manager (which simply runs the Authentication object through all of them), but you have to manage to get some filter in there that will handle your authentication scheme and populate the Authentication object. If you want this filter to also interact with the user (i.e. show a login form or something) it might interfere with other filters. In that case you can use separate filter chains, but this doesn't sound like it would be necessary in your case.

于 2009-11-06T13:59:54.670 に答える
1

質問に直接答えることはできませんが、ID管理セクターからの「役立つヒント」:すべての認証システムが同じ信頼値を持っているわけではありません-それらを平等に扱うことは、優れたセキュリティ設計の重大な違反です。

これがあなたのデザインに役立つことを願っています...

于 2009-11-06T02:15:56.250 に答える
1

さて、ここに解決策があります:

<beans:bean id="mySsoFilter" class="somePackage.MySsoProcessingFilter">
    <custom-filter after="CAS_PROCESSING_FILTER"/> <!-- Just a reference Point-->
    <beans:property name="authenticationManager" ref="authenticationManager"/>
    <beans:property name="defaultTargetUrl" value='/mainApplication/Main screen.html' />
    <beans:property name="authenticationFailureUrl" value="/Login.html?error=true"/>
</beans:bean>

これが困っている人に役立つことを願っています...

于 2009-11-09T09:43:32.383 に答える