Search in sources :

Example 1 with Credentials

use of com.b2international.snowowl.core.identity.Credentials in project snow-owl by b2ihealthcare.

the class CisClient method login.

public void login() {
    final String tokenBeforeLogin = getToken();
    LogUtils.logUserAccess(LOGGER, username, "Logging in to Component Identifier service.");
    HttpPost request = null;
    try {
        final Credentials credentials = new Credentials(username, password);
        request = httpPost("login", credentials);
        final String response = execute(request);
        final JsonNode node = mapper.readValue(response, JsonNode.class);
        String tokenAfterLogin = node.get("token").asText();
        // If this replacement fails, someone changed the token by the time we got here; let them have their ways.
        if (token.compareAndSet(tokenBeforeLogin, tokenAfterLogin)) {
            LOGGER.info("Received token from CIS: {}", tokenAfterLogin);
        }
    } catch (IOException e) {
        throw new SnowowlRuntimeException("Exception while logging in.", e);
    } finally {
        if (null != request)
            release(request);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Credentials(com.b2international.snowowl.core.identity.Credentials) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Aggregations

SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1 Credentials (com.b2international.snowowl.core.identity.Credentials)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 HttpPost (org.apache.http.client.methods.HttpPost)1