「這是我參與8月更文挑戰的第11天,活動詳情查看:8月更文挑戰」html
Spring Security There is no PasswordEncoder mapped for the id ";null";java
java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"\
at org.springframework.security.crypto.password.DelegatingPasswordEncoder$UnmappedIdPasswordEncoder.matches(DelegatingPasswordEncoder.java:238)\
at org.springframework.security.crypto.password.DelegatingPasswordEncoder.matches(DelegatingPasswordEncoder.java:198)\
at org.springframework.security.authentication.dao.DaoAuthenticationProvider.additionalAuthenticationChecks(DaoAuthenticationProvider.java:86)\
at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:166)\
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:174)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:199)
...
複製代碼
官網解釋:spring
docs.spring.io/spring-secu…express
The following error occurs when one of the passwords that are stored has no id as described in the section called 「Password Storage Format」.markdown
java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
at org.springframework.security.crypto.password.DelegatingPasswordEncoder$UnmappedIdPasswordEncoder.matches(DelegatingPasswordEncoder.java:233)
at org.springframework.security.crypto.password.DelegatingPasswordEncoder.matches(DelegatingPasswordEncoder.java:196)
複製代碼
The easiest way to resolve the error is to switch to explicitly provide the
PasswordEncoder
that you passwords are encoded with. The easiest way to resolve it is to figure out how your passwords are currently being stored and explicitly provide the correctPasswordEncoder
. If you are migrating from Spring Security 4.2.x you can revert to the previous behavior by exposing aNoOpPasswordEncoder
bean. For example, if you are using Java Configuration, you can create a configuration that looks like:app
java 配置:ide
@Bean
public static NoOpPasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();
}
public static NoOpPasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();
}
複製代碼
xml 配置:(if you are using XML configuration, you can expose a PasswordEncoder
with the id passwordEncoder
:)oop
<b:bean id="passwordEncoder" class="org.springframework.security.crypto.password.NoOpPasswordEncoder"
factory-method="getInstance"/>
複製代碼
xml完整配置:post
注意紅色位置: <security:password-encoder ref="passwordEncoder"/>ui
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<!-- use-expressions:Spring 表達式語言配置訪問控制 -->
<security:http auto-config="true" use-expressions="false">
<!-- 配置權限攔截,訪問全部url,都須要用戶登陸,且擁有ROLE_USER權限 -->
<security:intercept-url pattern="/**" access="ROLE_USER"/>
</security:http>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider>
<security:password-encoder ref="passwordEncoder"/>
<!-- 配置默認用戶,用戶名:admin 密碼:123456 擁有權限:ROLE_USER -->
<security:user-service>
<security:user name="admin" password="123456"
authorities="ROLE_USER"/>
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
<bean id="passwordEncoder"
class="org.springframework.security.crypto.password.NoOpPasswordEncoder" factory-method="getInstance"/>
</beans>
複製代碼