Search in sources :

Example 1 with AuthorizationController

use of com.bakdata.conquery.models.auth.AuthorizationController in project conquery by bakdata.

the class FormConfigTest method setupTestClass.

@BeforeAll
public void setupTestClass() throws Exception {
    datasetId = dataset.getId();
    datasetId1 = dataset1.getId();
    // Mock DatasetRegistry for translation
    namespacesMock = Mockito.mock(DatasetRegistry.class);
    doAnswer(invocation -> {
        throw new UnsupportedOperationException("Not yet implemented");
    }).when(namespacesMock).getOptional(any());
    doAnswer(invocation -> {
        final DatasetId id = invocation.getArgument(0);
        Namespace namespaceMock = Mockito.mock(Namespace.class);
        if (id.equals(datasetId)) {
            when(namespaceMock.getDataset()).thenReturn(dataset);
        } else if (id.equals(datasetId1)) {
            when(namespaceMock.getDataset()).thenReturn(dataset1);
        } else {
            throw new IllegalStateException("Unkown dataset id.");
        }
        return namespaceMock;
    }).when(namespacesMock).get(any(DatasetId.class));
    when(namespacesMock.getAllDatasets()).thenReturn(List.of(dataset, dataset1));
    when(namespacesMock.injectIntoNew(any(ObjectMapper.class))).thenCallRealMethod();
    when(namespacesMock.inject(any(MutableInjectableValues.class))).thenCallRealMethod();
    storage = new NonPersistentStoreFactory().createMetaStorage();
    ((MutableInjectableValues) FormConfigProcessor.getMAPPER().getInjectableValues()).add(IdResolveContext.class, namespacesMock);
    processor = new FormConfigProcessor(validator, storage, namespacesMock);
    controller = new AuthorizationController(storage, new DevelopmentAuthorizationConfig());
    controller.start();
}
Also used : AuthorizationController(com.bakdata.conquery.models.auth.AuthorizationController) DevelopmentAuthorizationConfig(com.bakdata.conquery.models.config.auth.DevelopmentAuthorizationConfig) FormConfigProcessor(com.bakdata.conquery.models.forms.frontendconfiguration.FormConfigProcessor) MutableInjectableValues(com.bakdata.conquery.io.jackson.MutableInjectableValues) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) Namespace(com.bakdata.conquery.models.worker.Namespace) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with AuthorizationController

use of com.bakdata.conquery.models.auth.AuthorizationController in project conquery by bakdata.

the class ManagerNode method run.

