Search in sources :

Example 1 with IdentityService

use of com.att.cdp.zones.IdentityService in project AJSC by att.

the class TestOpenStackContext method testLoginLogout.

/**
 * Test that we can login and out of the provider, and access the services once logged in (so we dont have to
 * repeatedly login/out)
 *
 * @throws ZoneException
 */
@Test
@Ignore
public void testLoginLogout() throws ZoneException {
    OpenStackContext context = login();
    /*
         * make sure we can retreive all of the services
         */
    ComputeService computeService = context.getComputeService();
    assertNotNull(computeService);
    IdentityService identityService = context.getIdentityService();
    assertNotNull(identityService);
    ImageService imageService = context.getImageService();
    assertNotNull(imageService);
    NetworkService networkService = context.getNetworkService();
    assertNotNull(networkService);
    VolumeService volumeService = context.getVolumeService();
    assertNotNull(volumeService);
    SnapshotService snapshotService = context.getSnapshotService();
    assertNotNull(snapshotService);
    StackService stackService = context.getStackService();
    assertNotNull(stackService);
    /*
         * Services are locally cached by the provider context. If we get them again, we should get the same exact
         * object. Check that too.
         */
    assertTrue(computeService == context.getComputeService());
    assertTrue(identityService == context.getIdentityService());
    assertTrue(imageService == context.getImageService());
    assertTrue(networkService == context.getNetworkService());
    assertTrue(volumeService == context.getVolumeService());
    assertTrue(snapshotService == context.getSnapshotService());
    assertTrue(stackService == context.getStackService());
    /*
         * Test that we can also obtain the connectors
         */
    GlanceConnector glanceConnector = context.getGlanceConnector();
    assertNotNull(glanceConnector);
    NovaConnector novaConnector = context.getNovaConnector();
    assertNotNull(novaConnector);
    QuantumConnector quantumConnector = context.getQuantumConnector();
    assertNotNull(quantumConnector);
    /*
         * Connectors are locally cached, check that
         */
    assertTrue(glanceConnector == context.getGlanceConnector());
    assertTrue(novaConnector == context.getNovaConnector());
    assertTrue(quantumConnector == context.getQuantumConnector());
    /*
         * Now, check that we can obtain the tenant as well
         */
    Tenant tenant = context.getTenant();
    assertNotNull(tenant);
    assertEquals(tenant.getName(), context.getTenantName());
    assertEquals(tenant.getId(), context.getTenantId());
    logout(context);
}
Also used : IdentityService(com.att.cdp.zones.IdentityService) SnapshotService(com.att.cdp.zones.SnapshotService) StackService(com.att.cdp.zones.StackService) Tenant(com.att.cdp.zones.model.Tenant) GlanceConnector(com.att.cdp.openstack.connectors.GlanceConnector) VolumeService(com.att.cdp.zones.VolumeService) QuantumConnector(com.att.cdp.openstack.connectors.QuantumConnector) NetworkService(com.att.cdp.zones.NetworkService) NovaConnector(com.att.cdp.openstack.connectors.NovaConnector) OpenStackComputeService(com.att.cdp.openstack.v2.OpenStackComputeService) ComputeService(com.att.cdp.zones.ComputeService) ImageService(com.att.cdp.zones.ImageService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with IdentityService

use of com.att.cdp.zones.IdentityService in project AJSC by att.

the class TestKeyPairs method testCreateAndDeleteKeypair.

/**
 * Test the creation and deletion of a key pair
 *
 * @throws ZoneException
 *             If the connection to the provider fails
 */
@Test
@Ignore
public void testCreateAndDeleteKeypair() throws ZoneException {
    Context context = connect();
    IdentityService service = context.getIdentityService();
    KeyPair model = new KeyPair(KEYPAIR_NAME, null);
    KeyPair actual = service.createKeyPair(model);
    assertNotNull(actual);
    assertEquals(model.getName(), actual.getName());
    assertNotNull(actual.getFingerprint());
    assertNotNull(actual.getPrivateKey());
    assertNotNull(actual.getPublicKey());
    service.deleteKeyPair(actual);
    context.logout();
}
Also used : Context(com.att.cdp.zones.Context) IdentityService(com.att.cdp.zones.IdentityService) KeyPair(com.att.cdp.zones.model.KeyPair) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with IdentityService

use of com.att.cdp.zones.IdentityService in project AJSC by att.

the class TestKeyPairs method listKeyPairs.

/**
 * @throws ZoneException
 */
@Test
@Ignore
public void listKeyPairs() throws ZoneException {
    Context context = connect();
    IdentityService service = context.getIdentityService();
    List<KeyPair> kps = service.getKeyPairs();
    assertNotNull(kps);
    for (KeyPair kp : kps) {
        if (kp.getName().equals(KEYPAIR_NAME)) {
            fail("KeyPair should not have existed");
        }
    }
    context.logout();
}
Also used : Context(com.att.cdp.zones.Context) IdentityService(com.att.cdp.zones.IdentityService) KeyPair(com.att.cdp.zones.model.KeyPair) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with IdentityService

use of com.att.cdp.zones.IdentityService in project AJSC by att.

the class AbstractContext method login.

/**
 * This method delegates to the identity service the request to login. This is a convenience method.
 *
 * @throws ZoneException
 *             If any of the following conditions are true:
 *             <ul>
 *             <li>the user has not successfully logged in to the provider</li>
 *             <li>the context has been closed and this service is requested</li>
 *             <li>the current user does not have the rights to perform this operation</li>
 *             <li>the user and/or credentials are not valid</li>
 *             </ul>
 * @see com.att.cdp.zones.Context#login(java.lang.String, java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public void login(String principal, String credential) throws IllegalStateException, IllegalArgumentException, ZoneException {
    this.principal = principal;
    this.credentials = credential;
    String msg = String.format("About to login principal [%s] to provider [%s] on tenant [%s] ", principal, provider.getName(), tenantName);
    appLogger.debug(msg);
    securityLogger.info(msg);
    IdentityService identity = getIdentityService();
    if (identity == null) {
        msg = EELFResourceManager.format(Msg.NO_PROVIDER_SERVICE, "Identity", provider.getName());
        appLogger.error(msg);
        securityLogger.error(msg);
        throw new IllegalStateException(msg);
    }
    if (principal == null || principal.trim().length() == 0) {
        msg = EELFResourceManager.format(Msg.INVALID_PRINCIPAL, principal, provider.getName());
        appLogger.error(msg);
        securityLogger.error(msg);
        throw new IllegalArgumentException(msg);
    }
    if (credential == null || credential.trim().length() == 0) {
        msg = EELFResourceManager.format(Msg.INVALID_CREDENTIAL, provider.getName());
        appLogger.error(msg);
        securityLogger.error(msg);
        throw new IllegalArgumentException(msg);
    }
    /*
         * This logic was incorrect and not handling the failed login attempts correctly. This has been revised. If we
         * catch a connection exception during authentication, we will attempt recovery in case it is a communications
         * error. If the retries are exhausted, then we will throw an IllegalStateException.
         */
    int attempts = 0;
    while (attempts < getRetryLimit()) {
        try {
            identity.authenticate(principal, credential);
            msg = EELFResourceManager.format(Msg.PRINCIPAL_HAS_BEEN_AUTHENTICATED, principal, provider.getName(), tenantName);
            appLogger.debug(msg);
            securityLogger.info(msg);
            loggedIn = true;
            tenantName = identity.getTenant().getName();
            String providerName = provider.getName();
            appLogger.debug(EELFResourceManager.format(Msg.PROVIDER_LOGIN, principal, providerName));
            securityLogger.debug(EELFResourceManager.format(Msg.PROVIDER_LOGIN, principal, providerName));
            break;
        } catch (ContextConnectionException e) {
            appLogger.error(EELFResourceManager.format(Msg.RETRY_PROVIDER_CONNECTION, identity.getURL(), e.getClass().getSimpleName(), e.getMessage(), Integer.toString(attempts + 1), Integer.toString(getRetryLimit()), Integer.toString(getRetryDelay())));
            try {
                Thread.sleep(getRetryDelay() * 1000L);
            } catch (InterruptedException ex) {
            // ignore
            }
            attempts++;
        }
    }
    if (attempts >= getRetryLimit()) {
        msg = EELFResourceManager.format(Msg.NO_PROVIDER_SERVICE, "Identity", provider.getName());
        appLogger.error(msg);
        securityLogger.error(msg);
        throw new IllegalStateException(msg);
    }
}
Also used : IdentityService(com.att.cdp.zones.IdentityService) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException)

Aggregations

IdentityService (com.att.cdp.zones.IdentityService)4 Ignore (org.junit.Ignore)3 Test (org.junit.Test)3 Context (com.att.cdp.zones.Context)2 KeyPair (com.att.cdp.zones.model.KeyPair)2 ContextConnectionException (com.att.cdp.exceptions.ContextConnectionException)1 GlanceConnector (com.att.cdp.openstack.connectors.GlanceConnector)1 NovaConnector (com.att.cdp.openstack.connectors.NovaConnector)1 QuantumConnector (com.att.cdp.openstack.connectors.QuantumConnector)1 OpenStackComputeService (com.att.cdp.openstack.v2.OpenStackComputeService)1 ComputeService (com.att.cdp.zones.ComputeService)1 ImageService (com.att.cdp.zones.ImageService)1 NetworkService (com.att.cdp.zones.NetworkService)1 SnapshotService (com.att.cdp.zones.SnapshotService)1 StackService (com.att.cdp.zones.StackService)1 VolumeService (com.att.cdp.zones.VolumeService)1 Tenant (com.att.cdp.zones.model.Tenant)1