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);
}
}
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;
}
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);
}
Aggregations