- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 Spring Security 与 OAuth 2 结合使用。我的 OAuth 用户具有 account_locked
和 enabled
字段,我出于不同的原因使用它们。例如。 account_locked
用于阻止用户,enabled
用于停用用户。当用户尝试登录并被阻止时,他会收到 401
HTTP 代码和消息“用户帐户已锁定”。如果他被停用,那么他还会收到 401
HTTP 代码和消息“用户已禁用”。
我想通过附加信息来增强这些错误(例如可以使用 TokenEnhancer 来增强 token ),以区分客户端上的 block 代码和停用代码。例如。与字段reason_of_fail
。请注意,我不想使用这些错误中的短信。
我已经尝试使用这个(来自 this answer ):
@Override
protected void configure(HttpSecurity http) throws Exception {
http.exceptionHandling()
.authencationEntryPoint(unauthorizedHandler)
.accessDeniedHandler(accessDeniedHandler);
}
但是这些处理程序不会捕获 LockedException
和 DisabledException
。
那么,我如何通过附加字段(键值对)来增强这些错误?
最佳答案
授权服务器
如果您想将此功能添加到您的授权服务器,并且您有一个自定义 AbstractTokenGranter
(请参阅下面的对话),然后您可以在 getOAuth2Authentication
方法中捕获所需的异常。
然后,您可以抛出一个自定义异常,该异常扩展 OAuth2Exception
并使用您需要的任何其他字段填充 additionalInformation
映射。
有关如何执行此操作的示例,您可以查看 ResourceOwnerPasswordTokenGranter来自 spring-security-oauth 项目。
客户端
如果您想将此功能添加到 OAuth2 客户端,则可以使用自定义 AuthenticationFailureHandler
来捕获 LockedException
和 DisabledException
。
以下是安全配置示例:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.oauth2Login()
.failureHandler(new CustomAuthenticationFailureHandler());
}
以及自定义 AuthenticationFailureHandler
的示例:
public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler {
@Override
public void onAuthenticationFailure(HttpServletRequest request,
HttpServletResponse response, AuthenticationException exception) {
if (exception instanceof DisabledException) {
// throw new exception or modify response
}
}
}
关于java - 捕获并增强LockedException和DisabledException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56730581/
我正在尝试使用增强的 for 循环遍历 Iterable,但我无法确定何时处理最后一个值。 public void apply(Tuple key,
我正在使用以下代码在 Sheet2 的 A:H 范围内查找和替换 Sheet1 中存在的单词列表(ColA 用于 FIND 单词,ColB 用于 REPLACE 单词)。它执行这项工作,但非常缓慢。可
我正在使用 Hibernate (JPA2) hibernate.hbm2ddl.auto=update用于测试和 hibernate.hbm2ddl.auto=validate用于生产。 我想要做的
基本问题: 为什么我只能用 Scala 编写: println(10) 为什么我不需要写: Console println(10) 后续问题: 如何引入一个新方法“foo”,它像“println”一样
我正在尝试将 Maven 项目迁移到 Bazel,但在 Datanucleus 增强方面遇到了麻烦。 后 jar -file 已构建,Datanucleus 会查看其中的内部并执行一些字节码操作以增强
正在使用 css3 转换进行漂亮的导航。为此还编写了一些 javascript。 但不幸的是它看起来有点凌乱。你们能给我一些优化 javascript 代码的技巧吗? 笔--> http://code
我想将自定义任务绑定(bind)到默认构建器发布周期中。我想在项目编译、打包、标记和部署之后但在增加版本号并提交之前运行此代码。 我将如何融入发布周期的这一部分? 最佳答案 不幸的是,release
我使用ElasticSearch 6.6。我的应用程序通过从不同数据源提取数据来构建ES索引。搜索未指定数据源。它只是建立一个类似的查询: GET employerdata/_search { "
我正在使用此代码将“k1 = v1; k2 = v2; k3 = v3; kn = vn”字符串解析为映射。 qi::phrase_parse( begin,end,
我正在试图弄清楚作业的一部分,但我已经把头撞在墙上有一段时间了。我正在尝试将 DNA 序列转录为 RNA 序列。然而,我收到了 ArrayOutOfBoundsException。我不熟悉使用增强的
我需要对基于 python Google App Engine 的应用程序的警告进行分类。我从 GAE stackdriver 下载日志。我认为 GAE Stackdriver 错误报告位于 http
我有一个 django charField,通过 is_valid() 方法进行检查。用户应该在此字段中输入有效的逻辑表达式,因此我编写了一个解析方法,如果表达式不正确,该方法会引发异常。 如何增强
我编写了以下控制台应用程序,要求用户输入一天。 我需要一些帮助才能改进,以便他们为一周中的所有日子提供正确的答案。 如果用户输入除星期一以外的任何其他日期,则输出为“今天”、“昨天”、“明天”,并在这
我在使用带有 ES6 let 关键字的模块模式(扩充)时遇到错误。 这有效。 var Example = ( Example => { Example.name = ""; retur
我只是问是否线程安全可以使用 我明确指出“doSomething()”是线程安全的。 最佳答案 线程安全取决于您正在迭代的 Collection,而不是 enhanced for 的使用。如果 Col
我有一个非常符合 this Jquery demo 的要求,这是一个简单的购物车演示。基本上,我需要对该演示进行两项改进。 我需要文本输入以及可用的“产品”。因此,当我拖放其中一种产品时,文本字段应随
我正在三个表 messages、message_recipients 和 users 上运行查询。 messages表的表结构: id int pk message_id int message te
这个问题已经有答案了: In detail, how does the 'for each' loop work in Java? (29 个回答) 已关闭 4 年前。 由于增强的 for 循环是只读
我在 css 中制作了一个很酷的鼠标悬停,当父级鼠标悬停时它会显示动画 gif。 这是我的代码:http://codepen.io/clemeeent/pen/oggzMa 问题是我将有大约 40 天
目前,当使用 Knockout foreach 绑定(bind)时,您可以使用 $index 访问当前索引。我想让其他类似的功能可用于我的内部绑定(bind) - 例如: array(让我访问正在操作
我是一名优秀的程序员,十分优秀!