2011-11-17 9 views
3

XMLでSpring Securityを設定しようとしましたが、動作しないようです。ここで私はこれまで持っているものです:私が見つけたXMLでSpring Security 3の設定

<?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:mvc="http://www.springframework.org/schema/mvc" 
     xmlns:security="http://www.springframework.org/schema/security" 
     xsi:schemaLocation="http://www.springframework.org/schema/mvc 
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
          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.0.xsd"> 

    [...] 

    <security:http auto-config="true"> 
     <security:intercept-url pattern="/**" access="ROLE_USER" /> 
     <security:http-basic /> 
    </security:http> 

    <security:authentication-manager> 
     <security:authentication-provider> 
      [???] <!-- What goes here? --> 
     </security:authentication-provider> 
    </security:authentication-manager> 

</beans> 

すべてのチュートリアルでは、私はプレースホルダで<user-service>を入れたいように見えるが、NetBeansはオートコンプリートその要素にしません。その要素に似ているのはany-user-serviceですが、わかっている限り、「抽象的な」要素です。

ユーザーとパスワードのメモリ内リストを構成するだけです。 Spring Securityバージョン3ではどうしたらいいですか?

答えて

2
<security:authentication-manager> 
    <security:authentication-provider user-service-ref="userService"> 
</security:authentication-provider> 

<bean id="userService" class="path.to.your.implementation.of.UserDetailsService" /> 

か、メモリ認証(代わりに、同様)で基本を持つことができます。

<security:authentication-manager> 
    <security:authentication-provider user-service-ref="userService"> 
    </security:authentication-provider> 
    <security:authentication-provider user-service-ref="customAdmin">   
    </security:authentication-provider> 
</security:authentication-manager> 

<security:user-service id="customAdmin"> 
<security:user name="yourUserName" password="yourPassword" authorities="ROLE_USER, ROLE_ADMIN" /> 
<security:user name="yourOtherUserName" password="yourOtherPassword" authorities="ROLE_USER, ROLE_ADMIN" /> 
</security:user-service> 

公式春のドキュメントは私見、常にbest place to readです。

1

Beanを作成し、認証マネージャへの参照を提供し、org.springframework.security.authentication.AuthenticationProviderあなた自身を書く:

(あざけるとき、私はこれを使用)

<authentication-manager> 
    <authentication-provider ref="com.example.CustomAuthenticationProvider"/> 
</authentication-manager> 

代わりに、あなただけの彼らの関係当局とユーザー名とパスワードを供給することができます

<authentication-manager> 
    <authentication-provider> 
     <user-service> 
      <user name="test" password="test" authorities="ROLE_AUTHENTICATED" /> 
     </user-service> 
    </authentication-provider> 
</authentication-manager> 
+0

私の質問で説明したように、 'user-service'はその位置で有効な要素ではないようです。私はこれがおそらくSpring Securityの比較的最近の変更だと思っています。 – damd