Search in sources :

Example 21 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class AuthCredentialsOperationProcessingChainTest method testPlainTextCredentials.

@Test
public void testPlainTextCredentials() throws Throwable {
    // do NOT init EncryptionUtils
    AuthCredentialsServiceState credentials = createCredentials("username", "password", false);
    assertEquals("username", credentials.userEmail);
    assertNotNull(credentials.privateKey);
    assertFalse(credentials.privateKey.startsWith(EncryptionUtils.ENCRYPTION_PREFIX));
    String publicKey = "-----BEGIN CERTIFICATE-----\nABC\n-----END CERTIFICATE-----";
    credentials = createCredentialsWithKeys(publicKey, "-----BEGIN PRIVATE KEY-----\nDEF\n-----END PRIVATE KEY-----");
    assertEquals(publicKey, credentials.publicKey);
    assertNotNull(credentials.privateKey);
    assertFalse(credentials.privateKey.startsWith(EncryptionUtils.ENCRYPTION_PREFIX));
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 22 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class AuthCredentialsOperationProcessingChainTest method createCredentials.

protected AuthCredentialsServiceState createCredentials(String username, String password, boolean isSystem) throws Throwable {
    AuthCredentialsServiceState credentials = new AuthCredentialsServiceState();
    credentials.userEmail = username;
    credentials.privateKey = password;
    credentials.type = AuthCredentialsType.Password.toString();
    if (isSystem) {
        credentials.customProperties = new HashMap<>();
        credentials.customProperties.put(CUSTOM_PROP_CREDENTIALS_SCOPE, CredentialsScope.SYSTEM.toString());
    }
    return injectOperationProcessingChain(postServiceSynchronously(AuthCredentialsService.FACTORY_LINK, credentials, AuthCredentialsServiceState.class));
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 23 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class AuthCredentialsOperationProcessingChainTest method createCredentialsWithKeys.

protected AuthCredentialsServiceState createCredentialsWithKeys(String publicKey, String privateKey) throws Throwable {
    AuthCredentialsServiceState credentials = new AuthCredentialsServiceState();
    credentials.publicKey = publicKey;
    credentials.privateKey = privateKey;
    credentials.type = AuthCredentialsType.PublicKey.toString();
    return injectOperationProcessingChain(postServiceSynchronously(AuthCredentialsService.FACTORY_LINK, credentials, AuthCredentialsServiceState.class));
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 24 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class EndpointRemovalTaskServiceTest method createAuthCredentials.

private static void createAuthCredentials(BaseModelTest test, String endpointLink, List<String> tenantLinks) throws Throwable {
    AuthCredentialsServiceState auth = new AuthCredentialsServiceState();
    auth.userEmail = "email";
    auth.privateKey = "pass";
    auth.customProperties = new HashMap<>();
    auth.tenantLinks = tenantLinks;
    auth.customProperties.put(CUSTOM_PROP_ENDPOINT_LINK, endpointLink);
    test.postServiceSynchronously(AuthCredentialsService.FACTORY_LINK, auth, AuthCredentialsServiceState.class);
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 25 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class AuthTranslationService method translateCredentials.

private AuthCredentialsServiceState translateCredentials(Operation op) {
    AuthSecrets secrets = op.getBody(AuthSecrets.class);
    if (secrets.environmentName == null) {
        secrets.environmentName = "Unknown";
    }
    AuthCredentialsServiceState authState = new AuthCredentialsServiceState();
    authState.tenantLinks = secrets.tenantLinks;
    switch(secrets.environmentName) {
        case ComputeDescriptionService.ComputeDescription.ENVIRONMENT_NAME_AWS:
            authState.privateKey = secrets.privateKey;
            authState.privateKeyId = secrets.privateKeyId;
            break;
        default:
            authState.userLink = secrets.client_id;
            authState.userEmail = secrets.client_email;
            authState.privateKey = secrets.private_key;
            authState.privateKeyId = secrets.private_key_id;
            authState.tokenReference = secrets.token_uri;
            authState.type = secrets.type;
    }
    return authState;
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Aggregations

AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)98 Operation (com.vmware.xenon.common.Operation)33 Before (org.junit.Before)28 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)25 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)19 UriUtils (com.vmware.xenon.common.UriUtils)18 URI (java.net.URI)18 List (java.util.List)18 HashMap (java.util.HashMap)17 CompletionException (java.util.concurrent.CompletionException)16 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)15 Utils (com.vmware.xenon.common.Utils)15 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)14 StatelessService (com.vmware.xenon.common.StatelessService)13 TimeUnit (java.util.concurrent.TimeUnit)13 Collections (java.util.Collections)12 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)11 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)11 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)10