Search in sources :

Example 1 with Header

use of com.opentext.ia.sdk.support.http.Header in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenMakingClientSideAuthentication method shouldIssueBasicHeader.

@Test
public void shouldIssueBasicHeader() {
    String finalToken = "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8));
    Header authHeader = new Header("Authorization", finalToken);
    assertEquals("Tokens should be the same", authHeader, basicAuth.issueAuthHeader());
}
Also used : Header(com.opentext.ia.sdk.support.http.Header) Test(org.junit.Test)

Example 2 with Header

use of com.opentext.ia.sdk.support.http.Header in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenMakingClientSideAuthentication method shouldIssueGivenHeader.

@Test
public void shouldIssueGivenHeader() {
    String finalToken = "Bearer " + token;
    Header authHeader = new Header("Authorization", finalToken);
    assertEquals("Tokens should be the same", authHeader, tokenAuth.issueAuthHeader());
}
Also used : Header(com.opentext.ia.sdk.support.http.Header) Test(org.junit.Test)

Example 3 with Header

use of com.opentext.ia.sdk.support.http.Header in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenUsingGatewayInfo method shouldCorrecltyFormAuthorizationHeader.

@Test
public void shouldCorrecltyFormAuthorizationHeader() {
    String correctToken = "Basic " + Base64.getEncoder().encodeToString((clientId + ":" + clientSecret).getBytes(StandardCharsets.UTF_8));
    Header correctHeader = new Header("Authorization", correctToken);
    assertEquals("Header should be formed correctly", correctHeader, gatewayInfo.getAuthorizationHeader());
}
Also used : Header(com.opentext.ia.sdk.support.http.Header) Test(org.junit.Test)

Example 4 with Header

use of com.opentext.ia.sdk.support.http.Header in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class Authenticate method main.

@SuppressWarnings("PMD.SystemPrintln")
public static void main(String[] args) {
    HttpClient httpClient = new ApacheHttpClient();
    try {
        // Log in to the gateway with user name & password
        AuthenticationStrategy authentication = new JwtAuthentication(USER_NAME, PASSWORD, new GatewayInfo(GATEWAY_URL, CLIENT_ID, CLIENT_SECRET), httpClient);
        // Get an authentication header using a token provided by the gateway
        Header header = authentication.issueAuthHeader();
        // Use this header in calls using the HTTP client
        System.out.println(header);
    } finally {
        httpClient.close();
    }
}
Also used : GatewayInfo(com.opentext.ia.sdk.support.http.rest.GatewayInfo) Header(com.opentext.ia.sdk.support.http.Header) HttpClient(com.opentext.ia.sdk.support.http.HttpClient) ApacheHttpClient(com.opentext.ia.sdk.support.http.apache.ApacheHttpClient) ApacheHttpClient(com.opentext.ia.sdk.support.http.apache.ApacheHttpClient) AuthenticationStrategy(com.opentext.ia.sdk.support.http.rest.AuthenticationStrategy) JwtAuthentication(com.opentext.ia.sdk.support.http.rest.JwtAuthentication)

Example 5 with Header

use of com.opentext.ia.sdk.support.http.Header in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenMakingJwtAuthentication method shouldCorrectlyFormAuthorizationHeader.

@Test
public void shouldCorrectlyFormAuthorizationHeader() throws IOException {
    String authToken = Base64.getEncoder().encodeToString((clientId + ":" + clientSecret).getBytes(StandardCharsets.UTF_8));
    Header authHeader = new Header("Authorization", "Basic " + authToken);
    Header contentTypeHeader = new Header("Content-Type", ContentType.APPLICATION_FORM_URLENCODED.toString());
    Collection<Header> headers = new ArrayList<>(Arrays.asList(authHeader, contentTypeHeader));
    authentication.issueAuthHeader();
    verify(httpClient).post(any(), eq(headers), eq(AuthenticationSuccess.class), anyString());
}
Also used : Header(com.opentext.ia.sdk.support.http.Header) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Header (com.opentext.ia.sdk.support.http.Header)7 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)2 HttpClient (com.opentext.ia.sdk.support.http.HttpClient)1 ApacheHttpClient (com.opentext.ia.sdk.support.http.apache.ApacheHttpClient)1 AuthenticationStrategy (com.opentext.ia.sdk.support.http.rest.AuthenticationStrategy)1 GatewayInfo (com.opentext.ia.sdk.support.http.rest.GatewayInfo)1 JwtAuthentication (com.opentext.ia.sdk.support.http.rest.JwtAuthentication)1 RuntimeIoException (com.opentext.ia.sdk.support.io.RuntimeIoException)1 IOException (java.io.IOException)1