Example usage for org.springframework.http HttpStatus NETWORK_AUTHENTICATION_REQUIRED

List of usage examples for org.springframework.http HttpStatus NETWORK_AUTHENTICATION_REQUIRED

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus NETWORK_AUTHENTICATION_REQUIRED.

Prototype

HttpStatus NETWORK_AUTHENTICATION_REQUIRED

To view the source code for org.springframework.http HttpStatus NETWORK_AUTHENTICATION_REQUIRED.

Click Source Link

Document

511 Network Authentication Required .

Usage

From source file:com.pubkit.web.controller.BaseController.java

@ExceptionHandler(RoquitoAuthException.class)
void handleAuthError(HttpServletResponse response) throws IOException {
    response.sendError(HttpStatus.NETWORK_AUTHENTICATION_REQUIRED.value());
}

From source file:com.hemou.android.account.AccountUtils.java

/**
 * Is the given {@link Exception} due to a 401 Unauthorized API response?
 * //w  ww  .ja va  2 s  .c o m
 * @param e
 * @return true if 401, false otherwise
 */
public static boolean isUnauthorized(final Exception e) {
    Log.e(TAG, "Exception occured[" + Thread.currentThread().getId() + "]:{type:" + e.getClass().getName() + ","
            + e.getLocalizedMessage() + "}");
    String errorMess = e.getMessage();

    if (!StringUtils.isEmpty(errorMess) && (errorMess.contains("The authorization has expired")
            || errorMess.contains("401 Unauthorized") || errorMess.contains("403 Forbidden")))
        return true;

    if (e instanceof NotAuthorizedException) {
        Log.e(TAG, "?...");
        return true;
    }
    //      if (e instanceof ResourceAccessException)
    //         return true;
    if (e instanceof HttpClientErrorException) {
        HttpClientErrorException expt = (HttpClientErrorException) e;
        HttpStatus status = expt.getStatusCode();
        if (Arrays.asList(HttpStatus.UNAUTHORIZED, HttpStatus.NETWORK_AUTHENTICATION_REQUIRED,
                HttpStatus.NON_AUTHORITATIVE_INFORMATION, HttpStatus.PROXY_AUTHENTICATION_REQUIRED,
                //403??????
                HttpStatus.FORBIDDEN).contains(status))
            return true;
    }

    return false;
}