@Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); String authValue; try { authValue = "Negotiate " + buildAuthorizationHeader("HTTP/" + host); } catch (Exception e) { throw new FailedRequestException(e.getMessage(), e); } Request authenticatedRequest = request.newBuilder().header("Authorization", authValue).build(); return chain.proceed(authenticatedRequest); } }
public HTTPKerberosAuthInterceptor(String host, Map<String,String> krbOptions) { this.host = host; this.krbOptions = krbOptions; try { buildSubjectCredentials(); } catch (LoginException e) { throw new FailedRequestException(e.getMessage(), e); } }
@Override public String advanceLsqt(RequestLogger reqlog, String temporalCollection, long lag) { if (logger.isDebugEnabled()) logger.debug("Advancing LSQT in temporal collection {}", temporalCollection); logRequest(reqlog, "wiped %s document", temporalCollection); RequestParameters params = new RequestParameters(); params.add("result", "advance-lsqt"); if ( lag > 0 ) params.add("lag", String.valueOf(lag)); Map<String,List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); postResource(reqlog, "temporal/collections/" + temporalCollection, null, params, null, null, "advanceLsqt", headers); List<String> values = headers.get(HEADER_ML_LSQT); if ( values != null && values.size() > 0 ) { return values.get(0); } else { throw new FailedRequestException("Response missing header \"" + HEADER_ML_LSQT + "\""); } }
private void checkStatus(Response response, int status, String operation, String entityType, String path, ResponseStatus expected) { if (!expected.isExpected(status)) { FailedRequest failure = extractErrorFields(response); if (status == STATUS_NOT_FOUND) { throw new ResourceNotFoundException("Could not " + operation + " " + entityType + " at " + path, failure); } if ("RESTAPI-CONTENTNOVERSION".equals(failure.getMessageCode())) { throw new FailedRequestException("Content version required to " + operation + " " + entityType + " at " + path, failure); } else if (status == STATUS_FORBIDDEN) { throw new ForbiddenUserException("User is not allowed to " + operation + " " + entityType + " at " + path, failure); } throw new FailedRequestException("failed to " + operation + " " + entityType + " at " + path + ": " + getReasonPhrase(response), failure); } }
@Override public Object run() { try { Oid krb5Mechanism = new Oid("1.2.840.113554.1.2.2"); Oid krb5PrincipalNameType = new Oid("1.2.840.113554.1.2.2.1"); final GSSManager manager = GSSManager.getInstance(); final GSSName clientName = manager.createName(clientPrincipalName, krb5PrincipalNameType); final GSSCredential clientCred = manager.createCredential(clientName, 8 * 3600, krb5Mechanism, GSSCredential.INITIATE_ONLY); final GSSName serverName = manager.createName(serverPrincipalName, krb5PrincipalNameType); final GSSContext context = manager.createContext(serverName, krb5Mechanism, clientCred, GSSContext.DEFAULT_LIFETIME); byte[] inToken = new byte[0]; byte[] outToken = context.initSecContext(inToken, 0, inToken.length); context.requestMutualAuth(true); outputToken.append(new String(Base64.getEncoder().encode(outToken))); context.dispose(); } catch (GSSException exception) { throw new FailedRequestException(exception.getMessage(), exception); } return null; } }
throw new FailedRequestException( "Service unavailable and maximum retry period elapsed: "+ Math.round((System.currentTimeMillis() - startTime) / 1000)+
extractErrorFields(response)); } else { throw new FailedRequestException( "Document existence check failed: " + getReasonPhrase(response),
failure.setStatusString("UNKNOWN"); FailedRequestException ex = failure == null ? new FailedRequestException("failed to " + method + " at " + endpoint + ": " + getReasonPhrase(response)) : new FailedRequestException("failed to " + method + " at " + endpoint + ": " + getReasonPhrase(response), failure); throw ex;
throw new FailedRequestException( "Service unavailable and maximum retry period elapsed: "+ Math.round((System.currentTimeMillis() - startTime) / 1000)+
@Override public void deleteValues(RequestLogger reqlog, String type) throws ForbiddenUserException, FailedRequestException { logger.debug("Deleting {}", type); Request.Builder requestBldr = setupRequest(type, null); requestBldr = addTelemetryAgentId(requestBldr); Function<Request.Builder, Response> doDeleteFunction = new Function<Request.Builder, Response>() { public Response apply(Request.Builder funcBuilder) { return sendRequestOnce(funcBuilder.delete().build()); } }; Response response = sendRequestWithRetry(requestBldr, doDeleteFunction, null); int status = response.code(); if (status == STATUS_FORBIDDEN) { throw new ForbiddenUserException("User is not allowed to delete " + type, extractErrorFields(response)); } if (status != STATUS_NO_CONTENT) { throw new FailedRequestException("delete failed: " + getReasonPhrase(response), extractErrorFields(response)); } response.close(); logRequest(reqlog, "deleted %s values", type); }
throw new FailedRequestException(type + " read failed: " + getReasonPhrase(response), extractErrorFields(response));
private void checkStatus(ClientResponse response, ClientResponse.Status status, String operation, String entityType, String path, ResponseStatus expected) { if (!expected.isExpected(status)) { if (status == ClientResponse.Status.NOT_FOUND) { throw new ResourceNotFoundException("Could not " + operation + " " + entityType + " at " + path, extractErrorFields(response)); } if (status == ClientResponse.Status.FORBIDDEN) { throw new ForbiddenUserException("User is not allowed to " + operation + " " + entityType + " at " + path, extractErrorFields(response)); } throw new FailedRequestException("failed to " + operation + " " + entityType + " at " + path + ": " + status.getReasonPhrase(), extractErrorFields(response)); } }
@Override public void deleteValue(RequestLogger reqlog, String type, String key) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { logger.debug("Deleting {}/{}", type, key); Request.Builder requestBldr = setupRequest(type + "/" + key, null); requestBldr = addTelemetryAgentId(requestBldr); Function<Request.Builder, Response> doDeleteFunction = new Function<Request.Builder, Response>() { public Response apply(Request.Builder funcBuilder) { return sendRequestOnce(funcBuilder.delete().build()); } }; Response response = sendRequestWithRetry(requestBldr, doDeleteFunction, null); int status = response.code(); if (status == STATUS_FORBIDDEN) { throw new ForbiddenUserException("User is not allowed to delete " + type, extractErrorFields(response)); } if (status == STATUS_NOT_FOUND) { throw new ResourceNotFoundException(type + " not found for delete", extractErrorFields(response)); } if (status != STATUS_NO_CONTENT) { throw new FailedRequestException("delete failed: " + getReasonPhrase(response), extractErrorFields(response)); } response.close(); logRequest(reqlog, "deleted %s value with %s key", type, key); }
throw new FailedRequestException("search failed: " + getReasonPhrase(response), extractErrorFields(response));
+ type, extractErrorFields(response)); } else { throw new FailedRequestException(type + " read failed: " + getReasonPhrase(response), extractErrorFields(response));
throw new FailedRequestException("match failed: " + getReasonPhrase(response), extractErrorFields(response));
throw new FailedRequestException("match failed: " + getReasonPhrase(response), extractErrorFields(response));
throw new FailedRequestException("search failed: " + getReasonPhrase(response), extractErrorFields(response));
throw new FailedRequestException("transaction " + result + " failed: " + getReasonPhrase(response), extractErrorFields(response));
throw new FailedRequestException("delete failed: " + getReasonPhrase(response), extractErrorFields(response));