remoting/src/main/java/org/springframework/security/remoting/httpinvoker/AuthenticationSimpleHttpInvokerRequestExecutor.java
protected void prepareConnection(HttpURLConnection con, int contentLength)
			throws IOException {
		super.prepareConnection(con, contentLength);

		Authentication auth = SecurityContextHolder.getContext().getAuthentication();

		if ((auth != null) && (auth.getName() != null) && (auth.getCredentials() != null)
				&& !trustResolver.isAnonymous(auth)) {
			String base64 = auth.getName() + ":" + auth.getCredentials().toString();
			con.setRequestProperty("Authorization",
					"Basic " + new String(Base64.getEncoder().encode(base64.getBytes())));

			if (logger.isDebugEnabled()) {
				logger.debug("HttpInvocation now presenting via BASIC authentication SecurityContextHolder-derived: "
						+ auth.toString());
			}
		}
		else {
			if (logger.isDebugEnabled()) {
				logger.debug("Unable to set BASIC authentication header as SecurityContext did not provide "
						+ "valid Authentication: " + auth);
			}
		}

		doPrepareConnection(con, contentLength);
	}
protected void prepareConnection(HttpURLConnection con, int contentLength)
			throws IOException {
		super.prepareConnection(con, contentLength);

		Authentication auth = SecurityContextHolder.getContext().getAuthentication();

		if ((auth != null) && (auth.getName() != null) && (auth.getCredentials() != null)
				&& !trustResolver.isAnonymous(auth)) {
			String base64 = auth.getName() + ":" + auth.getCredentials().toString();
			con.setRequestProperty("Authorization",
					"Basic " + new String(Base64.getEncoder().encode(base64.getBytes())));

			if (logger.isDebugEnabled()) {
				logger.debug("HttpInvocation now presenting via BASIC authentication SecurityContextHolder-derived: "
						+ auth.toString());
			}
		}
		else {
			if (logger.isDebugEnabled()) {
				logger.debug("Unable to set BASIC authentication header as SecurityContext did not provide "
						+ "valid Authentication: " + auth);
			}
		}

		doPrepareConnection(con, contentLength);
	}
Called every time a HTTP invocation is made.
<p>
Simply allows the parent to setup the connection, and then adds an
<code>Authorization</code> HTTP header property that will be used for BASIC
authentication.
</p>
<p>
The <code>SecurityContextHolder</code> is used to obtain the relevant principal and
credentials.
</p>

@param con the HTTP connection to prepare
@param contentLength the length of the content to send

@throws IOException if thrown by HttpURLConnection methods