Example usage for org.springframework.security.oauth2.common.exceptions OAuth2Exception getAdditionalInformation

List of usage examples for org.springframework.security.oauth2.common.exceptions OAuth2Exception getAdditionalInformation

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.common.exceptions OAuth2Exception getAdditionalInformation.

Prototype

public Map<String, String> getAdditionalInformation() 

Source Link

Document

Get any additional information associated with this error.

Usage

From source file:org.springframework.security.oauth2.common.exception.OAuth2ExceptionJackson2DeserializerTests.java

@Test
public void readValueUndefinedException() throws Exception {
    String accessToken = createResponse("notdefinedcode");
    OAuth2Exception result = mapper.readValue(accessToken, OAuth2Exception.class);
    assertEquals(DETAILS, result.getMessage());
    assertEquals(null, result.getAdditionalInformation());
}

From source file:org.springframework.security.oauth2.common.exception.OAuth2ExceptionJackson2DeserializerTests.java

@Test
public void readValueWithObjects() throws Exception {
    String accessToken = "{\"error\": [\"invalid\",\"client\"], \"error_description\": {\"some\":\"detail\"}, \"foo\": [\"bar\"]}";
    OAuth2Exception result = mapper.readValue(accessToken, OAuth2Exception.class);
    assertEquals("{some=detail}", result.getMessage());
    assertEquals("{foo=[bar]}", result.getAdditionalInformation().toString());
}

From source file:org.springframework.security.oauth2.common.exceptions.OAuth2ExceptionJackson2Serializer.java

@Override
public void serialize(OAuth2Exception value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    jgen.writeStartObject();// w  w  w  .  ja va2s.c o m
    jgen.writeStringField("error", value.getOAuth2ErrorCode());
    jgen.writeStringField("error_description", value.getMessage());
    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();
}

From source file:org.joyrest.oauth2.endpoint.AuthorizationEndpoint.java

private String getUnsuccessfulRedirect(AuthorizationRequest authorizationRequest, OAuth2Exception failure,
        boolean fragment) {
    if (isNull(authorizationRequest) || isNull(authorizationRequest.getRedirectUri())) {
        // we have no redirect for the user. very sad.
        throw new UnapprovedClientAuthenticationException("Authorization failure, and no redirect URI.",
                failure);//from   w  ww  .  ja  v a  2s. co m
    }

    Map<String, String> query = new LinkedHashMap<>();

    query.put("error", failure.getOAuth2ErrorCode());
    query.put("error_description", failure.getMessage());

    if (nonNull(authorizationRequest.getState())) {
        query.put("state", authorizationRequest.getState());
    }

    if (nonNull(failure.getAdditionalInformation())) {
        for (Map.Entry<String, String> additionalInfo : failure.getAdditionalInformation().entrySet()) {
            query.put(additionalInfo.getKey(), additionalInfo.getValue());
        }
    }

    return append(authorizationRequest.getRedirectUri(), query, fragment);
}

From source file:org.cloudfoundry.identity.uaa.oauth.UaaAuthorizationEndpoint.java

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);//from  w  w w . j ava2s.c  o m
    }

    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();

}

From source file:org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint.java

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);/*from w w  w.j a  va 2  s. c  om*/
    }

    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);

}