Last active
November 18, 2016 19:02
-
-
Save geapi/7c04701232471e74c49a6b695174d9fb to your computer and use it in GitHub Desktop.
Helper class that returns encoded basic auth header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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