Search in sources :

Example 1 with OSClientV3

use of org.openstack4j.api.OSClient.OSClientV3 in project openstack4j by ContainX.

the class KeystoneAuthenticationTests method authenticate_userId_password_unscoped_reauthenticate_Test.

/**
 * get an unscoped token, then reauthenticate with it
 *
 * @throws Exception
 */
public void authenticate_userId_password_unscoped_reauthenticate_Test() throws Exception {
    respondWithHeaderAndResource(HEADER_AUTH_PROJECT_RESPONSE, 201, JSON_AUTH_UNSCOPED);
    OSClientV3 osclient_unscoped = OSFactory.builderV3().endpoint(authURL("/v3")).credentials(USER_ID, PASSWORD).authenticate();
    String tokenId_unscoped = osclient_unscoped.getToken().getId();
    respondWithHeaderAndResource(HEADER_AUTH_TOKEN_RESPONSE, 200, JSON_AUTH_PROJECT);
    OSClientV3 osclient_scoped = (OSFactory.builderV3().endpoint(authURL("/v3")).token(tokenId_unscoped).scopeToProject(Identifier.byId(PROJECT_ID)).authenticate());
    String tokenId_scoped = osclient_scoped.getToken().getId();
    respondWithHeaderAndResource(HEADER_REAUTH_TOKEN_RESPONSE, 200, JSON_AUTH_PROJECT);
    associateClientV3(OSFactory.builderV3().endpoint(authURL("/v3")).token(tokenId_scoped).scopeToProject(Identifier.byId(PROJECT_ID)).authenticate());
    assertEquals(osv3.getToken().getUser().getId(), USER_ID);
    assertEquals(osv3.getToken().getProject().getId(), PROJECT_ID);
}
Also used : OSClientV3(org.openstack4j.api.OSClient.OSClientV3)

Example 2 with OSClientV3

use of org.openstack4j.api.OSClient.OSClientV3 in project openstack4j by ContainX.

the class KeystoneAuthenticationTests method authenticate_userId_password_unscopedTokenToScopedToken_Test.

/**
 * get an unscoped token, then use it to get a scoped token
 *
 * @throws Exception
 */
public void authenticate_userId_password_unscopedTokenToScopedToken_Test() throws Exception {
    respondWithHeaderAndResource(HEADER_AUTH_TOKEN_RESPONSE, 201, JSON_AUTH_UNSCOPED);
    OSClientV3 osclient_unscoped = OSFactory.builderV3().endpoint(authURL("/v3")).credentials(USER_ID, PASSWORD).authenticate();
    String tokenUnscopedId = osclient_unscoped.getToken().getId();
    respondWithHeaderAndResource(HEADER_AUTH_PROJECT_RESPONSE, 200, JSON_AUTH_PROJECT);
    OSClientV3 osclient_scoped = OSFactory.builderV3().endpoint(authURL("/v3")).token(tokenUnscopedId).scopeToProject(Identifier.byId(PROJECT_ID)).authenticate();
    String tokenScopedId = osclient_scoped.getToken().getId();
    assertTrue(tokenUnscopedId != tokenScopedId);
}
Also used : OSClientV3(org.openstack4j.api.OSClient.OSClientV3)

Example 3 with OSClientV3

use of org.openstack4j.api.OSClient.OSClientV3 in project openstack4j by ContainX.

the class KeystoneAuthenticationTests method authenticate_token_unscoped.

/*
     * token based authentication
     *
     * @throws Exception
     */
public void authenticate_token_unscoped() throws Exception {
    respondWithHeaderAndResource(HEADER_AUTH_TOKEN_RESPONSE, 201, JSON_AUTH_TOKEN_UNSCOPED);
    OSClientV3 osclient_token_unscoped = (OSFactory.builderV3().endpoint(authURL("/v3")).token(TOKEN_UNSCOPED_ID).authenticate());
    assertEquals(osclient_token_unscoped.getToken().getId(), TOKEN_UNSCOPED_ID);
}
Also used : OSClientV3(org.openstack4j.api.OSClient.OSClientV3)

Example 4 with OSClientV3

use of org.openstack4j.api.OSClient.OSClientV3 in project so by onap.

the class OpenstackClientFactoryImpl method createOpenstackV3Client.

@Override
public OpenstackClient createOpenstackV3Client(OpenstackAccess osAccess) throws OpenstackClientException {
    Preconditions.checkNotNull(osAccess.getUrl(), "Keystone-v3 Auth: endpoint not set.");
    Preconditions.checkNotNull(osAccess.getUser(), "Keystone-v3 Auth: username not set.");
    Preconditions.checkNotNull(osAccess.getPassword(), "Keystone-v3 Auth: password not set.");
    Preconditions.checkNotNull(osAccess.getDomainNameIdentifier(), "Keystone-v3 Auth: domain not set.");
    Preconditions.checkNotNull(osAccess.getRegion(), "Keystone-v3 Auth: region not set.");
    Preconditions.checkNotNull(osAccess.getTenantId(), "Keystone-v3 Auth: tenant-id not set.");
    OSClientV3 client;
    try {
        OSFactory.enableHttpLoggingFilter(true);
        client = OSFactory.builderV3().endpoint(osAccess.getUrl()).credentials(osAccess.getUser(), osAccess.getPassword(), osAccess.getDomainNameIdentifier()).scopeToProject(Identifier.byId(osAccess.getTenantId()), osAccess.getProjectNameIdentifier()).authenticate().useRegion(osAccess.getRegion());
        return new OpenstackV3ClientImpl(client);
    } catch (AuthenticationException exception) {
        throw new OpenstackClientException("Failed to authenticate with Keystone-v3: " + osAccess.getUrl(), exception);
    }
}
Also used : OSClientV3(org.openstack4j.api.OSClient.OSClientV3) AuthenticationException(org.openstack4j.api.exceptions.AuthenticationException) OpenstackClientException(org.onap.so.heatbridge.openstack.api.OpenstackClientException) OpenstackV3ClientImpl(org.onap.so.heatbridge.openstack.api.OpenstackV3ClientImpl)

Aggregations

OSClientV3 (org.openstack4j.api.OSClient.OSClientV3)4 OpenstackClientException (org.onap.so.heatbridge.openstack.api.OpenstackClientException)1 OpenstackV3ClientImpl (org.onap.so.heatbridge.openstack.api.OpenstackV3ClientImpl)1 AuthenticationException (org.openstack4j.api.exceptions.AuthenticationException)1