Search in sources :

Example 1 with AuthenticationStrategy

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

the class WhenConfiguringAuthenticationStrategy method shouldGetJwtAuthentication.

@Test
public void shouldGetJwtAuthentication() {
    configuration.setClientId(randomString());
    configuration.setClientSecret(randomString());
    configuration.setAuthenticationGateway(randomString());
    configuration.setAuthenticationUser(randomString());
    configuration.setAuthenticationPassword(randomString());
    HttpClient httpClient = mock(HttpClient.class);
    Clock clock = mock(Clock.class);
    AuthenticationStrategy authentication = authFactory.getAuthenticationStrategy(() -> httpClient, () -> clock);
    assertTrue(authentication instanceof JwtAuthentication);
}
Also used : HttpClient(com.opentext.ia.sdk.support.http.HttpClient) AuthenticationStrategy(com.opentext.ia.sdk.support.http.rest.AuthenticationStrategy) Clock(com.opentext.ia.sdk.support.datetime.Clock) JwtAuthentication(com.opentext.ia.sdk.support.http.rest.JwtAuthentication) Test(org.junit.Test)

Example 2 with AuthenticationStrategy

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

the class WhenConfiguringAuthenticationStrategy method shouldGetBasicAuthentication.

@Test
public void shouldGetBasicAuthentication() {
    configuration.setAuthenticationUser(randomString());
    configuration.setAuthenticationPassword(randomString());
    AuthenticationStrategy authentication = authFactory.getAuthenticationStrategy(() -> null, () -> null);
    assertTrue(authentication instanceof BasicAuthentication);
}
Also used : AuthenticationStrategy(com.opentext.ia.sdk.support.http.rest.AuthenticationStrategy) BasicAuthentication(com.opentext.ia.sdk.support.http.rest.BasicAuthentication) Test(org.junit.Test)

Example 3 with AuthenticationStrategy

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

the class PropertiesBasedConfigurer method initRestClient.

private void initRestClient() throws IOException {
    if (restClient == null) {
        HttpClient httpClient = NewInstance.fromConfiguration(configuration, HTTP_CLIENT_CLASSNAME, ApacheHttpClient.class.getName()).as(HttpClient.class);
        AuthenticationStrategy authentication = new AuthenticationStrategyFactory(getServerConfiguration()).getAuthenticationStrategy(() -> httpClient, () -> clock);
        restClient = new RestClient(httpClient);
        restClient.init(authentication);
    }
    cache.setServices(restClient.get(configured(SERVER_URI), Services.class));
}
Also used : AuthenticationStrategyFactory(com.opentext.ia.sdk.client.api.AuthenticationStrategyFactory) ApacheHttpClient(com.opentext.ia.sdk.support.http.apache.ApacheHttpClient) AuthenticationStrategy(com.opentext.ia.sdk.support.http.rest.AuthenticationStrategy) RestClient(com.opentext.ia.sdk.support.http.rest.RestClient)

Example 4 with AuthenticationStrategy

use of com.opentext.ia.sdk.support.http.rest.AuthenticationStrategy 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 AuthenticationStrategy

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

the class ArchiveClients method createRestClient.

private static RestClient createRestClient(ServerConfiguration configuration, Clock clock) {
    HttpClient httpClient = NewInstance.of(configuration.getHttpClientClassName(), ApacheHttpClient.class.getName()).as(HttpClient.class);
    AuthenticationStrategy authentication = new AuthenticationStrategyFactory(configuration).getAuthenticationStrategy(() -> httpClient, () -> clock);
    RestClient result = new RestClient(httpClient);
    result.init(authentication);
    return result;
}
Also used : AuthenticationStrategyFactory(com.opentext.ia.sdk.client.api.AuthenticationStrategyFactory) HttpClient(com.opentext.ia.sdk.support.http.HttpClient) ApacheHttpClient(com.opentext.ia.sdk.support.http.apache.ApacheHttpClient) AuthenticationStrategy(com.opentext.ia.sdk.support.http.rest.AuthenticationStrategy) InfoArchiveRestClient(com.opentext.ia.sdk.client.impl.InfoArchiveRestClient) RestClient(com.opentext.ia.sdk.support.http.rest.RestClient)

Aggregations

AuthenticationStrategy (com.opentext.ia.sdk.support.http.rest.AuthenticationStrategy)6 HttpClient (com.opentext.ia.sdk.support.http.HttpClient)3 ApacheHttpClient (com.opentext.ia.sdk.support.http.apache.ApacheHttpClient)3 Test (org.junit.Test)3 AuthenticationStrategyFactory (com.opentext.ia.sdk.client.api.AuthenticationStrategyFactory)2 JwtAuthentication (com.opentext.ia.sdk.support.http.rest.JwtAuthentication)2 RestClient (com.opentext.ia.sdk.support.http.rest.RestClient)2 InfoArchiveRestClient (com.opentext.ia.sdk.client.impl.InfoArchiveRestClient)1 Clock (com.opentext.ia.sdk.support.datetime.Clock)1 Header (com.opentext.ia.sdk.support.http.Header)1 BasicAuthentication (com.opentext.ia.sdk.support.http.rest.BasicAuthentication)1 GatewayInfo (com.opentext.ia.sdk.support.http.rest.GatewayInfo)1 NonExpiringTokenAuthentication (com.opentext.ia.sdk.support.http.rest.NonExpiringTokenAuthentication)1