1つのLDAPプロバイダと別のDAOプロバイダの2つのプロバイダをコンフィグレーションできます。
<sec:authentication-manager alias="authenticationManager">
<sec:authentication-provider ref="yourLdapAuthenticationProvider" />
<sec:authentication-provider ref="yourDaoAuthenticationProvider" />
</sec:authentication-manager>
LDAPが失敗すると、DAO認証プロバイダに返されます。
yourDaoAuthenticationProvider
にそのフラグを挿入するように独自の認証フィルタを設定する必要があります。その結果、認証がyourDaoAuthenticationProvider
に戻ったときに、さらなる認証(開発中)を続行するか、生産中)。だから、あなたのauthenticationFilter
、フラグを格納するsetDetails()
をオーバーライドするには: -
myAuthenticationFilter豆これにより
@Override
protected void setDetails(HttpServletRequest request, UsernamePasswordAuthenticationToken authRequest) {
YourObject yourObject = new YourObject(request.getParameter("devAuthAgainstDAO"));
authRequest.setDetails(yourObject);
}
、あなたのyourDaoAuthenticationProvider
はさらに、認証に進む前に、このフラグに対してチェックする必要があります。
最後に、あなたの構成は次のようになります: -
<sec:http auto-config="false" entry-point-ref="loginUrlAuthenticationEntryPoint">
<sec:logout logout-success-url="/login.jsp"/>
<sec:intercept-url ... />
<sec:custom-filter position="FORM_LOGIN_FILTER" ref="myAuthenticationFilter"/>
</sec:http>
<bean id="myAuthenticationFilter" class="[YOUR_CUSTOM_AUTHENTICATION_FILTER]">
<property name="authenticationManager" ref="authenticationManager"/>
<property name="authenticationFailureHandler" ref="failureHandler"/>
<property name="authenticationSuccessHandler" ref="successHandler"/>
</bean>
<bean id="loginUrlAuthenticationEntryPoint"
class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
<property name="loginFormUrl" value="/login.jsp"/>
</bean>
<bean id="successHandler"
class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
<property name="defaultTargetUrl" value="/welcome.jsp"/>
<property name="alwaysUseDefaultTargetUrl" value="true"/>
</bean>
<bean id="failureHandler"
class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
<property name="defaultFailureUrl" value="/login.jsp?login_error=1"/>
</bean>
<bean id="yourLdapAuthenticationProvider" ... />
<bean id="yourDaoAuthenticationProvider" ... />
<sec:authentication-manager alias="authenticationManager">
<sec:authentication-provider ref="yourLdapAuthenticationProvider"/>
<sec:authentication-provider ref="yourDaoAuthenticationProvider"/>
</sec:authentication-manager>
をデータベース内のユーザーにすべてのそれらの役割を追加しますか? – OrangeDog
いいえ、私はプログラムでそれらを理解することができます。この要件は多少のハックですが、それはdevでのみ行われます - 私は低俗なハックを書くための少しの余裕があります – mkoryak