Search in sources :

Example 1 with FeatureDisabledException

use of io.cdap.cdap.common.FeatureDisabledException in project cdap by caskdata.

the class AuthorizationClient method doExecuteRequest.

private HttpResponse doExecuteRequest(HttpRequest request, int... additionalAllowedErrorCodes) throws AccessException {
    try {
        int[] allowedErrorCodes = new int[additionalAllowedErrorCodes.length + 2];
        System.arraycopy(additionalAllowedErrorCodes, 0, allowedErrorCodes, 0, additionalAllowedErrorCodes.length);
        allowedErrorCodes[additionalAllowedErrorCodes.length] = HttpURLConnection.HTTP_NOT_IMPLEMENTED;
        HttpResponse response = restClient.execute(request, config.getAccessToken(), allowedErrorCodes);
        if (HttpURLConnection.HTTP_NOT_IMPLEMENTED == response.getResponseCode()) {
            FeatureDisabledException.Feature feature = FeatureDisabledException.Feature.AUTHORIZATION;
            String enableConfig = Constants.Security.Authorization.ENABLED;
            if (response.getResponseBodyAsString().toLowerCase().contains("authentication")) {
                feature = FeatureDisabledException.Feature.AUTHENTICATION;
                enableConfig = Constants.Security.ENABLED;
            }
            throw new FeatureDisabledException(feature, FeatureDisabledException.CDAP_SITE, enableConfig, "true");
        }
        return response;
    } catch (IOException e) {
        throw new AccessIOException(e);
    }
}
Also used : AccessIOException(io.cdap.cdap.security.spi.AccessIOException) HttpResponse(io.cdap.common.http.HttpResponse) AccessIOException(io.cdap.cdap.security.spi.AccessIOException) IOException(java.io.IOException) FeatureDisabledException(io.cdap.cdap.common.FeatureDisabledException)

Aggregations

FeatureDisabledException (io.cdap.cdap.common.FeatureDisabledException)1 AccessIOException (io.cdap.cdap.security.spi.AccessIOException)1 HttpResponse (io.cdap.common.http.HttpResponse)1 IOException (java.io.IOException)1