[英]spring security custom inject AuthenticationProvider inside AuthenticationManager
[英]Spring security. Custom AuthenticationManager
我有spring mvc應用程序。 我已經使用CustomAuthenticationManager添加了Spring Security。 這是appContex.xml中包含的application-security.xml。 在login.jsp中,我使用帶有2個輸入的標准登錄頁面:name ='j_username'和name ='j_password',而不是在CustomAuthenticationManager.authenticate(身份驗證身份驗證)中的方法中,我只接收密碼,但不接收帶有名稱的主體。 我做錯了什么?
<?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:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p" xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<bean id="loginPassAuthenticationFilter"
class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter">
<property name="authenticationManager" ref="customAuthenticationManager" />
<property name="allowSessionCreation" value="true" />
<property name="filterProcessesUrl" value="/j_spring_security_check" />
<property name="authenticationFailureHandler" ref="customAuthenticationFailureHandler" />
<property name="authenticationSuccessHandler" ref="customAuthenticationSuccessHandler" />
</bean>
<bean id="customAuthenticationManager"
class="com.whatever.security.CustomAuthenticationManager" />
<bean id="authenticationFilter"
class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"
p:authenticationManager-ref="customAuthenticationManager"
p:authenticationFailureHandler-ref="customAuthenticationFailureHandler"
p:authenticationSuccessHandler-ref="customAuthenticationSuccessHandler" />
<bean id="customAuthenticationFailureHandler"
class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"
p:defaultFailureUrl="/?error=true" />
<bean id="customAuthenticationSuccessHandler"
class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler"
p:defaultTargetUrl="/" />
<bean id="authenticationEntryPoint"
class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"
p:loginFormUrl="/" />
<security:authentication-manager />
<bean id="passwordEncoder"
class="org.springframework.security.authentication.encoding.ShaPasswordEncoder">
<constructor-arg value="512" />
</bean>
<form name='f' action="<c:url value='j_spring_security_check' />"
method='POST'>
<table>
<tr>
<td>User:</td>
<td><input type='text' name='j_username' value=''></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='j_password' /></td>
</tr>
<tr>
<td colspan='2'><input name="submit" type="submit"
value="submit" /></td>
</tr>
<tr>
<td colspan='2'><input name="reset" type="reset" /></td>
</tr>
</table>
</form>
我建議使用安全命名空間(鏈接到最小配置的示例):
http://static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#ns-minimal
這里是您如何定義自己的身份驗證提供程序的鏈接: http : //static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#ns-auth-manager
創建自己的身份驗證提供程序可以解決大多數用例。 如果您需要任何其他說明,請告訴我。
最好的祝福,
邁克爾
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.