Search in sources :

Example 11 with SimpleModule

use of io.crnk.core.module.SimpleModule in project crnk-framework by crnk-project.

the class SecurityModuleTest method setup.

@Before
public void setup() {
    // TODO simplify ones simple module is fixed
    SimpleModule appModule = new SimpleModule("app") {

        @Override
        public void setupModule(ModuleContext context) {
            super.setupModule(context);
            context.addSecurityProvider(new SecurityProvider() {

                @Override
                public boolean isUserInRole(String role) {
                    return role.equals(allowedRule);
                }
            });
        }
    };
    appModule.addRepository(new TaskRepository());
    appModule.addRepository(new ProjectRepository());
    Builder builder = SecurityConfig.builder();
    builder.permitAll(ResourcePermission.GET);
    builder.permitRole("taskRole", Task.class, ResourcePermission.ALL);
    builder.permitRole("projectRole", "projects", ResourcePermission.POST);
    SecurityConfig config = builder.build();
    securityModule = SecurityModule.newServerModule(config);
    Assert.assertSame(config, securityModule.getConfig());
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    moduleRegistry.setServiceDiscovery(new EmptyServiceDiscovery());
    moduleRegistry.setResourceRegistry(new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry));
    moduleRegistry.addModule(securityModule);
    moduleRegistry.addModule(appModule);
    moduleRegistry.addModule(new JacksonModule(new ObjectMapper(), false, ImmutableList.of(new OffsetLimitPagingBehavior())));
    moduleRegistry.addModule(new CoreModule());
    moduleRegistry.init(new ObjectMapper());
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ProjectRepository(io.crnk.security.model.ProjectRepository) TaskRepository(io.crnk.security.model.TaskRepository) Builder(io.crnk.security.SecurityConfig.Builder) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) JacksonModule(io.crnk.core.engine.internal.jackson.JacksonModule) SecurityProvider(io.crnk.core.engine.security.SecurityProvider) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) CoreModule(io.crnk.core.engine.internal.CoreModule) SimpleModule(io.crnk.core.module.SimpleModule) EmptyServiceDiscovery(io.crnk.core.module.discovery.EmptyServiceDiscovery) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 12 with SimpleModule

use of io.crnk.core.module.SimpleModule in project crnk-framework by crnk-project.

the class ClientStubBaseTest method setup.

@Before
public void setup() {
    client = new CrnkClient("http://x");
    SimpleModule module = new SimpleModule("test");
    module.addExceptionMapper(new CheckedExceptionMapper());
    client.addModule(module);
    urlBuilder = Mockito.mock(JsonApiUrlBuilder.class);
    stub = new ClientStubBase(client, urlBuilder, Task.class);
}
Also used : CrnkClient(io.crnk.client.CrnkClient) Task(io.crnk.test.mock.models.Task) JsonApiUrlBuilder(io.crnk.core.engine.internal.utils.JsonApiUrlBuilder) SimpleModule(io.crnk.core.module.SimpleModule) Before(org.junit.Before)

Example 13 with SimpleModule

use of io.crnk.core.module.SimpleModule in project crnk-framework by crnk-project.

the class ResourceFieldContributorTest method setup.

@Before
public void setup() {
    MockRepositoryUtil.clear();
    contributedRepository = Mockito.spy(new ContributorRelationshipRepository());
    SimpleModule testModule = new SimpleModule("test");
    testModule.addRepository(new TaskRepository());
    testModule.addRepository(new ProjectRepository());
    testModule.addRepository(new ProjectToTaskRepository());
    testModule.addRepository(contributedRepository);
    boot = new CrnkBoot();
    boot.setServiceDiscovery(new TestServiceDiscovery());
    boot.addModule(testModule);
    boot.boot();
}
Also used : ProjectRepository(io.crnk.core.mock.repository.ProjectRepository) CrnkBoot(io.crnk.core.boot.CrnkBoot) ProjectToTaskRepository(io.crnk.core.mock.repository.ProjectToTaskRepository) TestServiceDiscovery(io.crnk.core.module.discovery.TestServiceDiscovery) ProjectToTaskRepository(io.crnk.core.mock.repository.ProjectToTaskRepository) TaskRepository(io.crnk.core.mock.repository.TaskRepository) SimpleModule(io.crnk.core.module.SimpleModule) Before(org.junit.Before)

