Spring Security There is no PasswordEncoder mapped for the id "null"

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)

 

...

官网解释:

https://docs.spring.io/spring-security/site/docs/5.0.5.RELEASE/reference/htmlsingle/#pe-dpe-format

java 配置:

 

@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:)

 

 

 
<b:bean id= "passwordEncoder" class= "org.springframework.security.crypto.password.NoOpPasswordEncoder"
factory-method= "getInstance" />
 
 

xml完整配置:

 

注意红色位置: <security:password-encoder ref="passwordEncoder"/>

 

<?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>

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值