2012-01-25 24 views
2

私のWebアプリケーションには、複数の認証マネージャがあります(WEBアクセスのAPIは1つです)。私はそれが子供豆のconfigsによってoverrideableになりたいので、私は、認証プロバイダをインラインすることはできませんスプリングセキュリティ - 複数の認証プロバイダ

<?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:security="http://www.springframework.org/schema/security" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

    <security:authentication-manager alias="apiAuthenticationManager"> 
     <security:authentication-provider ref="apiAuthenticationProvider" /> 
    </security:authentication-manager> 

    <security:authentication-provider > 
     <security:user-service> 
      <security:user name="apiadmin" password="password" authorities="ROLE_API_ADMIN" /> 
      <security:user name="apiuser" password="otherpassword" authorities="ROLE_API_USER" /> 
     </security:user-service> 
    </security:authentication-provider> 
... 

:下図のように春のセキュリティマークアップを介して設定 - APIは基本的な認証サービスを持っている必要があります。

私の問題は、security:authentication-provider要素でエイリアス/ IDを定義して、authentication-managerでそれを参照できないということです。この簡単な回避策はありますか?

ソリューション:

私は最終的にプレーンな豆の設定にダイビングせずに、名前空間ウェイを使用してそれを行う方法を考え出した:)

<security:user-service id="apiUserDetailsService"> 
    <security:user name="apiadmin" password="password" authorities="ROLE_API_ADMIN" /> 
    <security:user name="apiuser" password="otherpassword" authorities="ROLE_API_USER" /> 
    </security:user-service> 

<security:authentication-manager alias="apiAuthenticationManager"> 
    <security:authentication-provider user-service-ref="apiUserDetailsService"/> 
</security:authentication-manager> 

答えて

4

この春のセキュリティXML名前空間ということを覚えておいてください。 XMLを整理するうえでの単なる方法です。プレーンな<bean> configと全く同じソリューションを実現することができます。そうすれば、いつものようにIDを使うことができます。 This blog postが役に立ちます。

0

名前空間では、javaの名前に@Service("userDetailsService")という名前を付けて名前を付け加えることができます。

また、Beanを定義してチェーンに追加することもできます。

<bean id="myFilter" class="a.b.c.myFilter"> 
    <security:custom-filter before="BASIC_PROCESSING_FILTER" /> 
    <property name="authenticationManager" ref="_authenticationManager" /> 
</bean> 
<bean id="myProvider" class="a.b.c.myProvider"> 
    <security:custom-authentication-provider /> 
    <property name="userDetailsService" ref="userDetailsService" /> 
</bean> 

<security:http> 
    [...] 
</security:http> 

_authenticationManagerは、namespaceに登録されているBeanの名前です。

これは基本的な認証の前に実行されます。

関連する問題