forked from cer/event-sourcing-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd63640
commit 859a01a
Showing
8 changed files
with
59 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,10 @@ | |
*/ | ||
public class BasicAuthUtils { | ||
|
||
public static HttpHeaders basicAuthHeaders(String username) { | ||
public static HttpHeaders basicAuthHeaders(String username, String password) { | ||
return new HttpHeaders() { | ||
{ | ||
String auth = username + ":"; | ||
String auth = username + ":" + password; | ||
byte[] encodedAuth = Base64.encodeBase64( | ||
auth.getBytes(Charset.forName("US-ASCII"))); | ||
String authHeader = "Basic " + new String(encodedAuth); | ||
|
@@ -24,16 +24,16 @@ public static HttpHeaders basicAuthHeaders(String username) { | |
}; | ||
} | ||
|
||
public static <T> T doBasicAuthenticatedRequest(RestTemplate restTemplate, String url, HttpMethod httpMethod, Class<T> responseType) { | ||
return doBasicAuthenticatedRequest(restTemplate, url, httpMethod, responseType, null); | ||
public static <T> T doBasicAuthenticatedRequest(RestTemplate restTemplate, String url, HttpMethod httpMethod, Class<T> responseType, String email, String password) { | ||
return doBasicAuthenticatedRequest(restTemplate, url, httpMethod, responseType, null, email, password); | ||
} | ||
|
||
public static <T> T doBasicAuthenticatedRequest(RestTemplate restTemplate, String url, HttpMethod httpMethod, Class<T> responseType, Object requestObject) { | ||
public static <T> T doBasicAuthenticatedRequest(RestTemplate restTemplate, String url, HttpMethod httpMethod, Class<T> responseType, Object requestObject, String email, String password) { | ||
HttpEntity httpEntity; | ||
if (requestObject != null) { | ||
httpEntity = new HttpEntity<>(requestObject, BasicAuthUtils.basicAuthHeaders("[email protected]")); | ||
httpEntity = new HttpEntity<>(requestObject, BasicAuthUtils.basicAuthHeaders(email, password)); | ||
} else { | ||
httpEntity = new HttpEntity(BasicAuthUtils.basicAuthHeaders("[email protected]")); | ||
httpEntity = new HttpEntity(BasicAuthUtils.basicAuthHeaders(email, password)); | ||
} | ||
|
||
ResponseEntity<T> responseEntity = restTemplate.exchange(url, | ||
|
This file contains 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