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 error = this.getOAuth2ErrorCode(); if (error != null) { builder.append(delim).append("error=\"").append(error).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); }
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(); }
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(); }
@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()) ; } }
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 error = this.getOAuth2ErrorCode(); if (error != null) { builder.append(delim).append("error=\"").append(error).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); }
@Override public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception { ResponseEntity<OAuth2Exception> responseEntity = super.translate(e); HttpHeaders headers = new HttpHeaders(); headers.setAll(responseEntity.getHeaders().toSingleValueMap()); ErrorResponse errorResponse; OAuth2Exception oAuth2Exception = responseEntity.getBody(); switch (oAuth2Exception.getOAuth2ErrorCode()) { case INVALID_TOKEN: errorResponse = new ErrorResponse(GlobalErrorCodes.INVALID_TOKEN_CODE, oAuth2Exception.getOAuth2ErrorCode(), oAuth2Exception.getMessage()); break; case INVALID_GRANT: errorResponse = new ErrorResponse(GlobalErrorCodes.INVALID_USERNAME_PASSWORD_CODE, oAuth2Exception.getOAuth2ErrorCode(), oAuth2Exception.getMessage()); break; default: errorResponse = new ErrorResponse(GlobalErrorCodes.AUTH_ERROR_CODE, oAuth2Exception.getOAuth2ErrorCode(), oAuth2Exception.getMessage()); } return new ResponseEntity<>(new CustomOAuth2Exception(errorResponse, oAuth2Exception), headers, responseEntity.getStatusCode()); } }
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(); }