Search in sources :

Example 1 with FeatureDisabledException

use of co.cask.cdap.common.FeatureDisabledException in project cdap by caskdata.

the class AuthorizationClient method doExecuteRequest.

private HttpResponse doExecuteRequest(HttpRequest request, int... additionalAllowedErrorCodes) throws IOException, UnauthenticatedException, FeatureDisabledException, UnauthorizedException {
    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;
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) FeatureDisabledException(co.cask.cdap.common.FeatureDisabledException)

Aggregations

FeatureDisabledException (co.cask.cdap.common.FeatureDisabledException)1 HttpResponse (co.cask.common.http.HttpResponse)1