Skip to content

Instantly share code, notes, and snippets.

@geapi
Last active November 18, 2016 19:02
Show Gist options
  • Save geapi/7c04701232471e74c49a6b695174d9fb to your computer and use it in GitHub Desktop.
Save geapi/7c04701232471e74c49a6b695174d9fb to your computer and use it in GitHub Desktop.
Helper class that returns encoded basic auth header
package tips.cloudnative.testauthentication;
import org.apache.commons.codec.binary.Base64;
import org.springframework.http.HttpHeaders;
public class TestAuthentication {
public static HttpHeaders basicAuthHeaders() {
String plainCreds = "user:password";
byte[] plainCredsBytes = plainCreds.getBytes();
byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
String base64Creds = new String(base64CredsBytes);
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Basic " + base64Creds);
return headers;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment