1 回答

TA貢獻1815條經驗 獲得超13個贊
授權服務器
如果您想將此功能添加到您的授權服務器,并且您有一個自定義AbstractTokenGranter(請參閱下面的對話),那么您可以在該方法中捕獲所需的異常getOAuth2Authentication。然后,您可以拋出一個自定義異常,用您需要的任何附加字段
擴展OAuth2Exception和填充地圖。 有關如何執行此操作的示例,您可以查看spring-security-oauth 項目中的ResourceOwnerPasswordTokenGranter 。additionalInformation
客戶
相反,如果您想將此功能添加到您的 OAuth2 客戶端,那么您可以使用自定義AuthenticationFailureHandler來捕獲LockedExceptionand 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
}
}
}
添加回答
舉報