org.apache.hadoop.fs.swift.exceptions.SwiftAuthenticationFailedException Java Examples

The following examples show how to use org.apache.hadoop.fs.swift.exceptions.SwiftAuthenticationFailedException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwiftRestClient.java    From sahara-extra with Apache License 2.0 6 votes vote down vote up
@Override
public AccessToken extractResult(AuthPostMethod method) throws IOException {

  //initial check for failure codes leading to authentication failures
  if (method.getStatusCode() == SC_BAD_REQUEST) {
    throw new SwiftAuthenticationFailedException(
      authenticationRequest.toString(), "POST", authUri, method);
  }

  if (authenticationRequest instanceof AuthenticationRequestV2) {
    return extractResultV2(method);
  } else {
    return extractResultV3(method);
  }

}
 
Example #2
Source File: SwiftRestClient.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Execute a method in a new HttpClient instance.
 * If the auth failed, authenticate then retry the method.
 *
 * @param method methot to exec
 * @param <M> Method type
 * @return the status code
 * @throws IOException on any failure
 */
private <M extends HttpMethod> int exec(M method) throws IOException {
  final HttpClient client = new HttpClient();
  if (proxyHost != null) {
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
            new HttpHost(proxyHost, proxyPort));
  }

  int statusCode = execWithDebugOutput(method, client);

  if ((statusCode == HttpStatus.SC_UNAUTHORIZED
          || statusCode == HttpStatus.SC_BAD_REQUEST)
          && method instanceof AuthPostMethod
          && !useKeystoneAuthentication) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Operation failed with status " + method.getStatusCode() +
               " attempting keystone auth");
    }
    //if rackspace key authentication failed - try custom Keystone authentication
    useKeystoneAuthentication = true;
    final AuthPostMethod authentication = (AuthPostMethod) method;
    //replace rackspace auth with keystone one
    authentication.setRequestEntity(getAuthenticationRequst(keystoneAuthRequest));
    statusCode = execWithDebugOutput(method, client);
  }

  if (statusCode == HttpStatus.SC_UNAUTHORIZED ) {
    //unauthed -or the auth uri rejected it.

    if (method instanceof AuthPostMethod) {
        //unauth response from the AUTH URI itself.
        throw new SwiftAuthenticationFailedException(authRequest.toString(),
                                                     "auth",
                                                     authUri,
                                                     method);
    }
    //any other URL: try again
    if (LOG.isDebugEnabled()) {
      LOG.debug("Reauthenticating");
    }
    //re-auth, this may recurse into the same dir
    authenticate();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Retrying original request");
    }
    statusCode = execWithDebugOutput(method, client);
  }
  return statusCode;
}
 
Example #3
Source File: SwiftRestClient.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Execute a method in a new HttpClient instance.
 * If the auth failed, authenticate then retry the method.
 *
 * @param method methot to exec
 * @param <M> Method type
 * @return the status code
 * @throws IOException on any failure
 */
private <M extends HttpMethod> int exec(M method) throws IOException {
  final HttpClient client = new HttpClient();
  if (proxyHost != null) {
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
            new HttpHost(proxyHost, proxyPort));
  }

  int statusCode = execWithDebugOutput(method, client);

  if ((statusCode == HttpStatus.SC_UNAUTHORIZED
          || statusCode == HttpStatus.SC_BAD_REQUEST)
          && method instanceof AuthPostMethod
          && !useKeystoneAuthentication) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Operation failed with status " + method.getStatusCode() +
               " attempting keystone auth");
    }
    //if rackspace key authentication failed - try custom Keystone authentication
    useKeystoneAuthentication = true;
    final AuthPostMethod authentication = (AuthPostMethod) method;
    //replace rackspace auth with keystone one
    authentication.setRequestEntity(getAuthenticationRequst(keystoneAuthRequest));
    statusCode = execWithDebugOutput(method, client);
  }

  if (statusCode == HttpStatus.SC_UNAUTHORIZED ) {
    //unauthed -or the auth uri rejected it.

    if (method instanceof AuthPostMethod) {
        //unauth response from the AUTH URI itself.
        throw new SwiftAuthenticationFailedException(authRequest.toString(),
                                                     "auth",
                                                     authUri,
                                                     method);
    }
    //any other URL: try again
    if (LOG.isDebugEnabled()) {
      LOG.debug("Reauthenticating");
    }
    //re-auth, this may recurse into the same dir
    authenticate();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Retrying original request");
    }
    statusCode = execWithDebugOutput(method, client);
  }
  return statusCode;
}
 
Example #4
Source File: SwiftRestClient.java    From sahara-extra with Apache License 2.0 4 votes vote down vote up
/**
 * Execute a method in a new HttpClient instance.
 * If the auth failed, authenticate then retry the method.
 *
 * @param method methot to exec
 * @param <M> Method type
 * @return the status code
 * @throws IOException on any failure
 */
private <M extends HttpMethod> int exec(M method) throws IOException {
  final HttpClient client = new HttpClient();
  if (proxyHost != null) {
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
            new HttpHost(proxyHost, proxyPort));
  }

  int statusCode = execWithDebugOutput(method, client);

  if ((statusCode == HttpStatus.SC_UNAUTHORIZED
          || statusCode == HttpStatus.SC_BAD_REQUEST)
          && method instanceof AuthPostMethod
          && !useKeystoneAuthentication) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Operation failed with status " + method.getStatusCode() +
               " attempting keystone auth");
    }
    //if rackspace key authentication failed - try custom Keystone authentication
    useKeystoneAuthentication = true;
    final AuthPostMethod authentication = (AuthPostMethod) method;
    //replace rackspace auth with keystone one
    authentication.setRequestEntity(getAuthenticationRequst(keystoneAuthRequest));
    statusCode = execWithDebugOutput(method, client);
  }

  if (statusCode == HttpStatus.SC_UNAUTHORIZED ) {
    //unauthed -or the auth uri rejected it.

    if (method instanceof AuthPostMethod) {
        //unauth response from the AUTH URI itself.
        throw new SwiftAuthenticationFailedException(authRequest.toString(),
                                                     "auth",
                                                     authUri,
                                                     method);
    }
    //any other URL: try again
    if (LOG.isDebugEnabled()) {
      LOG.debug("Reauthenticating");
    }
    //re-auth, this may recurse into the same dir
    setAuthToken(method, authenticate());
    if (LOG.isDebugEnabled()) {
      LOG.debug("Retrying original request");
    }
    statusCode = execWithDebugOutput(method, client);
  }
  return statusCode;
}