Skip to content
Permalink
Browse files
Beginning refactoring in preparation for provisioning application spe…
…cific permissions.
  • Loading branch information
mifosio-04-04-2018 committed May 3, 2017
1 parent 580c553 commit fd86eed7b3322d3ccb64a4fa21eb5568fc175b97
Showing 5 changed files with 45 additions and 51 deletions.
@@ -33,6 +33,7 @@ dependencies {
[group: 'io.mifos.provisioner', name: 'api', version: project.version],
[group: 'io.mifos.anubis', name: 'library', version: versions.frameworkanubis],
[group: 'io.mifos.anubis', name: 'api', version: versions.frameworkanubis],
[group: 'io.mifos.permitted-feign-client', name: 'api', version: versions.frameworkanput],
[group: 'io.mifos.identity', name: 'api', version: versions.mifosidentityservice],
[group: 'com.google.code.gson', name: 'gson', version: versions.gson],
[group: 'io.mifos.core', name: 'api', version: versions.frameworkapi],
@@ -19,7 +19,6 @@
import com.datastax.driver.mapping.Mapper;
import com.datastax.driver.mapping.Result;
import io.mifos.anubis.api.v1.domain.ApplicationSignatureSet;
import io.mifos.anubis.api.v1.domain.Signature;
import io.mifos.anubis.config.TenantSignatureRepository;
import io.mifos.core.cassandra.core.CassandraSessionProvider;
import io.mifos.core.lang.AutoTenantContext;
@@ -70,22 +69,39 @@ public void assign(final @Nonnull TenantApplicationEntity tenantApplicationEntit
Assert.notNull(tenantApplicationEntity);
Assert.notNull(appNameToUriMap);

final Optional<TenantEntity> tenantEntity = tenantCassandraRepository.get(tenantApplicationEntity.getTenantIdentifier());
tenantEntity.ifPresent(x -> {
checkApplications(tenantApplicationEntity.getApplications());
final TenantEntity tenantEntity = tenantCassandraRepository.get(tenantApplicationEntity.getTenantIdentifier())
.orElseThrow(() -> ServiceException.notFound("Tenant {0} not found.", tenantApplicationEntity.getTenantIdentifier()));

saveTenantApplicationAssignment(tenantApplicationEntity);
checkApplicationsExist(tenantApplicationEntity.getApplications());

final Set<ApplicationNameToUriPair> applicationNameToUriPairs =
getApplicationNameToUriPairs(tenantApplicationEntity, appNameToUriMap);
saveTenantApplicationAssignment(tenantApplicationEntity);

initializeIsis(x, applicationNameToUriPairs);
final Set<ApplicationNameToUriPair> applicationNameToUriPairs =
getApplicationNameToUriPairs(tenantApplicationEntity, appNameToUriMap);

getLatestIdentityManagerSignatureSet(x).ifPresent(y -> initializeAnubis(x, y.getTimestamp(), y.getIdentityManagerSignature(), applicationNameToUriPairs));
});
getLatestIdentityManagerSignatureSet(tenantEntity)
.ifPresent(y -> initializeSecurity(tenantEntity, y, applicationNameToUriPairs));
}

tenantEntity.orElseThrow(
() -> ServiceException.notFound("Tenant {0} not found.", tenantApplicationEntity.getTenantIdentifier()));
private void initializeSecurity(final TenantEntity tenantEntity,
final ApplicationSignatureSet identityManagerSignatureSet,
final Set<ApplicationNameToUriPair> applicationNameToUriPairs) {
applicationNameToUriPairs.forEach(x -> {
final ApplicationSignatureSet applicationSignatureSet = anubisInitializer.initializeAnubis(
tenantEntity.getIdentifier(),
x.name,
x.uri,
identityManagerSignatureSet.getTimestamp(),
identityManagerSignatureSet.getIdentityManagerSignature());

identityServiceInitializer.postApplicationDetails(
tenantEntity.getIdentifier(),
tenantEntity.getIdentityManagerApplicationName(),
tenantEntity.getIdentityManagerApplicationUri(),
x.name,
x.uri,
applicationSignatureSet);
});
}

private void saveTenantApplicationAssignment(final @Nonnull TenantApplicationEntity tenantApplicationEntity) {
@@ -134,32 +150,6 @@ private Optional<ApplicationSignatureSet> getLatestIdentityManagerSignatureSet(f
}
}

private void initializeIsis(
final @Nonnull TenantEntity tenantEntity,
final @Nonnull Set<ApplicationNameToUriPair> applicationNameToUriPairs) {
applicationNameToUriPairs.forEach(applicationNameUriPair ->
identityServiceInitializer.postPermittableGroups(
tenantEntity.getIdentifier(),
tenantEntity.getIdentityManagerApplicationName(),
tenantEntity.getIdentityManagerApplicationUri(),
applicationNameUriPair.uri));
}

private void initializeAnubis(
final @Nonnull TenantEntity tenantEntity,
final @Nonnull String keyTimestamp,
final @Nonnull Signature identityServiceTenantSignature,
final @Nonnull Set<ApplicationNameToUriPair> applicationNameToUriPairs) {
applicationNameToUriPairs.forEach(applicationNameUriPair ->
anubisInitializer.initializeAnubis(
tenantEntity.getIdentifier(),
applicationNameUriPair.name,
applicationNameUriPair.uri,
keyTimestamp,
identityServiceTenantSignature)
);
}

public TenantApplicationEntity find(final String tenantIdentifier) {
checkTenant(tenantIdentifier);

@@ -195,7 +185,7 @@ void removeApplication(final String name) {
}
}

private void checkApplications(final Set<String> applications) {
private void checkApplicationsExist(final Set<String> applications) {
final Mapper<ApplicationEntity> applicationEntityMapper =
this.cassandraSessionProvider.getAdminSessionMappingManager().mapper(ApplicationEntity.class);

@@ -16,12 +16,12 @@
package io.mifos.provisioner.internal.service.applications;

import io.mifos.anubis.api.v1.client.Anubis;
import io.mifos.anubis.api.v1.domain.ApplicationSignatureSet;
import io.mifos.anubis.api.v1.domain.Signature;
import io.mifos.provisioner.config.ProvisionerConstants;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
@@ -42,20 +42,20 @@ public AnubisInitializer(
this.logger = logger;
}

@Async
public void initializeAnubis(final @Nonnull String tenantIdentifier,
final @Nonnull String applicationName,
final @Nonnull String uri,
final @Nonnull String keyTimestamp,
final @Nonnull Signature signature) {
public ApplicationSignatureSet initializeAnubis(final @Nonnull String tenantIdentifier,
final @Nonnull String applicationName,
final @Nonnull String uri,
final @Nonnull String keyTimestamp,
final @Nonnull Signature signature) {
try (final AutoCloseable ignored
= this.applicationCallContextProvider.getApplicationCallContext(tenantIdentifier, applicationName))
{
final Anubis anubis = this.applicationCallContextProvider.getApplication(Anubis.class, uri);
anubis.createSignatureSet(keyTimestamp, signature);
anubis.initializeResources();
logger.info("Anubis initialization for io.mifos.provisioner.tenant '{}' and application '{}' succeeded with signature '{}'.",
tenantIdentifier, applicationName, signature);
final ApplicationSignatureSet applicationSignatureSet = anubis.createSignatureSet(keyTimestamp, signature);
logger.info("Anubis initialization for io.mifos.provisioner.tenant '{}' and application '{}' succeeded with signature set '{}'.",
tenantIdentifier, applicationName, applicationSignatureSet);
return applicationSignatureSet;

} catch (final Exception e) {
throw new IllegalStateException(e);
@@ -123,11 +123,13 @@ public IdentityServiceInitializationResult initializeIsis(
}
}

public void postPermittableGroups(
public void postApplicationDetails(
final @Nonnull String tenantIdentifier,
final @Nonnull String identityManagerApplicationName,
final @Nonnull String identityManagerApplicationUri,
final @Nonnull String applicationUri)
final @Nonnull String applicationName,
final @Nonnull String applicationUri,
final @Nonnull ApplicationSignatureSet applicationSignatureSet)
{
final List<PermittableEndpoint> permittables;
try (final AutoCloseable ignored = applicationCallContextProvider.getApplicationCallGuestContext(tenantIdentifier)) {
@@ -4,6 +4,7 @@ version '0.1.0-BUILD-SNAPSHOT'
ext.versions = [
mifosidentityservice : '0.1.0-BUILD-SNAPSHOT',
frameworkanubis : '0.1.0-BUILD-SNAPSHOT',
frameworkanput : '0.1.0-BUILD-SNAPSHOT',
frameworkapi : '0.1.0-BUILD-SNAPSHOT',
frameworklang : '0.1.0-BUILD-SNAPSHOT',
frameworkasync : '0.1.0-BUILD-SNAPSHOT',

0 comments on commit fd86eed

Please sign in to comment.