private static Credentials extractCredentials(ClientRequestContext request, Type type) { String usernameKey = null; String passwordKey = null; if (type == null) { usernameKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_USERNAME; passwordKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_PASSWORD; } else if (type == Type.BASIC) { usernameKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_USERNAME; passwordKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_PASSWORD; } else if (type == Type.DIGEST) { usernameKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_DIGEST_USERNAME; passwordKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_DIGEST_PASSWORD; } String userName = (String) request.getProperty(usernameKey); if (userName != null && !userName.equals("")) { byte[] pwdBytes; Object password = request.getProperty(passwordKey); if (password instanceof byte[]) { pwdBytes = ((byte[]) password); } else if (password instanceof String) { pwdBytes = ((String) password).getBytes(CHARACTER_SET); } else { throw new RequestAuthenticationException( LocalizationMessages.AUTHENTICATION_CREDENTIALS_REQUEST_PASSWORD_UNSUPPORTED()); } return new Credentials(userName, pwdBytes); } return null; }
SecurityContext context = (SecurityContext) requestContext.getProperty(ClientSecurityFeature.PROPERTY_CONTEXT); .start(); String explicitProvider = (String) requestContext.getProperty(ClientSecurityFeature.PROPERTY_PROVIDER); outboundEp.addAtribute(name, requestContext.getProperty(name));
private static Credentials extractCredentials(ClientRequestContext request, Type type) { String usernameKey = null; String passwordKey = null; if (type == null) { usernameKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_USERNAME; passwordKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_PASSWORD; } else if (type == Type.BASIC) { usernameKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_USERNAME; passwordKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_PASSWORD; } else if (type == Type.DIGEST) { usernameKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_DIGEST_USERNAME; passwordKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_DIGEST_PASSWORD; } String userName = (String) request.getProperty(usernameKey); if (userName != null && !userName.equals("")) { byte[] pwdBytes; Object password = request.getProperty(passwordKey); if (password instanceof byte[]) { pwdBytes = ((byte[]) password); } else if (password instanceof String) { pwdBytes = ((String) password).getBytes(CHARACTER_SET); } else { throw new RequestAuthenticationException( LocalizationMessages.AUTHENTICATION_CREDENTIALS_REQUEST_PASSWORD_UNSUPPORTED()); } return new Credentials(userName, pwdBytes); } return null; }
@Override public void filter(ClientRequestContext request, ClientResponseContext response) { Span span = tracer.currentSpan(); if (span == null) return; ((Tracer.SpanInScope) request.getProperty(Tracer.SpanInScope.class.getName())).close(); handler.handleReceive(response, null, span); }
private static <T> Optional<T> property(ClientRequestContext requestContext, Class<T> clazz, String propertyName) { return OptionalHelper.from(Optional.empty()) .or(() -> Optional.ofNullable(requestContext.getProperty(propertyName)) .filter(clazz::isInstance)) .or(() -> Optional.ofNullable(requestContext.getConfiguration().getProperty(propertyName)) .filter(clazz::isInstance)) .asOptional() .map(clazz::cast); }
private static Credentials extractCredentials(ClientRequestContext request, Type type) { String usernameKey = null; String passwordKey = null; if (type == null) { usernameKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_USERNAME; passwordKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_PASSWORD; } else if (type == Type.BASIC) { usernameKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_USERNAME; passwordKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_PASSWORD; } else if (type == Type.DIGEST) { usernameKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_DIGEST_USERNAME; passwordKey = HttpAuthenticationFeature.HTTP_AUTHENTICATION_DIGEST_PASSWORD; } String userName = (String) request.getProperty(usernameKey); if (userName != null && !userName.equals("")) { byte[] pwdBytes; Object password = request.getProperty(passwordKey); if (password instanceof byte[]) { pwdBytes = ((byte[]) password); } else if (password instanceof String) { pwdBytes = ((String) password).getBytes(CHARACTER_SET); } else { throw new RequestAuthenticationException( LocalizationMessages.AUTHENTICATION_CREDENTIALS_REQUEST_PASSWORD_UNSUPPORTED()); } return new Credentials(userName, pwdBytes); } return null; }
@Override public void filter(ClientRequestContext request) throws IOException { String token = this.accessToken; final String propertyToken = (String) request.getProperty(OAuth2ClientSupport.OAUTH2_PROPERTY_ACCESS_TOKEN); if (propertyToken != null) { token = propertyToken; } request.removeProperty(OAuth2ClientSupport.OAUTH2_PROPERTY_ACCESS_TOKEN); if (token == null) { return; } String authentication = "Bearer " + token; if (!request.getHeaders().containsKey(HttpHeaders.AUTHORIZATION)) { request.getHeaders().add(HttpHeaders.AUTHORIZATION, authentication); } } }
@Override public void filter(ClientRequestContext request, ClientResponseContext response) throws IOException { if ("true".equals(request.getProperty(REQUEST_PROPERTY_FILTER_REUSED))) { return; Type operation = (Type) request.getProperty(REQUEST_PROPERTY_OPERATION); if (operation != null) { updateCache(request, !authenticate, operation);
@Override public void filter(ClientRequestContext request, ClientResponseContext response) throws IOException { if ("true".equals(request.getProperty(REQUEST_PROPERTY_FILTER_REUSED))) { return; Type operation = (Type) request.getProperty(REQUEST_PROPERTY_OPERATION); if (operation != null) { updateCache(request, !authenticate, operation);
@Override public void filter(ClientRequestContext request, ClientResponseContext response) throws IOException { if ("true".equals(request.getProperty(REQUEST_PROPERTY_FILTER_REUSED))) { return; Type operation = (Type) request.getProperty(REQUEST_PROPERTY_OPERATION); if (operation != null) { updateCache(request, !authenticate, operation);
@Override public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) throws IOException { if (!logger.isLoggable(level)) { return; } final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY); final long id = requestId != null ? (Long) requestId : _id.incrementAndGet(); final StringBuilder b = new StringBuilder(); printResponseLine(b, "Client response received", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders()); if (responseContext.hasEntity() && printEntity(verbosity, responseContext.getMediaType())) { responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream(), MessageUtils.getCharset(responseContext.getMediaType()))); } log(b); } }
@Override public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) throws IOException { if (!logger.isLoggable(level)) { return; } final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY); final long id = requestId != null ? (Long) requestId : _id.incrementAndGet(); final StringBuilder b = new StringBuilder(); printResponseLine(b, "Client response received", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders()); if (responseContext.hasEntity() && printEntity(verbosity, responseContext.getMediaType())) { responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream(), MessageUtils.getCharset(responseContext.getMediaType()))); } log(b); } }
@Override public void filter(ClientRequestContext request) throws IOException { if ("true".equals(request.getProperty(REQUEST_PROPERTY_FILTER_REUSED))) { return;
@Override public void filter(ClientRequestContext request) throws IOException { if ("true".equals(request.getProperty(REQUEST_PROPERTY_FILTER_REUSED))) { return;
@Override public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) { Object property = requestContext.getProperty(SPAN_PROPERTY_NAME); if (property instanceof Span) { Span span = (Span) property; int status = responseContext.getStatus(); Tags.HTTP_STATUS.set(span, status); if (status >= HTTP_STATUS_ERROR_THRESHOLD) { Tags.ERROR.set(span, true); span.log(CollectionsHelper.mapOf("event", "error", "message", "Response HTTP status: " + status, "error.kind", (status < HTTP_STATUS_SERVER_ERROR_THRESHOLD) ? "ClientError" : "ServerError")); } span.finish(); } }
@Override public void filter(ClientRequestContext request) throws IOException { if ("true".equals(request.getProperty(REQUEST_PROPERTY_FILTER_REUSED))) { return;
@Override public void filter(ClientRequestContext requestContext) throws IOException { Tracer.SpanBuilder spanBuilder = GlobalTracer.get() .buildSpan(LocalizationMessages.OPENTRACING_SPAN_PREFIX_CLIENT() + requestContext.getMethod()) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT) .withTag(Tags.HTTP_URL.getKey(), requestContext.getUri().toASCIIString()) .withTag(Tags.HTTP_METHOD.getKey(), requestContext.getMethod()) .withTag(LocalizationMessages.OPENTRACING_TAG_HAS_REQUEST_ENTITY(), requestContext.hasEntity()) .withTag(LocalizationMessages.OPENTRACING_TAG_ACCEPTABLE_MEDIA_TYPES(), requestContext.getAcceptableMediaTypes() .stream() .map(MediaType::toString) .collect(Collectors.joining(", "))) .withTag(LocalizationMessages.OPENTRACING_TAG_REQUEST_HEADERS(), OpenTracingUtils.headersAsString(requestContext.getHeaders())); // if pre-stored "span" property is found, propagate the stored context final Object property = requestContext.getProperty(OpenTracingFeature.SPAN_CONTEXT_PROPERTY); if (property != null && property instanceof SpanContext) { spanBuilder = spanBuilder.asChildOf((SpanContext) property); } Span span = spanBuilder.startManual(); requestContext.setProperty(OpenTracingFeature.SPAN_CONTEXT_PROPERTY, span); Map<String, String> addedHeaders = new HashMap<>(); GlobalTracer.get().inject(span.context(), Format.Builtin.HTTP_HEADERS, new TextMapInjectAdapter(addedHeaders)); addedHeaders.forEach((key, value) -> requestContext.getHeaders().add(key, value)); } }
@Override public void filter(ClientRequestContext request) throws IOException { final ConsumerCredentials consumerFromProperties = (ConsumerCredentials) request.getProperty(OAuth1ClientSupport.OAUTH_PROPERTY_CONSUMER_CREDENTIALS); request.removeProperty(OAuth1ClientSupport.OAUTH_PROPERTY_CONSUMER_CREDENTIALS); = (AccessToken) request.getProperty(OAuth1ClientSupport.OAUTH_PROPERTY_ACCESS_TOKEN); request.removeProperty(OAuth1ClientSupport.OAUTH_PROPERTY_ACCESS_TOKEN); OAuth1Parameters parameters = (OAuth1Parameters) request.getProperty(OAuth1ClientSupport.OAUTH_PROPERTY_OAUTH_PARAMETERS); if (parameters == null) { parameters = (OAuth1Parameters) request.getConfiguration() OAuth1Secrets secrets = (OAuth1Secrets) request.getProperty(OAuth1ClientSupport.OAUTH_PROPERTY_OAUTH_SECRETS); if (secrets == null) { secrets = (OAuth1Secrets) request.getConfiguration().getProperty(OAuth1ClientSupport.OAUTH_PROPERTY_OAUTH_SECRETS);
@Override public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { final Object spanProperty = requestContext.getProperty(OpenTracingFeature.SPAN_CONTEXT_PROPERTY); if (spanProperty != null && spanProperty instanceof Span) { ((Span) spanProperty) .setTag(Tags.HTTP_STATUS.getKey(), responseContext.getStatus()) .setTag(LocalizationMessages.OPENTRACING_TAG_HAS_RESPONSE_ENTITY(), responseContext.hasEntity()) .setTag(LocalizationMessages.OPENTRACING_TAG_RESPONSE_LENGTH(), responseContext.getLength()) .setTag(LocalizationMessages.OPENTRACING_TAG_RESPONSE_HEADERS(), OpenTracingUtils.headersAsString(responseContext.getHeaders())) .finish(); } } }
@Override public void filter(ClientRequestContext requestContext) throws IOException { KeyRepository repository = (KeyRepository) requestContext.getProperty(KeyRepository.class.getName()); if (repository == null) { repository = ResteasyContext.getContextData(KeyRepository.class); } DKIMSignature header = createHeader(repository); requestContext.getHeaders().add(DKIMSignature.DKIM_SIGNATURE, header); }