在 PreAuthenticationProvider 中处理 UserNotFoundException
我有两个身份验证提供商。一个检查数据库,另一个是 SAML 断言的预验证提供商。
用户信息及其各自的角色保存在数据库中。因此,当用户使用 SAML 点击应用程序时,我们会在数据库中插入一行并分配一个默认角色,然后将用户重定向到注册页面,我们在其中捕获一些用户特定信息。
使用 PreAuthenticatedProvider,我捕获 UserNotFoundException,问题是如何从我的身份验证方法将用户重定向到注册页面?
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
try {
// custom code
} catch (UsernameNotFoundException e) {
// Redirect user to a view
}
}
有没有更好的方法来处理此类案件?
编辑:我对处理来自 AuthenticationProviders 特别是 PreAuthenticationProviders 的 AuthenticationExceptions 感兴趣。
I have two authentication providers. One checks against the database and the other is a pre-authenticated provider for SAML assertion.
User information and their respective roles are persisted in a DB. So when the user hits application with SAML, we insert a row in the database and assign a default role after which redirect the user to a registration page where we capture some user specific information.
With PreAuthenticatedProvider I am catching UserNotFoundException and the question is how do I redirect the user to registration page from my authenticate method?
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
try {
// custom code
} catch (UsernameNotFoundException e) {
// Redirect user to a view
}
}
Is there a better way of handling such cases?
EDIT: I am interested in handling AuthenticationExceptions coming from AuthenticationProviders particularly PreAuthenticationProviders.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写自己的自定义
ExceptionTranslationFilter
并将其放在表单处理过滤器之前的过滤器链中,以捕获这些异常并进行正确处理。application-context.xml 中类似的内容
您的 ExceptionTransalationFilter 需要扩展 ExceptionTranslationFilter 并覆盖
doFilter
方法:在 8.2 下查看:
http://static.springsource.org/spring-security/site/docs/3.0.x/reference/core-web-filters.html
You can write your own Custom
ExceptionTranslationFilter
and put it in the filter chain before the form processin filter to catch these exceptions and handle properly.Something like this in the application-context.xml
Your ExceptionTransalationFilter need to extend
ExceptionTranslationFilter
and Override thedoFilter
Method:Look under 8.2 Here:
http://static.springsource.org/spring-security/site/docs/3.0.x/reference/core-web-filters.html