/** * Creates an {@link OAuth2Exception} from a Map<String,String>. * * @param errorParams * @return */ public static OAuth2Exception valueOf(Map<String, String> errorParams) { String errorCode = errorParams.get(ERROR); String errorMessage = errorParams.containsKey(DESCRIPTION) ? errorParams.get(DESCRIPTION) : null; OAuth2Exception ex = create(errorCode, errorMessage); Set<Map.Entry<String, String>> entries = errorParams.entrySet(); for (Map.Entry<String, String> entry : entries) { String key = entry.getKey(); if (!ERROR.equals(key) && !DESCRIPTION.equals(key)) { ex.addAdditionalInformation(key, entry.getValue()); } } return ex; }
if (!"error".equals(key) && !"error_description".equals(key)) { Object value = entry.getValue(); ex.addAdditionalInformation(key, value == null ? null : value.toString());
if (!"error".equals(key) && !"error_description".equals(key)) { Object value = entry.getValue(); ex.addAdditionalInformation(key, value == null ? null : value.toString());
private String generateCode(AuthorizationRequest authorizationRequest, Authentication authentication) throws AuthenticationException { try { OAuth2Request storedOAuth2Request = getOAuth2RequestFactory().createOAuth2Request(authorizationRequest); OAuth2Authentication combinedAuth = new OAuth2Authentication(storedOAuth2Request, authentication); String code = authorizationCodeServices.createAuthorizationCode(combinedAuth); return code; } catch (OAuth2Exception e) { if (authorizationRequest.getState() != null) { e.addAdditionalInformation("state", authorizationRequest.getState()); } throw e; } }
private String generateCode(AuthorizationRequest authorizationRequest, Authentication authentication) throws AuthenticationException { try { OAuth2Request storedOAuth2Request = getOAuth2RequestFactory().createOAuth2Request(authorizationRequest); OAuth2Authentication combinedAuth = new OAuth2Authentication(storedOAuth2Request, authentication); String code = authorizationCodeServices.createAuthorizationCode(combinedAuth); return code; } catch (OAuth2Exception e) { if (authorizationRequest.getState() != null) { e.addAdditionalInformation("state", authorizationRequest.getState()); } throw e; } }
@Override public ResponseEntity<OAuth2Exception> translate(final Exception e) throws Exception { // Translate the exception with the default translator ResponseEntity<OAuth2Exception> defaultResponse = this.defaultTranslator.translate(e); // Build your own error object String errorCode = defaultResponse.getBody().getOAuth2ErrorCode(); OAuth2Exception excBody = defaultResponse.getBody(); log.info("Came here==>"+errorCode); if(errorCode.equals("unauthorized")) { excBody.addAdditionalInformation("error_description", "Authentication required to access this resource"); } return new ResponseEntity<OAuth2Exception>(excBody, defaultResponse.getStatusCode()) ; } }
/** * Creates an {@link OAuth2Exception} from a Map<String,String>. * * @param errorParams * @return */ public static OAuth2Exception valueOf(Map<String, String> errorParams) { String errorCode = errorParams.get(ERROR); String errorMessage = errorParams.containsKey(DESCRIPTION) ? errorParams.get(DESCRIPTION) : null; OAuth2Exception ex = create(errorCode, errorMessage); Set<Map.Entry<String, String>> entries = errorParams.entrySet(); for (Map.Entry<String, String> entry : entries) { String key = entry.getKey(); if (!ERROR.equals(key) && !DESCRIPTION.equals(key)) { ex.addAdditionalInformation(key, entry.getValue()); } } return ex; }
oAuth2Exception.addAdditionalInformation("code", code); oAuth2Exception.addAdditionalInformation("message", message); } else { ResponseEntity<OAuth2Exception> responseEntity = super.translate(e); oAuth2Exception.addAdditionalInformation("code", StringUtils.isNotEmpty(errorCode) ? errorCode : GenericErrorCodes.GENERIC_API_ERROR_CODE.getCode() + ""); oAuth2Exception.addAdditionalInformation("message", "账号认证失败"); LOGGER.error("OAuth2Exception", oAuth2Exception);
oAuth2Exception.addAdditionalInformation("code", code); oAuth2Exception.addAdditionalInformation("message", message); } else { ResponseEntity<OAuth2Exception> responseEntity = super.translate(e); oAuth2Exception.addAdditionalInformation("code", StringUtils.isNotEmpty(errorCode) ? errorCode : GenericErrorCodes.GENERIC_API_ERROR_CODE.getCode() + ""); oAuth2Exception.addAdditionalInformation("message", "账号认证失败"); LOGGER.error("OAuth2Exception", oAuth2Exception);
if (!"error".equals(key) && !"error_description".equals(key)) { Object value = entry.getValue(); ex.addAdditionalInformation(key, value == null ? null : value.toString());
if (!"error".equals(key) && !"error_description".equals(key)) { Object value = entry.getValue(); ex.addAdditionalInformation(key, value == null ? null : value.toString());
private String generateCode(AuthorizationRequest authorizationRequest, Authentication authentication) throws AuthenticationException { try { OAuth2Request storedOAuth2Request = getOAuth2RequestFactory().createOAuth2Request(authorizationRequest); OAuth2Authentication combinedAuth = new OAuth2Authentication(storedOAuth2Request, authentication); String code = authorizationCodeServices.createAuthorizationCode(combinedAuth); return code; } catch (OAuth2Exception e) { if (authorizationRequest.getState() != null) { e.addAdditionalInformation("state", authorizationRequest.getState()); } throw e; } }