2011-10-11 26 views
14

'u Kullanmak İçin Yapılandırın Güvenliği'un yalnızca bir alt sınıfı olan kendi LowerCaseUsernamePasswordAuthenticationFilter'u uygulamıyorum.Özel Parola Kullanıcı Adı Parola Kimlik Doğrulaması Oluşturucusu

Ama şimdi benim sorunum, bu filtreyi kullanmak için Spring güvenliğini nasıl yapılandırılır. Yukarı

şimdi kullandığım için:

<security:http auto-config="true" use-expressions="true"> 
    <security:form-login login-processing-url="/resources/j_spring_security_check" login-page="/login" authentication-failure-url="/login?login_error=t" /> 
    <security:logout logout-url="/resources/j_spring_security_logout" /> 

    <security:intercept-url pattern="/**" access="isAuthenticated()" requires-channel="${cfma.security.channel}" /> 
</security:http> 

Gerçekten auto-config arasında dönüp eliyle tüm filtreleri yapılandırmak için ihtiyaç mı? - Eğer bu doğruysa, kimse bir örnek verebilir mi lütfen?


sadece security:custom-filter eklemek için yolu:

<security:http ...> 

    <security:form-login login-processing-url="/resources/j_spring_security_check" login-page="/login" authentication-failure-url="/login?login_error=t" /> 
    <security:custom-filter ref="lowerCaseUsernamePasswordAuthenticationFilter" position="FORM_LOGIN_FILTER"/> 
    ... 
</security:http> 

bu mesajın bir istisna yol vermez:

Yapılandırma sorun: Filtre fasulye <lowerCaseUsernamePasswordAuthenticationFilter> ve 'Kök fasulyesi: sınıf [ org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter]; kapsamı =; Anahtar = false; = False lazyInit; autowireMode = 0; dependencyCheck = 0; autowireCandidate = Gerçek; Birincil = false; factoryBeanName = null; factoryMethodName = null; initMethodName = null; destroyMethodName = null 'aynı' sipariş 'değerine sahip. Özel filtreler kullanırken, konumların varsayılan filtrelerle çakışmadığından emin olun. Alternatif olarak, ilgili alt öğeleri kaldırarak ve bunlardan kaçınarak varsayılan filtreleri devre dışı bırakabilirsiniz.

cevap

12

Gerekli otomatik olarak yapılandırılmış fasulyeleri el ile yazarak yaptım. Bu, sonucun:

<!-- HTTP security configurations --> 
<security:http auto-config="false" use-expressions="true" entry-point-ref="loginUrlAuthenticationEntryPoint"> 

    <!-- 
    <security:form-login login-processing-url="/resources/j_spring_security_check" login-page="/login" authentication-failure-url="/login?login_error=t" /> 
     replaced by lowerCaseUsernamePasswordAuthenticationFilter 
     the custom-filter with position FORM_LOGIN_FILTER requries that auto-config is false! 
    --> 
    <security:custom-filter ref="lowerCaseUsernamePasswordAuthenticationFilter" position="FORM_LOGIN_FILTER"/> 
    <security:logout logout-url="/resources/j_spring_security_logout" /> 

    <security:intercept-url pattern="/**" access="isAuthenticated()" /> 
</security:http> 

<bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"> 
    <property name="loginFormUrl" value="/login"/> 
</bean> 

<bean id="lowerCaseUsernamePasswordAuthenticationFilter" 
    class="com.queomedia.cfma.infrastructure.security.LowerCaseUsernamePasswordAuthenticationFilter"> 
    <property name="filterProcessesUrl" value="/resources/j_spring_security_check"/> 
    <property name="authenticationManager" ref="authenticationManager"/> 
    <property name="authenticationFailureHandler"> 
     <bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> 
      <property name="defaultFailureUrl" value="/login?login_error=t"/>  
     </bean> 
    </property> 
</bean> 
2

Scala'da bir örnek. Spring Security OAuth tarafından sağlanan bir filtreyi değiştirmek için bunu yapmak zorundaydım.

Temel olarak fikir, FilterChainProxy ve filtrenize değiştirmek istediğiniz mevcut filtreyi enjekte etmektir. Mevcut filtreyi filterChainMap'da bulun ve sizinkiyle değiştirin.

import org.springframework.security.oauth2.provider.verification.{VerificationCodeFilter => SpringVerificationCodeFilter} 

@Component 
class VerificationCodeFilter extends SpringVerificationCodeFilter with InitializingBean { 
    @Autowired var filterChainProxy: FilterChainProxy = _ 
    @Autowired var springVerificationCodeFilter: SpringVerificationCodeFilter = _ 


    override def afterPropertiesSet() { 
    super.afterPropertiesSet() 

    val filterChainMap = filterChainProxy.getFilterChainMap 
    val filterChain = 
     filterChainMap.find(_._2.exists(_.isInstanceOf[SpringVerificationCodeFilter])). 
      getOrElse(throw new Exception("Could not find VerificationCodeFilter in FilterChainMap"))._2 
    val index = filterChain.indexOf(springVerificationCodeFilter) 
    filterChain.remove(index) 
    filterChain.add(index, this) 
    } 
} 
İlgili konular