org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator Java Examples
The following examples show how to use
org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomAuthorizationServerConfigurer.java From spring-microservice-exam with MIT License | 7 votes |
@Bean @Lazy public WebResponseExceptionTranslator<OAuth2Exception> webResponseExceptionTranslator() { return new DefaultWebResponseExceptionTranslator() { @Override public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception { if (e instanceof OAuth2Exception) { OAuth2Exception exception = (OAuth2Exception) e; // 转换返回结果 return ResponseEntity.status(exception.getHttpErrorCode()).body(new CustomOauthException(e.getMessage())); } else { throw e; } } }; }
Example #2
Source File: SecurityHandlerConfig.java From microservices-platform with Apache License 2.0 | 5 votes |
@Bean public WebResponseExceptionTranslator webResponseExceptionTranslator() { return new DefaultWebResponseExceptionTranslator() { public static final String BAD_MSG = "坏的凭证"; @Override public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception { OAuth2Exception oAuth2Exception; if (e.getMessage() != null && e.getMessage().equals(BAD_MSG)) { oAuth2Exception = new InvalidGrantException("用户名或密码错误", e); } else if (e instanceof InternalAuthenticationServiceException) { oAuth2Exception = new InvalidGrantException(e.getMessage(), e); } else if (e instanceof RedirectMismatchException) { oAuth2Exception = new InvalidGrantException(e.getMessage(), e); } else if (e instanceof InvalidScopeException) { oAuth2Exception = new InvalidGrantException(e.getMessage(), e); } else { oAuth2Exception = new UnsupportedResponseTypeException("服务内部错误", e); } ResponseEntity<OAuth2Exception> response = super.translate(oAuth2Exception); ResponseEntity.status(oAuth2Exception.getHttpErrorCode()); response.getBody().addAdditionalInformation("resp_code", oAuth2Exception.getHttpErrorCode() + ""); response.getBody().addAdditionalInformation("resp_msg", oAuth2Exception.getMessage()); return response; } }; }
Example #3
Source File: OAuth2Config.java From Auth-service with MIT License | 5 votes |
@Autowired public OAuth2Config(AuthenticationManager authenticationManager, WebResponseExceptionTranslator webResponseExceptionTranslator, HikariDataSource dataSource, RedisConnectionFactory redisConnectionFactory) { this.authenticationManager = authenticationManager; this.webResponseExceptionTranslator = webResponseExceptionTranslator; this.dataSource = dataSource; this.redisConnectionFactory = redisConnectionFactory; }
Example #4
Source File: ResourceServerConfig.java From pacbot with Apache License 2.0 | 4 votes |
/** Define your custom exception translator bean here */ @Bean public WebResponseExceptionTranslator exceptionTranslator() { return new ApiErrorWebResponseExceptionTranslator(); }
Example #5
Source File: AuthorizationServerConfig.java From lion with Apache License 2.0 | 4 votes |
@Bean public WebResponseExceptionTranslator<OAuth2Exception> webResponseExceptionTranslator() { return new CustomWebResponseExceptionTranslator(); }
Example #6
Source File: ServiceConfig.java From Auth-service with MIT License | 4 votes |
@Bean public WebResponseExceptionTranslator webResponseExceptionTranslator() { return new CustomWebResponseExceptionTranslator(); }
Example #7
Source File: ServiceConfig.java From microservice-integration with MIT License | 4 votes |
@Bean public WebResponseExceptionTranslator webResponseExceptionTranslator() { return new CustomWebResponseExceptionTranslator(); }
Example #8
Source File: OAuthRestController.java From spring-oauth-server with GNU General Public License v2.0 | 4 votes |
protected WebResponseExceptionTranslator getExceptionTranslator() { return providerExceptionHandler; }
Example #9
Source File: AuthorizationServerConfig.java From SpringCloud with Apache License 2.0 | 2 votes |
/** * 自定义OAuth2异常处理 * * @return CustomWebResponseExceptionTranslator */ @Bean public WebResponseExceptionTranslator<OAuth2Exception> customExceptionTranslator() { return new CustomWebResponseExceptionTranslator(); }