use of io.gravitee.am.service.model.NewReporter 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.service.model.NewReporter in project gravitee-access-management by gravitee-io.
the class ReporterServiceImpl method createMongoReporter.
private NewReporter createMongoReporter(String domain) {
NewReporter newReporter = new NewReporter();
newReporter.setId(RandomString.generate());
newReporter.setEnabled(true);
newReporter.setName("MongoDB Reporter");
newReporter.setType("mongodb");
newReporter.setConfiguration(createReporterConfig(domain));
return newReporter;
}
use of io.gravitee.am.service.model.NewReporter in project gravitee-access-management by gravitee-io.
the class ReportersResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a reporter for a security domain", notes = "User must have the DOMAIN_REPORTER[CREATE] permission on the specified domain " + "or DOMAIN_REPORTER[CREATE] permission on the specified environment " + "or DOMAIN_REPORTER[CREATE] permission on the specified organization.")
@ApiResponses({ @ApiResponse(code = 201, message = "Reporter created for a security domain", response = Reporter.class), @ApiResponse(code = 500, message = "Internal server error") })
public void create(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, NewReporter newReporter, @Suspended final AsyncResponse response) {
User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_REPORTER, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(irrelevant -> reporterService.create(domain, newReporter, authenticatedUser, false)).map(reporter -> response.resume(Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/reporters/" + reporter.getId())).entity(reporter).build()))).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.service.model.NewReporter in project gravitee-access-management by gravitee-io.
the class ReporterServiceImpl method create.
@Override
public Single<Reporter> create(String domain, NewReporter newReporter, User principal, boolean system) {
LOGGER.debug("Create a new reporter {} for domain {}", newReporter, domain);
Reporter reporter = new Reporter();
reporter.setId(newReporter.getId() == null ? RandomString.generate() : newReporter.getId());
reporter.setEnabled(newReporter.isEnabled());
reporter.setDomain(domain);
reporter.setName(newReporter.getName());
reporter.setSystem(system);
reporter.setType(newReporter.getType());
// currently only audit logs
reporter.setDataType("AUDIT");
reporter.setConfiguration(newReporter.getConfiguration());
reporter.setCreatedAt(new Date());
reporter.setUpdatedAt(reporter.getCreatedAt());
return checkReporterConfiguration(reporter).flatMap(ignore -> reporterRepository.create(reporter)).flatMap(reporter1 -> {
// create event for sync process
Event event = new Event(Type.REPORTER, new Payload(reporter1.getId(), ReferenceType.DOMAIN, reporter1.getDomain(), Action.CREATE));
return eventService.create(event).flatMap(__ -> Single.just(reporter1));
}).onErrorResumeNext(ex -> {
LOGGER.error("An error occurs while trying to create a reporter", ex);
String message = "An error occurs while trying to create a reporter. ";
if (ex instanceof ReporterConfigurationException) {
message += ex.getMessage();
}
return Single.error(new TechnicalManagementException(message, ex));
});
}
use of io.gravitee.am.service.model.NewReporter in project gravitee-access-management by gravitee-io.
the class ReporterServiceImpl method createDefault.
@Override
public Single<Reporter> createDefault(String domain) {
LOGGER.debug("Create default reporter for domain {}", domain);
NewReporter newReporter = createInternal(domain);
if (newReporter == null) {
return Single.error(new ReporterNotFoundException("Reporter type " + this.environment.getProperty("management.type") + " not found"));
}
return create(domain, newReporter);
}
Aggregations