Example usage for org.apache.hadoop.security SecurityUtil FAILED_TO_GET_UGI_MSG_HEADER

List of usage examples for org.apache.hadoop.security SecurityUtil FAILED_TO_GET_UGI_MSG_HEADER

Introduction

In this page you can find the example usage for org.apache.hadoop.security SecurityUtil FAILED_TO_GET_UGI_MSG_HEADER.

Prototype

String FAILED_TO_GET_UGI_MSG_HEADER

To view the source code for org.apache.hadoop.security SecurityUtil FAILED_TO_GET_UGI_MSG_HEADER.

Click Source Link

Usage

From source file:com.bigstep.datalake.DLFileSystem.java

License:Apache License

private static Map<?, ?> validateResponse(final HttpOpParam.Op op, final HttpURLConnection conn,
        boolean unwrapException) throws IOException {
    final int code = conn.getResponseCode();
    // server is demanding an authentication we don't support
    if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
        // match hdfs/rpc exception
        throw new AccessControlException(conn.getResponseMessage());
    }/*  w w w  .  j av a 2s .  c  o m*/
    if (code != op.getExpectedHttpResponseCode()) {
        final Map<?, ?> m;
        try {
            m = jsonParse(conn, true);
        } catch (Exception e) {
            throw new IOException(
                    "Unexpected HTTP response: code=" + code + " != " + op.getExpectedHttpResponseCode() + ", "
                            + op.toQueryString() + ", message=" + conn.getResponseMessage(),
                    e);
        }

        if (m == null) {
            throw new IOException(
                    "Unexpected HTTP response: code=" + code + " != " + op.getExpectedHttpResponseCode() + ", "
                            + op.toQueryString() + ", message=" + conn.getResponseMessage());
        } else if (m.get(RemoteException.class.getSimpleName()) == null) {
            return m;
        }

        IOException re = JsonUtil.toRemoteException(m);
        // extract UGI-related exceptions and unwrap InvalidToken
        // the NN mangles these exceptions but the DN does not and may need
        // to re-fetch a token if either report the token is expired
        if (re.getMessage() != null && re.getMessage().startsWith(SecurityUtil.FAILED_TO_GET_UGI_MSG_HEADER)) {
            String[] parts = re.getMessage().split(":\\s+", 3);
            re = new RemoteException(parts[1], parts[2]);
            re = ((RemoteException) re).unwrapRemoteException(SecretManager.InvalidToken.class);
        }
        throw unwrapException ? toIOException(re) : re;
    }
    return null;
}