@Override public Map<String, String> convert(OAuth2Error oauth2Error) { Map<String, String> parameters = new HashMap<>(); parameters.put(OAuth2ParameterNames.ERROR, oauth2Error.getErrorCode()); if (StringUtils.hasText(oauth2Error.getDescription())) { parameters.put(OAuth2ParameterNames.ERROR_DESCRIPTION, oauth2Error.getDescription()); } if (StringUtils.hasText(oauth2Error.getUri())) { parameters.put(OAuth2ParameterNames.ERROR_URI, oauth2Error.getUri()); } return parameters; } }
private Map<String, String> createParameters(AuthenticationException authException) { Map<String, String> parameters = new LinkedHashMap<>(); if (this.realmName != null) { parameters.put("realm", this.realmName); } if (authException instanceof OAuth2AuthenticationException) { OAuth2Error error = ((OAuth2AuthenticationException) authException).getError(); parameters.put("error", error.getErrorCode()); if (StringUtils.hasText(error.getDescription())) { parameters.put("error_description", error.getDescription()); } if (StringUtils.hasText(error.getUri())) { parameters.put("error_uri", error.getUri()); } if (error instanceof BearerTokenError) { BearerTokenError bearerTokenError = (BearerTokenError) error; if (StringUtils.hasText(bearerTokenError.getScope())) { parameters.put("scope", bearerTokenError.getScope()); } } } return parameters; }
@Test public void constructorWhenAllParametersProvidedAndValidThenCreated() { OAuth2Error error = new OAuth2Error(ERROR_CODE, ERROR_DESCRIPTION, ERROR_URI); assertThat(error.getErrorCode()).isEqualTo(ERROR_CODE); assertThat(error.getDescription()).isEqualTo(ERROR_DESCRIPTION); assertThat(error.getUri()).isEqualTo(ERROR_URI); } }
@Test public void readInternalWhenErrorResponseThenReadOAuth2Error() throws Exception { String errorResponse = "{\n" + " \"error\": \"unauthorized_client\",\n" + " \"error_description\": \"The client is not authorized\",\n" + " \"error_uri\": \"https://tools.ietf.org/html/rfc6749#section-5.2\"\n" + "}\n"; MockClientHttpResponse response = new MockClientHttpResponse( errorResponse.getBytes(), HttpStatus.BAD_REQUEST); OAuth2Error oauth2Error = this.messageConverter.readInternal(OAuth2Error.class, response); assertThat(oauth2Error.getErrorCode()).isEqualTo("unauthorized_client"); assertThat(oauth2Error.getDescription()).isEqualTo("The client is not authorized"); assertThat(oauth2Error.getUri()).isEqualTo("https://tools.ietf.org/html/rfc6749#section-5.2"); }
@Test public void buildErrorResponseWhenAllAttributesProvidedThenAllAttributesAreSet() { OAuth2AuthorizationResponse authorizationResponse = OAuth2AuthorizationResponse.error(ERROR_CODE) .errorDescription(ERROR_DESCRIPTION) .errorUri(ERROR_URI) .redirectUri(REDIRECT_URI) .state(STATE) .build(); assertThat(authorizationResponse.getError().getErrorCode()).isEqualTo(ERROR_CODE); assertThat(authorizationResponse.getError().getDescription()).isEqualTo(ERROR_DESCRIPTION); assertThat(authorizationResponse.getError().getUri()).isEqualTo(ERROR_URI); assertThat(authorizationResponse.getRedirectUri()).isEqualTo(REDIRECT_URI); assertThat(authorizationResponse.getState()).isEqualTo(STATE); }
@Override public Map<String, String> convert(OAuth2Error oauth2Error) { Map<String, String> parameters = new HashMap<>(); parameters.put(OAuth2ParameterNames.ERROR, oauth2Error.getErrorCode()); if (StringUtils.hasText(oauth2Error.getDescription())) { parameters.put(OAuth2ParameterNames.ERROR_DESCRIPTION, oauth2Error.getDescription()); } if (StringUtils.hasText(oauth2Error.getUri())) { parameters.put(OAuth2ParameterNames.ERROR_URI, oauth2Error.getUri()); } return parameters; } }
@Override public Map<String, String> convert(OAuth2Error oauth2Error) { Map<String, String> parameters = new HashMap<>(); parameters.put(OAuth2ParameterNames.ERROR, oauth2Error.getErrorCode()); if (StringUtils.hasText(oauth2Error.getDescription())) { parameters.put(OAuth2ParameterNames.ERROR_DESCRIPTION, oauth2Error.getDescription()); } if (StringUtils.hasText(oauth2Error.getUri())) { parameters.put(OAuth2ParameterNames.ERROR_URI, oauth2Error.getUri()); } return parameters; } }
private Map<String, String> createParameters(AuthenticationException authException) { Map<String, String> parameters = new LinkedHashMap<>(); if (this.realmName != null) { parameters.put("realm", this.realmName); } if (authException instanceof OAuth2AuthenticationException) { OAuth2Error error = ((OAuth2AuthenticationException) authException).getError(); parameters.put("error", error.getErrorCode()); if (StringUtils.hasText(error.getDescription())) { parameters.put("error_description", error.getDescription()); } if (StringUtils.hasText(error.getUri())) { parameters.put("error_uri", error.getUri()); } if (error instanceof BearerTokenError) { BearerTokenError bearerTokenError = (BearerTokenError) error; if (StringUtils.hasText(bearerTokenError.getScope())) { parameters.put("scope", bearerTokenError.getScope()); } } } return parameters; }