示例#1
0
  private static AuthorizationCode retrieveAuthenticationCode(
      final URI requestURI, final State state) throws ParseException {
    final AuthenticationResponse authenticationResponse =
        AuthenticationResponseParser.parse(requestURI);

    if (authenticationResponse instanceof AuthenticationErrorResponse) {
      final ErrorObject error =
          ((AuthenticationErrorResponse) authenticationResponse).getErrorObject();
      throw new GNUOpenBusinessApplicationException(error.getDescription());
    }

    if (((AuthenticationSuccessResponse) authenticationResponse).getState() == null
        || !((AuthenticationSuccessResponse) authenticationResponse)
            .getState()
            .getValue()
            .equals(state.getValue())) {
      throw new GNUOpenBusinessApplicationException(
          "State verification failed, recieved stated is not correct");
    }

    return ((AuthenticationSuccessResponse) authenticationResponse).getAuthorizationCode();
  }