use of io.gravitee.am.common.utils.GraviteeContext in project gravitee-access-management by gravitee-io.
the class AuditReporterManagerImpl method loadReporter.
private void loadReporter(io.gravitee.am.model.Reporter reporter) {
AuditReporterLauncher launcher = new AuditReporterLauncher(reporter);
domainService.findById(reporter.getDomain()).flatMapSingle(domain -> {
if (ReferenceType.ENVIRONMENT.equals(domain.getReferenceType())) {
return environmentService.findById(domain.getReferenceId()).map(env -> new GraviteeContext(env.getOrganizationId(), env.getId(), domain.getId()));
} else {
// currently domain is only linked to domainEnv
return Single.error(new EnvironmentNotFoundException("Domain " + reporter.getDomain() + " should be lined to an Environment"));
}
}).subscribeOn(Schedulers.io()).subscribe(launcher);
}
use of io.gravitee.am.common.utils.GraviteeContext in project gravitee-access-management by gravitee-io.
the class AuditReporterManagerImpl method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
logger.info("Register event listener for reporter events for the management API");
eventManager.subscribeForEvents(this, ReporterEvent.class);
// init noOpReporter
noOpReporter = new NoOpReporter();
// init internal reporter (organization reporter)
NewReporter organizationReporter = reporterService.createInternal();
logger.info("Initializing internal " + organizationReporter.getType() + " audit reporter");
internalReporter = reporterPluginManager.create(organizationReporter.getType(), organizationReporter.getConfiguration(), null);
logger.info("Internal audit " + organizationReporter.getType() + " reporter initialized");
logger.info("Initializing audit reporters");
reporterService.findAll().blockingForEach(reporter -> {
logger.info("Initializing audit reporter : {} for domain {}", reporter.getName(), reporter.getDomain());
try {
AuditReporterLauncher launcher = new AuditReporterLauncher(reporter);
domainService.findById(reporter.getDomain()).flatMapSingle(domain -> {
if (ReferenceType.ENVIRONMENT.equals(domain.getReferenceType())) {
return environmentService.findById(domain.getReferenceId()).map(env -> new GraviteeContext(env.getOrganizationId(), env.getId(), domain.getId()));
} else {
// currently domain is only linked to domainEnv
return Single.error(new EnvironmentNotFoundException("Domain " + reporter.getDomain() + " should be lined to an Environment"));
}
}).subscribeOn(Schedulers.io()).subscribe(launcher);
} catch (Exception ex) {
logger.error("An error has occurred while loading audit reporter: {} [{}]", reporter.getName(), reporter.getType(), ex);
removeReporter(reporter.getId());
}
});
// deploy internal reporter verticle
deployReporterVerticle(asList(new EventBusReporterWrapper(vertx, internalReporter)));
}
use of io.gravitee.am.common.utils.GraviteeContext in project gravitee-access-management by gravitee-io.
the class AuditReporterManagerImpl method updateReporter.
private void updateReporter(String reporterId, ReporterEvent reporterEvent) {
final String eventType = reporterEvent.toString().toLowerCase();
logger.info("Domain {} has received {} reporter event for {}", domain.getName(), eventType, reporterId);
reporterRepository.findById(reporterId).flatMapSingle(reporter -> environmentService.findById(domain.getReferenceId()).map(env -> new GraviteeContext(env.getOrganizationId(), env.getId(), domain.getId())).map(ctx -> Tuples.of(reporter, ctx))).subscribeOn(Schedulers.io()).subscribe(tupleReporterContext -> {
updateReporterProvider(tupleReporterContext.getT1(), tupleReporterContext.getT2());
logger.info("Reporter {} {}d for domain {}", reporterId, eventType, domain.getName());
}, error -> logger.error("Unable to {} reporter for domain {}", eventType, domain.getName(), error));
}
use of io.gravitee.am.common.utils.GraviteeContext in project gravitee-access-management by gravitee-io.
the class AuditReporterManagerImpl method deployReporter.
private void deployReporter(String reporterId, ReporterEvent reporterEvent) {
final String eventType = reporterEvent.toString().toLowerCase();
logger.info("Domain {} has received {} reporter event for {}", domain.getName(), eventType, reporterId);
reporterRepository.findById(reporterId).flatMapSingle(reporter -> environmentService.findById(domain.getReferenceId()).map(env -> new GraviteeContext(env.getOrganizationId(), env.getId(), domain.getId())).map(ctx -> Tuples.of(reporter, ctx))).subscribeOn(Schedulers.io()).subscribe(tupleReporterContext -> {
if (reporters.containsKey(reporterId)) {
updateReporterProvider(tupleReporterContext.getT1(), tupleReporterContext.getT2());
} else {
startReporterProvider(tupleReporterContext.getT1(), tupleReporterContext.getT2());
}
logger.info("Reporter {} {}d for domain {}", reporterId, eventType, domain.getName());
}, error -> logger.error("Unable to {} reporter for domain {}", eventType, domain.getName(), error));
}
use of io.gravitee.am.common.utils.GraviteeContext in project gravitee-access-management by gravitee-io.
the class FileAuditReporterTest method buildAuditLogsFilename.
protected String buildAuditLogsFilename() {
GraviteeContext context = GraviteeContext.defaultContext("domain");
String filename = Paths.get(System.getProperty(FileAuditReporter.REPORTERS_FILE_DIRECTORY), context.getOrganizationId(), context.getEnvironmentId(), context.getDomainId(), "FileAuditReporterTest-" + new SimpleDateFormat("yyyy_MM_dd").format(new Date(Instant.now().toEpochMilli())) + "." + Type.valueOf(System.getProperty(FileAuditReporter.REPORTERS_FILE_OUTPUT).toUpperCase()).getExtension()).toFile().getPath();
return filename;
}
Aggregations