Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RESTEASY-2216] Tests for testing basic authentication with ClientReq…
…uestFilter
- Loading branch information
Showing
2 changed files
with
97 additions
and
20 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
23 changes: 23 additions & 0 deletions
23
...tests/src/test/java/org/jboss/resteasy/test/security/resource/BasicAuthRequestFilter.java
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.jboss.resteasy.test.security.resource; | ||
|
||
|
||
import javax.ws.rs.client.ClientRequestContext; | ||
import javax.ws.rs.client.ClientRequestFilter; | ||
import javax.xml.bind.DatatypeConverter; | ||
import java.io.IOException; | ||
|
||
/** | ||
* This class implements ClientRequestFilter interface. It encodes username and password and adds it to the headers. | ||
*/ | ||
public class BasicAuthRequestFilter implements ClientRequestFilter { | ||
|
||
private final String token; | ||
|
||
public BasicAuthRequestFilter(final String user, final String password) { | ||
this.token = user + ":" + password; | ||
} | ||
|
||
public void filter(ClientRequestContext requestContext) throws IOException { | ||
requestContext.getHeaders().add("Authorization", "Basic " + DatatypeConverter.printBase64Binary(token.getBytes("UTF-8"))); | ||
} | ||
} |