Search in sources :

Example 96 with AuthCredentialsServiceState

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

the class AuthTranslationService method handleRequest.

@Override
public void handleRequest(Operation op) {
    switch(op.getAction()) {
        case POST:
            validateOperation(op);
            Operation post = Operation.createPost(createInventoryUri(this.getHost(), AuthCredentialsService.FACTORY_LINK)).setBody(translateCredentials(op)).setCompletion((o, ex) -> {
                if (ex != null) {
                    op.fail(ex);
                    return;
                }
                AuthCredentialsService.AuthCredentialsServiceState authBody = o.getBody(AuthCredentialsService.AuthCredentialsServiceState.class);
                // the POST operation will return the resultant
                // AuthCredentialsServiceState.
                op.setBody(authBody).complete();
            });
            sendRequest(post);
            break;
        default:
            super.handleRequest(op);
    }
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Operation(com.vmware.xenon.common.Operation) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService)

Example 97 with AuthCredentialsServiceState

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

the class EndpointAllocationTaskService method configureAuth.

private AuthCredentialsServiceState configureAuth(EndpointState state) {
    AuthCredentialsServiceState authState = new AuthCredentialsServiceState();
    authState.tenantLinks = state.tenantLinks;
    authState.customProperties = new HashMap<>();
    if (state.customProperties != null) {
        authState.customProperties.putAll(state.customProperties);
    }
    authState.customProperties.put(CUSTOM_PROP_ENPOINT_TYPE, state.endpointType);
    if (state.documentSelfLink != null) {
        authState.customProperties.put(CUSTOM_PROP_ENDPOINT_LINK, state.documentSelfLink);
    }
    return authState;
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 98 with AuthCredentialsServiceState

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

the class AuthCredentialsOperationProcessingChainTest method testPlainTextSystemCredentials.

@Test
public void testPlainTextSystemCredentials() throws Throwable {
    // init EncryptionUtils
    File keyFile = Paths.get(folder.newFolder().getPath(), "encryption.key").toFile();
    System.setProperty(EncryptionUtils.ENCRYPTION_KEY, keyFile.getPath());
    System.setProperty(EncryptionUtils.INIT_KEY_IF_MISSING, "true");
    EncryptionUtils.initEncryptionService();
    AuthCredentialsServiceState credentials = createCredentials("username", "password", true);
    assertEquals("username", credentials.userEmail);
    assertNotNull(credentials.privateKey);
    assertFalse(credentials.privateKey.startsWith(EncryptionUtils.ENCRYPTION_PREFIX));
    assertEquals("password", credentials.privateKey);
    credentials = createCredentials("username2", "password2", false);
    assertEquals("username2", credentials.userEmail);
    assertNotNull(credentials.privateKey);
    assertTrue(credentials.privateKey.startsWith(EncryptionUtils.ENCRYPTION_PREFIX));
    // like AuthBootstrapService does
    AuthCredentialsServiceState credentialsPatch = new AuthCredentialsServiceState();
    credentialsPatch.privateKey = "password2";
    credentialsPatch.customProperties = new HashMap<>();
    credentialsPatch.customProperties.put(CUSTOM_PROP_CREDENTIALS_SCOPE, CredentialsScope.SYSTEM.toString());
    credentials = patchServiceSynchronously(credentials.documentSelfLink, credentialsPatch, AuthCredentialsServiceState.class);
    assertEquals("username2", credentials.userEmail);
    assertNotNull(credentials.privateKey);
    assertFalse(credentials.privateKey.startsWith(EncryptionUtils.ENCRYPTION_PREFIX));
    assertEquals("password2", credentials.privateKey);
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) File(java.io.File) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

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