use of org.openstack4j.openstack.internal.OSClientSession.OSClientSessionV2 in project openstack4j by ContainX.
the class OSAuthenticator method authenticateV2.
private static OSClientV2 authenticateV2(org.openstack4j.openstack.identity.v2.domain.Auth auth, SessionInfo info, Config config) {
HttpRequest<KeystoneAccess> request = HttpRequest.builder(KeystoneAccess.class).header(ClientConstants.HEADER_OS4J_AUTH, TOKEN_INDICATOR).endpoint(info.endpoint).method(HttpMethod.POST).path("/tokens").config(config).entity(auth).build();
HttpResponse response = HttpExecutor.create().execute(request);
if (response.getStatus() >= 400) {
try {
throw mapException(response.getStatusMessage(), response.getStatus());
} finally {
HttpEntityHandler.closeQuietly(response);
}
}
KeystoneAccess access = response.getEntity(KeystoneAccess.class);
if (auth.getType() == Type.CREDENTIALS) {
access = access.applyContext(info.endpoint, (Credentials) auth);
} else if (auth.getType() == Type.RAX_APIKEY) {
access = access.applyContext(info.endpoint, (RaxApiKeyCredentials) auth);
} else {
access = access.applyContext(info.endpoint, (org.openstack4j.openstack.identity.v2.domain.TokenAuth) auth);
}
if (!info.reLinkToExistingSession)
return OSClientSession.OSClientSessionV2.createSession(access, info.perspective, info.provider, config);
OSClientSession.OSClientSessionV2 current = (OSClientSessionV2) OSClientSession.getCurrent();
current.access = access;
return current;
}
use of org.openstack4j.openstack.internal.OSClientSession.OSClientSessionV2 in project openstack4j by ContainX.
the class CustomEndpointURLResolverTest method customImplementation_Test.
/**
* This test validates the custom url endpoint resolver is used when it has
* been configured in the Config class.
*
* @throws IOException
*/
public void customImplementation_Test() throws IOException {
// create the default session
final OSClientSessionV2 customConfigSession = getCustomConfigSession();
// retrieve the default endpoint
final String result = customConfigSession.getEndpoint(ServiceType.IDENTITY);
// and make sure it's the default URL
assertEquals(result, "customUrl", "the message");
}
use of org.openstack4j.openstack.internal.OSClientSession.OSClientSessionV2 in project openstack4j by ContainX.
the class CustomEndpointURLResolverTest method defaultImplementation_Test.
/**
* This test verifies the default logic to retrieve the endpoint URL is
* still working. Internally it will generate the endpoint included in the
* security token.
*
* @throws IOException
*/
public void defaultImplementation_Test() throws IOException {
// create a default session containing the default Config object
final OSClientSessionV2 clientV2 = getDefaultSession();
// use default logic to generate the identity endpoint url
final String result = clientV2.getEndpoint(ServiceType.IDENTITY);
// and make sure it's the default URL
assertEquals(result, "http://127.0.0.1:5000/v2.0", "the message");
}
Aggregations