我再次遇到與Spring Security相同的問題:「密碼與存儲值不匹配」。春季安全 - 用戶創建和登錄時不同的SALT
我用我自定義的GraphPopulator
類在我的圖表中導入4個帳戶(我使用SpringData/Neo4J),並嘗試使用一個帳戶(「fbiville」/「s3cret」)登錄。
認證配置如下:
<beans:bean id="encoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder">
<beans:constructor-arg value="******" />
</beans:bean>
<beans:bean id="userService" class="com.lateralthoughts.devinlove.service.LoginService" />
<authentication-manager>
<authentication-provider user-service-ref="userService">
<password-encoder ref="encoder" />
</authentication-provider>
</authentication-manager>
和主管堅持賬戶類是部分地基於自定義SpringData倉庫實現:
class PersonRepositoryImpl implements PersonRepositoryCustom {
private final PasswordEncoder passwordEncoder;
private final Neo4jOperations template;
@Autowired
public PersonRepositoryImpl(PasswordEncoder passwordEncoder,
Neo4jOperations template) {
this.passwordEncoder = passwordEncoder;
this.template = template;
}
@Override
@Transactional
public void persist(Person person) {
person.setPassword(passwordEncoder.encode(person.getPassword()));
template.save(person);
}
}
最後,在登錄過程中配置如下:
<http auto-config='true' use-expressions='true' realm="devinlove: love is just another algorithm">
<form-login login-page="/login"
default-target-url="/"
authentication-failure-url="/login" />
<intercept-url pattern="/login" access="isAnonymous()" />
<intercept-url pattern="/**" access="hasRole('USER')" />
</http>
我調試了標準PasswordEncoder在創建帳戶和用戶登錄時,我注意到salt不匹配,這顯然導致認證錯誤。
如果您想重現問題,可以複製repository。
在此先感謝!
羅爾夫
一個指向任意大量的代碼是_not_勝過千言萬語的解釋。這甚至不值得_one_。它補充了一個解釋,因爲編寫解釋的行爲可以幫助你更好地理解問題。 –
你是對的,我的道歉。讓我編輯我的初始信息以提供更多細節。 – Rolf