Example 14 with SimpleModule

use of io.crnk.core.module.SimpleModule in project crnk-framework by crnk-project.

the class BasicActionTest method setupFeature.

@Override
protected void setupFeature(CrnkTestFeature feature) {
    filter = Mockito.spy(new DocumentFilter() {

        @Override
        public Response filter(DocumentFilterContext filterRequestContext, DocumentFilterChain chain) {
            return chain.doFilter(filterRequestContext);
        }
    });
    SimpleModule testModule = new SimpleModule("testFilter");
    testModule.addFilter(filter);
    feature.addModule(testModule);
}
Also used : DocumentFilterContext(io.crnk.core.engine.filter.DocumentFilterContext) DocumentFilterChain(io.crnk.core.engine.filter.DocumentFilterChain) DocumentFilter(io.crnk.core.engine.filter.DocumentFilter) SimpleModule(io.crnk.core.module.SimpleModule)

Example 15 with SimpleModule

use of io.crnk.core.module.SimpleModule in project crnk-framework by crnk-project.

the class CrnkBoot method setupComponents.

private void setupComponents() {
    // not that the provided default implementation here are added last and
    // as a consequence,
    // can be overriden by other modules, like the
    // JaxrsResourceRepositoryInformationBuilder.
    SimpleModule module = new SimpleModule("discovery") {

        @Override
        public void setupModule(ModuleContext context) {
            this.addHttpRequestProcessor(new JsonApiRequestProcessor(context));
            super.setupModule(context);
        }
    };
    for (JsonApiExceptionMapper<?> exceptionMapper : getInstancesByType(JsonApiExceptionMapper.class)) {
        module.addExceptionMapper(exceptionMapper);
    }
    for (DocumentFilter filter : getInstancesByType(DocumentFilter.class)) {
        module.addFilter(filter);
    }
    for (Object repository : getInstancesByType(Repository.class)) {
        module.addRepository(repository);
    }
    for (Object repository : serviceDiscovery.getInstancesByAnnotation(JsonApiResourceRepository.class)) {
        JsonApiResourceRepository annotation = ClassUtils.getAnnotation(repository.getClass(), JsonApiResourceRepository.class).get();
        Class<?> resourceClass = annotation.value();
        module.addRepository(resourceClass, repository);
    }
    for (Object repository : serviceDiscovery.getInstancesByAnnotation(JsonApiRelationshipRepository.class)) {
        JsonApiRelationshipRepository annotation = ClassUtils.getAnnotation(repository.getClass(), JsonApiRelationshipRepository.class).get();
        module.addRepository(annotation.source(), annotation.target(), repository);
    }
    moduleRegistry.addModule(module);
    moduleRegistry.addModule(new CoreModule());
}
Also used : JsonApiRequestProcessor(io.crnk.core.engine.internal.http.JsonApiRequestProcessor) JsonApiRelationshipRepository(io.crnk.legacy.repository.annotations.JsonApiRelationshipRepository) JsonApiResourceRepository(io.crnk.legacy.repository.annotations.JsonApiResourceRepository) DocumentFilter(io.crnk.core.engine.filter.DocumentFilter) CoreModule(io.crnk.core.engine.internal.CoreModule) SimpleModule(io.crnk.core.module.SimpleModule)

Aggregations

SimpleModule (io.crnk.core.module.SimpleModule)18 Before (org.junit.Before)9 CrnkBoot (io.crnk.core.boot.CrnkBoot)7 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)6 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)5 DocumentFilter (io.crnk.core.engine.filter.DocumentFilter)3 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)3 DocumentFilterChain (io.crnk.core.engine.filter.DocumentFilterChain)2 DocumentFilterContext (io.crnk.core.engine.filter.DocumentFilterContext)2 ResourceInformationProvider (io.crnk.core.engine.information.resource.ResourceInformationProvider)2 CoreModule (io.crnk.core.engine.internal.CoreModule)2 DefaultResourceFieldInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)2 DefaultResourceInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider)2 JacksonResourceFieldInformationProvider (io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider)2 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)2 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 DefaultQuerySpecConverter (io.crnk.legacy.internal.DefaultQuerySpecConverter)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApprovalRelationshipRepository (io.crnk.activiti.example.approval.ApprovalRelationshipRepository)1