Search in sources :

Example 41 with Authenticator

use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.

the class AssistantServiceTest method setUp.

/**
 * Sets up the tests.
 *
 * @throws Exception the exception
 */
/*
   * (non-Javadoc)
   * @see com.ibm.watson.common.WatsonServiceTest#setUp()
   */
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    String apiKey = System.getenv("ASSISTANT_APIKEY");
    workspaceId = System.getenv("ASSISTANT_WORKSPACE_ID");
    String serviceUrl = System.getenv("ASSISTANT_URL");
    if (apiKey == null) {
        apiKey = getProperty("assistant.apikey");
        workspaceId = getProperty("assistant.workspace_id");
        serviceUrl = getProperty("assistant.url");
    }
    Assume.assumeFalse("ASSISTANT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey == null);
    Authenticator authenticator = new IamAuthenticator(apiKey);
    service = new Assistant("2019-02-28", authenticator);
    service.setServiceUrl(serviceUrl);
    service.setDefaultHeaders(getDefaultHeaders());
}
Also used : IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Before(org.junit.Before)

Example 42 with Authenticator

use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.

the class AssistantTest method constructClientService.

// Constructs an instance of the service to be used by the tests
public void constructClientService() {
    final String serviceName = "testService";
    // set mock values for global params
    String version = "testString";
    final Authenticator authenticator = new NoAuthAuthenticator();
    assistantService = new Assistant(version, serviceName, authenticator);
    String url = server.url("/").toString();
    assistantService.setServiceUrl(url);
}
Also used : NoAuthAuthenticator(com.ibm.cloud.sdk.core.security.NoAuthAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) NoAuthAuthenticator(com.ibm.cloud.sdk.core.security.NoAuthAuthenticator)

Example 43 with Authenticator

use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.

the class AssistantServiceTest method setUp.

/**
 * Sets up the tests.
 *
 * @throws Exception the exception
 */
/*
   * (non-Javadoc)
   * @see com.ibm.watson.common.WatsonServiceTest#setUp()
   */
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    String apiKey = System.getenv("ASSISTANT_APIKEY");
    assistantId = System.getenv("ASSISTANT_ASSISTANT_ID");
    String serviceUrl = System.getenv("ASSISTANT_URL");
    if (apiKey == null) {
        apiKey = getProperty("assistant.apikey");
        assistantId = getProperty("assistant.assistant_id");
        serviceUrl = getProperty("assistant.url");
    }
    Assume.assumeFalse("ASSISTANT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey == null);
    Authenticator authenticator = new IamAuthenticator(apiKey);
    service = new Assistant("2019-02-28", authenticator);
    service.setServiceUrl(serviceUrl);
    service.setDefaultHeaders(getDefaultHeaders());
}
Also used : IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Before(org.junit.Before)

Example 44 with Authenticator

use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.

the class DiscoveryIT method setUp.

/**
 * Sets up the tests.
 *
 * @throws Exception the exception
 */
/*
   * (non-Javadoc)
   *
   * @see com.ibm.watson.common.WatsonServiceTest#setUp()
   */
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    String apiKey = System.getenv("DISCOVERY_V2_APIKEY");
    String serviceUrl = System.getenv("DISCOVERY_V2_URL");
    if (apiKey == null) {
        apiKey = getProperty("discovery_v2.apikey");
        serviceUrl = getProperty("discovery_v2.url");
    }
    assertNotNull("DISCOVERY_V2_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);
    Authenticator authenticator = new IamAuthenticator(apiKey);
    service = new Discovery(VERSION, authenticator);
    service.setDefaultHeaders(getDefaultHeaders());
    service.setServiceUrl(serviceUrl);
    HttpConfigOptions configOptions = new HttpConfigOptions.Builder().disableSslVerification(true).build();
    service.configureClient(configOptions);
}
Also used : HttpConfigOptions(com.ibm.cloud.sdk.core.http.HttpConfigOptions) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) Before(org.junit.Before)

Example 45 with Authenticator

use of com.ibm.cloud.sdk.core.security.Authenticator in project cloudant-java-sdk by IBM.

the class DelegatingAuthenticatorFactoryTest method getAuthenticatorForOtherAuthType.

@Test
void getAuthenticatorForOtherAuthType() {
    Authenticator authenticator = DelegatingAuthenticatorFactory.getAuthenticator("test", getServicePropsWithAuthType(Authenticator.PROPNAME_AUTH_TYPE, "BASIC"));
    assertFalse(authenticator instanceof CouchDbSessionAuthenticator, "Should not return " + "an instance of CouchDbSessionAuthenticator");
}
Also used : CouchDbSessionAuthenticator(com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) CouchDbSessionAuthenticator(com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator) Test(org.testng.annotations.Test)

Aggregations

Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)58 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)32 Before (org.junit.Before)15 NoAuthAuthenticator (com.ibm.cloud.sdk.core.security.NoAuthAuthenticator)14 Test (org.testng.annotations.Test)8 SpeechRecognitionResults (com.ibm.watson.speech_to_text.v1.model.SpeechRecognitionResults)5 BasicAuthenticator (com.ibm.cloud.sdk.core.security.BasicAuthenticator)4 BearerTokenAuthenticator (com.ibm.cloud.sdk.core.security.BearerTokenAuthenticator)4 File (java.io.File)4 InputStream (java.io.InputStream)4 CouchDbSessionAuthenticator (com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator)3 HttpConfigOptions (com.ibm.cloud.sdk.core.http.HttpConfigOptions)3 Response (com.ibm.cloud.sdk.core.http.Response)2 MessageInput (com.ibm.watson.assistant.v1.model.MessageInput)2 MessageOptions (com.ibm.watson.assistant.v1.model.MessageOptions)2 MessageResponse (com.ibm.watson.assistant.v1.model.MessageResponse)2 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)2 TranslateOptions (com.ibm.watson.language_translator.v3.model.TranslateOptions)2 TranslationResult (com.ibm.watson.language_translator.v3.model.TranslationResult)2 RecognizeWithWebsocketsOptions (com.ibm.watson.speech_to_text.v1.model.RecognizeWithWebsocketsOptions)2