我们正在开发将与部署的WAR文件传送到多个客户的Web应用程序进行控制。他们只需要他们的技术人员来定制他们的数据源。现在有一个要求。有些客户想要加密密码但其他人不需要。我试过:如何如果Spring Security认证使用密码加密或不
<bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>
<bean id="MyUserDetailsService" class="com.xxx.xxxx.listener.MyUserDetailsService"/>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider user-service-ref="MyUserDetailsService">
<security:password-encoder ref="encoder"/>
</security:authentication-provider>
</security:authentication-manager>
它的工作原理。我知道如果我删除
<security:password-encoder ref="encoder"/>
那么应用程序将不会在身份验证过程中应用密码加密。但我们不希望我们的客户自己做出这样的改变。我们希望根据数据库或网页中的系统设置以编程方式对其进行控制。我不知道如何实现它。请帮忙。提前致谢。
更新 感谢jhadesdev的想法。我通过创建一个子类并重写encodePassword方法来解决它。此时我使用ShaPasswordEncoder,因为我需要在PostgreSql数据库中编码大量现有密码。
public class CustomerShaPasswordEncoder extends ShaPasswordEncoder {
@Autowired
protected AdminDao adminDao = null;
public CustomerShaPasswordEncoder() {
super();
}
public CustomerShaPasswordEncoder(int strength) {
super(strength);
}
@Override
public String encodePassword(String rawPass, Object salt) {
SecuritySetting ss = adminDao.getSecuritySetting();
if ((ss == null || ss.getEncryptPassword() == null || ss
.getEncryptPassword() == false)) {
return rawPass;
} else {
return super.encodePassword(rawPass, salt);
}
}
}
但我不知道如何将参数加载到静态变量。