2011-11-17 5 views
3

XML을 통해 스프링 보안을 구성하려고 시도했지만 작동하지 않을 수 있습니다. 여기에 지금까지 무엇을 가지고 : 내가 찾은XML의 스프링 보안 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입니다. 제가 이해하는 한 "추상적 인"요소입니다.

사용자 및 암호의 메모리 내장 목록을 구성하기 만하면됩니다. 스프링 보안 버전 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> 

offical 한 스프링 문서는 이럴 항상 best place to read 있습니다.

1

는 쓰기 자신의 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

관련 문제