CAS DB 身份验证 "encode" 密码加密无法与使用 Spring Security 的 ShaPasswordEncoder 加密的数据库密码匹配
CAS DB Authentication "encode" password encryption can't match with database password encrypted using Spring Security's ShaPasswordEncoder
我目前正在配置我的 CAS 服务器 v5.0.2 以使用数据库身份验证,特别是使用编码方法,使用 CAS 属性文件。以下是属性文件中的相关 属性 配置:
cas.authn.jdbc.encode[0].sql=SELECT * FROM public.vt_user WHERE email=?
cas.authn.jdbc.encode[0].driverClass=org.postgresql.Driver
cas.authn.jdbc.encode[0].url=jdbc:postgresql://localhost:5432/tracking
cas.authn.jdbc.encode[0].user=postgres
cas.authn.jdbc.encode[0].password=postgres
cas.authn.jdbc.encode[0].saltFieldName=salt
cas.authn.jdbc.encode[0].passwordFieldName=password
cas.authn.jdbc.encode[0].healthQuery=SELECT 1 FROM INFORMATION_SCHEMA.TABLES
cas.authn.jdbc.encode[0].numberOfIterations=1
cas.authn.jdbc.encode[0].numberOfIterationsFieldName=
cas.authn.jdbc.encode[0].staticSalt=
cas.authn.jdbc.encode[0].algorithmName=SHA-1
cas.authn.jdbc.encode[0].dialect=org.hibernate.dialect.PostgreSQLDialect
cas.authn.jdbc.encode[0].passwordEncoder.type=DEFAULT
cas.authn.jdbc.encode[0].passwordEncoder.characterEncoding=UTF-8
cas.authn.jdbc.encode[0].passwordEncoder.encodingAlgorithm=SHA-1
我连接的数据库是 PostgreSQL 数据库。密码之前使用 Spring Security 的 3.2.5 ShaPasswordEncoder 编码,默认强度为 SHA-1 加盐值。我已经通过在 CAS 服务器的默认登录页面中输入有效凭据来测试 CAS DB 身份验证配置,但身份验证总是失败并且 return "Invalid credentials." 此外,我已经知道 3.2.5 ShaPasswordEncoder 已被弃用,但我不打算改变它的实施。日志显示可以从用户 table 成功查询用户名,但 table 的密码与输入不匹配。
现在我正在寻找解决此问题的任何方法。我对 CAS 还是比较陌生,非常感谢您提供的急需帮助。谢谢!
我通过修改来自 cas-server-upport-jdbc 依赖项(相同 CAS 版本)的 QueryAndEncodeDatabaseAuthenticationHandler.java 文件来使用 Spring Security 的 ShaPasswordEncoder 而不是CAS 使用的是 Apache Shiro 的默认哈希服务。
具体来说,我所做的是将修改后的 java 文件(加上 AbstractJdbcUsernamePasswordAuthenticationHandler.java)添加到我在 src/main/java/org/apereo/cas/adaptors/jdbc 目录中使用的 CAS maven 覆盖层中。我在 java 文件中修改的相关函数名为 digestEncodedPassword。我注释掉了原始代码行并将其替换为我的 ShaPasswordEncoder 实现。构建 CAS 时应同时编译自定义源代码。
我目前正在配置我的 CAS 服务器 v5.0.2 以使用数据库身份验证,特别是使用编码方法,使用 CAS 属性文件。以下是属性文件中的相关 属性 配置:
cas.authn.jdbc.encode[0].sql=SELECT * FROM public.vt_user WHERE email=?
cas.authn.jdbc.encode[0].driverClass=org.postgresql.Driver
cas.authn.jdbc.encode[0].url=jdbc:postgresql://localhost:5432/tracking
cas.authn.jdbc.encode[0].user=postgres
cas.authn.jdbc.encode[0].password=postgres
cas.authn.jdbc.encode[0].saltFieldName=salt
cas.authn.jdbc.encode[0].passwordFieldName=password
cas.authn.jdbc.encode[0].healthQuery=SELECT 1 FROM INFORMATION_SCHEMA.TABLES
cas.authn.jdbc.encode[0].numberOfIterations=1
cas.authn.jdbc.encode[0].numberOfIterationsFieldName=
cas.authn.jdbc.encode[0].staticSalt=
cas.authn.jdbc.encode[0].algorithmName=SHA-1
cas.authn.jdbc.encode[0].dialect=org.hibernate.dialect.PostgreSQLDialect
cas.authn.jdbc.encode[0].passwordEncoder.type=DEFAULT
cas.authn.jdbc.encode[0].passwordEncoder.characterEncoding=UTF-8
cas.authn.jdbc.encode[0].passwordEncoder.encodingAlgorithm=SHA-1
我连接的数据库是 PostgreSQL 数据库。密码之前使用 Spring Security 的 3.2.5 ShaPasswordEncoder 编码,默认强度为 SHA-1 加盐值。我已经通过在 CAS 服务器的默认登录页面中输入有效凭据来测试 CAS DB 身份验证配置,但身份验证总是失败并且 return "Invalid credentials." 此外,我已经知道 3.2.5 ShaPasswordEncoder 已被弃用,但我不打算改变它的实施。日志显示可以从用户 table 成功查询用户名,但 table 的密码与输入不匹配。
现在我正在寻找解决此问题的任何方法。我对 CAS 还是比较陌生,非常感谢您提供的急需帮助。谢谢!
我通过修改来自 cas-server-upport-jdbc 依赖项(相同 CAS 版本)的 QueryAndEncodeDatabaseAuthenticationHandler.java 文件来使用 Spring Security 的 ShaPasswordEncoder 而不是CAS 使用的是 Apache Shiro 的默认哈希服务。 具体来说,我所做的是将修改后的 java 文件(加上 AbstractJdbcUsernamePasswordAuthenticationHandler.java)添加到我在 src/main/java/org/apereo/cas/adaptors/jdbc 目录中使用的 CAS maven 覆盖层中。我在 java 文件中修改的相关函数名为 digestEncodedPassword。我注释掉了原始代码行并将其替换为我的 ShaPasswordEncoder 实现。构建 CAS 时应同时编译自定义源代码。