[英]How to configure BCryptPasswordEncoder in security xml
I read every API and documentation of spring security but i cant find how to configure the BCryptPasswordEncoder strength parameter in the spring security bean xml. 我阅读了Spring Security的所有API和文档,但找不到如何在Spring Security bean xml中配置BCryptPasswordEncoder强度参数。
trying to do somthing like: BCryptPasswordEncoder(int strength);
尝试做类似的事情:
BCryptPasswordEncoder(int strength);
My security.xml: 我的security.xml:
<bean id="bCryptPasswordEncoder"
class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" />
<security:authentication-manager>
<security:authentication-provider
user-service-ref="userDetailsServiceImpl">
<security:password-encoder ref="bCryptPasswordEncoder" />
</security:authentication-provider>
</security:authentication-manager>
For this you would use Spring's constructor dependency injection on the BCryptPasswordEncoder. 为此,您可以在BCryptPasswordEncoder上使用Spring的构造函数依赖项注入 。
<bean id="bCryptPasswordEncoder"
class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder">
<constructor-arg value="100"/>
</bean>
<security:authentication-manager>
<security:authentication-provider
user-service-ref="userDetailsServiceImpl">
<security:password-encoder ref="bCryptPasswordEncoder" />
</security:authentication-provider>
</security:authentication-manager>
As of Spring 3.1 you can make this more concise using the c-namespace . 从Spring 3.1开始,您可以使用c-namespace使其更加简洁。 For example:
例如:
<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"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="bCryptPasswordEncoder"
class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"
c:strength="100"/>
<security:authentication-manager>
<security:authentication-provider
user-service-ref="userDetailsServiceImpl">
<security:password-encoder ref="bCryptPasswordEncoder" />
</security:authentication-provider>
</security:authentication-manager>
</beans>
You will notice that in this example 您会注意到在此示例中
See the previous link for more details on the c-namespace. 有关c-命名空间的更多详细信息,请参见上一个链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.