public void run(ConqueryConfig config, Environment environment) throws InterruptedException {
    this.environment = environment;
    validator = environment.getValidator();
    client = new JerseyClientBuilder(environment).using(config.getJerseyClient()).build(getName());
    // Instantiate DatasetRegistry and MetaStorage so they are ready for injection into the object mapper (API + Storage)
    // The validator is already injected at this point see Conquery.java
    datasetRegistry = new DatasetRegistry(config.getCluster().getEntityBucketSize());
    storage = new MetaStorage(datasetRegistry);
    datasetRegistry.injectInto(environment.getObjectMapper());
    storage.injectInto(environment.getObjectMapper());
    jobManager = new JobManager("ManagerNode", config.isFailOnError());
    formScanner = new FormScanner();
    this.config = config;
    config.initialize(this);
    // Initialization of internationalization
    I18n.init();
    RESTServer.configure(config, environment.jersey().getResourceConfig());
    maintenanceService = environment.lifecycle().scheduledExecutorService("Maintenance Service").build();
    environment.lifecycle().manage(this);
    loadNamespaces();
    loadMetaStorage();
    authController = new AuthorizationController(storage, config.getAuthorizationRealms());
    environment.lifecycle().manage(authController);
    unprotectedAuthAdmin = AuthServlet.generalSetup(environment.metrics(), config, environment.admin(), environment.getObjectMapper());
    unprotectedAuthApi = AuthServlet.generalSetup(environment.metrics(), config, environment.servlets(), environment.getObjectMapper());
    // Create AdminServlet first to make it available to the realms
    admin = new AdminServlet(this);
    authController.externalInit(this, config.getAuthenticationRealms());
    // Register default components for the admin interface
    admin.register(this);
    log.info("Registering ResourcesProvider");
    for (Class<? extends ResourcesProvider> resourceProvider : CPSTypeIdResolver.listImplementations(ResourcesProvider.class)) {
        try {
            ResourcesProvider provider = resourceProvider.getConstructor().newInstance();
            provider.registerResources(this);
            providers.add(provider);
        } catch (Exception e) {
            log.error("Failed to register Resource {}", resourceProvider, e);
        }
    }
    try {
        formScanner.execute(null, null);
    } catch (Exception e) {
        Throwables.throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
    environment.admin().addTask(formScanner);
    environment.admin().addTask(new QueryCleanupTask(storage, Duration.of(config.getQueries().getOldQueriesTime().getQuantity(), config.getQueries().getOldQueriesTime().getUnit().toChronoUnit())));
    environment.admin().addTask(new PermissionCleanupTask(storage));
    environment.admin().addTask(new ClearFilterSourceSearch());
    environment.admin().addTask(new ReportConsistencyTask(datasetRegistry));
    ShutdownTask shutdown = new ShutdownTask();
    environment.admin().addTask(shutdown);
    environment.lifecycle().addServerLifecycleListener(shutdown);
}
Also used : FormScanner(com.bakdata.conquery.models.forms.frontendconfiguration.FormScanner) ResourcesProvider(com.bakdata.conquery.resources.ResourcesProvider) JobManager(com.bakdata.conquery.models.jobs.JobManager) PermissionCleanupTask(com.bakdata.conquery.tasks.PermissionCleanupTask) ClearFilterSourceSearch(com.bakdata.conquery.tasks.ClearFilterSourceSearch) ReportConsistencyTask(com.bakdata.conquery.tasks.ReportConsistencyTask) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) QueryCleanupTask(com.bakdata.conquery.tasks.QueryCleanupTask) AuthorizationController(com.bakdata.conquery.models.auth.AuthorizationController) AdminServlet(com.bakdata.conquery.resources.admin.AdminServlet) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) ShutdownTask(com.bakdata.conquery.resources.admin.ShutdownTask) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry)

Aggregations

AuthorizationController (com.bakdata.conquery.models.auth.AuthorizationController)2 DatasetRegistry (com.bakdata.conquery.models.worker.DatasetRegistry)2 MutableInjectableValues (com.bakdata.conquery.io.jackson.MutableInjectableValues)1 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)1 DevelopmentAuthorizationConfig (com.bakdata.conquery.models.config.auth.DevelopmentAuthorizationConfig)1 FormConfigProcessor (com.bakdata.conquery.models.forms.frontendconfiguration.FormConfigProcessor)1 FormScanner (com.bakdata.conquery.models.forms.frontendconfiguration.FormScanner)1 DatasetId (com.bakdata.conquery.models.identifiable.ids.specific.DatasetId)1 JobManager (com.bakdata.conquery.models.jobs.JobManager)1 Namespace (com.bakdata.conquery.models.worker.Namespace)1 ResourcesProvider (com.bakdata.conquery.resources.ResourcesProvider)1 AdminServlet (com.bakdata.conquery.resources.admin.AdminServlet)1 ShutdownTask (com.bakdata.conquery.resources.admin.ShutdownTask)1 ClearFilterSourceSearch (com.bakdata.conquery.tasks.ClearFilterSourceSearch)1 PermissionCleanupTask (com.bakdata.conquery.tasks.PermissionCleanupTask)1 QueryCleanupTask (com.bakdata.conquery.tasks.QueryCleanupTask)1 ReportConsistencyTask (com.bakdata.conquery.tasks.ReportConsistencyTask)1 NonPersistentStoreFactory (com.bakdata.conquery.util.NonPersistentStoreFactory)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)1