1

我将 CAS 从 3.5.2 升级到 4。

在版本 3.5.2 中,我创建了一个 CustomAuthentication 类扩展 AbstractJdbcUsernamePasswordAuthenticationHandler 来执行我的自定义身份验证并根据我的需要抛出异常

例子:

throw new BadCredentialsAuthenticationException("error.accountNotExist");

所以在 message.properties 我只是添加 error.accountNotExist=Account 不存在。

那么前端将返回上面的字符串。

但是在 CAS 版本 4 中,AbstractJdbcUsernamePasswordAuthenticationHandler 发生了变化。不再支持 BadCredentialsAuthenticationException。那么如何在 cas 版本 4 中执行它以返回我想要的任何自定义字符串?

4

1 回答 1

3

由于没有 1 个答案,我尝试自己找出答案。

添加自定义异常的步骤

1 创建新的异常类扩展LoginException

2 在messages.properties中为新添加的异常添加对应的消息

3 在 login-webflow.xml --> handleAuthenticationFailure action-state 添加<transition on="<yourCustomExcception>" to="generateLoginTicket"/>

4 创建一个CustomAuthenticationExceptionHandler.java,复制原始源码,在DEFAULT_ERROR_LIST中添加新的异常

5 在 cas-servlet.xml 中将 authenticationExceptionHandler 替换为您的 CustomAuthenticationExceptionHandler

于 2014-10-28T01:37:52.513 回答