@ExceptionHandler(OAuth2Exception.class) public ResponseEntity<OAuth2Exception> handleException(OAuth2Exception e) throws Exception { if (logger.isWarnEnabled()) { logger.warn("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage()); } return getExceptionTranslator().translate(e); }
public void write(OAuth2Exception t, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { MultiValueMap<String, String> data = new LinkedMultiValueMap<String, String>(); data.add(OAuth2Exception.ERROR, t.getOAuth2ErrorCode()); data.add(OAuth2Exception.DESCRIPTION, t.getMessage()); Map<String, String> additionalInformation = t.getAdditionalInformation(); if(additionalInformation != null) { for(Map.Entry<String,String> entry : additionalInformation.entrySet()) { data.add(entry.getKey(), entry.getValue()); } } delegateMessageConverter.write(data, contentType, outputMessage); }
String errorMessage = this.getMessage(); if (errorMessage != null) { builder.append(delim).append("error_description=\"").append(errorMessage).append("\"");
@Override public void serialize(OAuth2Exception value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeStringField("error", value.getOAuth2ErrorCode()); String errorMessage = value.getMessage(); if (errorMessage != null) { errorMessage = HtmlUtils.htmlEscape(errorMessage); } jgen.writeStringField("error_description", errorMessage); if (value.getAdditionalInformation()!=null) { for (Entry<String, String> entry : value.getAdditionalInformation().entrySet()) { String key = entry.getKey(); String add = entry.getValue(); jgen.writeStringField(key, add); } } jgen.writeEndObject(); }
private String getUnsuccessfulRedirect(AuthorizationRequest authorizationRequest, OAuth2Exception failure, boolean fragment) { if (authorizationRequest == null || authorizationRequest.getRedirectUri() == null) { // we have no redirect for the user. very sad. throw new UnapprovedClientAuthenticationException("Authorization failure, and no redirect URI.", failure); } Map<String, String> query = new LinkedHashMap<String, String>(); query.put("error", failure.getOAuth2ErrorCode()); query.put("error_description", failure.getMessage()); if (authorizationRequest.getState() != null) { query.put("state", authorizationRequest.getState()); } if (failure.getAdditionalInformation() != null) { for (Map.Entry<String, String> additionalInfo : failure.getAdditionalInformation().entrySet()) { query.put(additionalInfo.getKey(), additionalInfo.getValue()); } } return append(authorizationRequest.getRedirectUri(), query, fragment); }
logger.debug("Authentication request failed: " + failed); eventPublisher.publishAuthenticationFailure(new BadCredentialsException(failed.getMessage(), failed), new PreAuthenticatedAuthenticationToken("access-token", "N/A")); new InsufficientAuthenticationException(failed.getMessage(), failed));
protected JaxbOAuth2Exception convertToInternal(OAuth2Exception exception) { JaxbOAuth2Exception result = new JaxbOAuth2Exception(); result.setDescription(exception.getMessage()); result.setErrorCode(exception.getOAuth2ErrorCode()); return result; }
@Override public void serialize(OAuth2Exception value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeStringField("error", value.getOAuth2ErrorCode()); String errorMessage = value.getMessage(); if (errorMessage != null) { errorMessage = HtmlUtils.htmlEscape(errorMessage); } jgen.writeStringField("error_description", errorMessage); if (value.getAdditionalInformation()!=null) { for (Entry<String, String> entry : value.getAdditionalInformation().entrySet()) { String key = entry.getKey(); String add = entry.getValue(); jgen.writeStringField(key, add); } } jgen.writeEndObject(); }
return; } catch (OAuth2Exception failed) { String message = failed.getMessage(); logger.debug("Authentication request failed with Oauth exception: " + message); InsufficientAuthenticationException ex = new InsufficientAuthenticationException (message, failed);
private String getUnsuccessfulRedirect(AuthorizationRequest authorizationRequest, OAuth2Exception failure, boolean fragment) { if (authorizationRequest == null || authorizationRequest.getRedirectUri() == null) { // we have no redirect for the user. very sad. throw new UnapprovedClientAuthenticationException("Authorization failure, and no redirect URI.", failure); } UriComponentsBuilder template = UriComponentsBuilder.fromUriString(authorizationRequest.getRedirectUri()); StringBuilder values = new StringBuilder(); values.append("error=" + encode(failure.getOAuth2ErrorCode())); values.append("&error_description=" + encode(failure.getMessage())); if (authorizationRequest.getState() != null) { values.append("&state=" + encode(authorizationRequest.getState())); } if (failure.getAdditionalInformation() != null) { for (Map.Entry<String, String> additionalInfo : failure.getAdditionalInformation().entrySet()) { values.append("&" + encode(additionalInfo.getKey()) + "=" + encode(additionalInfo.getValue())); } } if (fragment) { template.fragment(values.toString()); } else { template.query(values.toString()); } return template.build(true).toUriString(); }
oauth2Exception = new OAuth2AccessDeniedException(oauth2Exception.getMessage());
public CustomOAuth2Exception(ErrorResponse errorResponse, OAuth2Exception ex) { super(ex.getMessage(), ex.getCause()); this.errorResponse = errorResponse; }
@ExceptionHandler(OAuth2Exception.class) public ResponseEntity<OAuth2Exception> handleException(OAuth2Exception e) throws Exception { if (logger.isWarnEnabled()) { logger.warn("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage()); } return getExceptionTranslator().translate(e); }
@Override public void serialize(OAuth2Exception value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); jgen.writeStringField("status", String.valueOf(value.getHttpErrorCode())); jgen.writeStringField("message", value.getMessage()); if (value.getAdditionalInformation() != null) { for (Map.Entry<String, String> entry : value.getAdditionalInformation().entrySet()) { String key = entry.getKey(); String add = entry.getValue(); jgen.writeStringField(key, add); } } jgen.writeEndObject(); }
public void write(OAuth2Exception t, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { MultiValueMap<String, String> data = new LinkedMultiValueMap<String, String>(); data.add(OAuth2Exception.ERROR, t.getOAuth2ErrorCode()); data.add(OAuth2Exception.DESCRIPTION, t.getMessage()); Map<String, String> additionalInformation = t.getAdditionalInformation(); if(additionalInformation != null) { for(Map.Entry<String,String> entry : additionalInformation.entrySet()) { data.add(entry.getKey(), entry.getValue()); } } delegateMessageConverter.write(data, contentType, outputMessage); }
@Override public void serialize(OAuth2Exception value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeStringField("error", value.getOAuth2ErrorCode()); String errorMessage = value.getMessage(); if (errorMessage != null) { errorMessage = HtmlUtils.htmlEscape(errorMessage); } jgen.writeStringField("error_description", errorMessage); if (value.getAdditionalInformation()!=null) { for (Entry<String, String> entry : value.getAdditionalInformation().entrySet()) { String key = entry.getKey(); String add = entry.getValue(); jgen.writeStringField(key, add); } } jgen.writeEndObject(); }
@Override public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception { OAuth2Exception oAuth2Exception = (OAuth2Exception) e; return ResponseEntity .status(oAuth2Exception.getHttpErrorCode()) .body(new CustomOauthException(oAuth2Exception.getMessage())); } }
private String getUnsuccessfulRedirect(AuthorizationRequest authorizationRequest, OAuth2Exception failure, boolean fragment) { if (authorizationRequest == null || authorizationRequest.getRedirectUri() == null) { // we have no redirect for the user. very sad. throw new UnapprovedClientAuthenticationException("Authorization failure, and no redirect URI.", failure); } Map<String, String> query = new LinkedHashMap<String, String>(); query.put("error", failure.getOAuth2ErrorCode()); query.put("error_description", failure.getMessage()); if (authorizationRequest.getState() != null) { query.put("state", authorizationRequest.getState()); } if (failure.getAdditionalInformation() != null) { for (Map.Entry<String, String> additionalInfo : failure.getAdditionalInformation().entrySet()) { query.put(additionalInfo.getKey(), additionalInfo.getValue()); } } return append(authorizationRequest.getRedirectUri(), query, fragment); }
protected JaxbOAuth2Exception convertToInternal(OAuth2Exception exception) { JaxbOAuth2Exception result = new JaxbOAuth2Exception(); result.setDescription(exception.getMessage()); result.setErrorCode(exception.getOAuth2ErrorCode()); return result; }
@Override public void serialize(OAuth2Exception value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeStringField("error", value.getOAuth2ErrorCode()); String errorMessage = value.getMessage(); if (errorMessage != null) { errorMessage = HtmlUtils.htmlEscape(errorMessage); } jgen.writeStringField("error_description", errorMessage); if (value.getAdditionalInformation()!=null) { for (Entry<String, String> entry : value.getAdditionalInformation().entrySet()) { String key = entry.getKey(); String add = entry.getValue(); jgen.writeStringField(key, add); } } jgen.writeEndObject(); }