Search in sources :

Example 26 with EntityTypeIdentity

use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.

the class UserPermissionEvaluatorImplTest method hasPermissionOnEntityTypeTrue.

@WithMockUser(username = "USER")
@Test
public void hasPermissionOnEntityTypeTrue() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    when(permissionEvaluator.hasPermission(authentication, "entityType0", "entityType", EntityTypePermission.READ)).thenReturn(true);
    assertTrue(userPermissionEvaluator.hasPermission(new EntityTypeIdentity("entityType0"), EntityTypePermission.READ));
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Authentication(org.springframework.security.core.Authentication) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 27 with EntityTypeIdentity

use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.

the class HasPermissionDirectiveTest method executeWithoutPermission.

@Test
public void executeWithoutPermission() throws TemplateException, IOException {
    when(permissionService.hasPermission(new EntityTypeIdentity("entity"), EntityTypePermission.WRITE)).thenReturn(false);
    Map<String, Object> params = Maps.newHashMap();
    params.put("entityTypeId", "entity");
    params.put("permission", "WRITE");
    directive.execute(new Environment(fakeTemplate, null, envWriter), params, new TemplateModel[0], out -> out.write("PERMISSION"));
    assertEquals(envWriter.toString(), "");
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Environment(freemarker.core.Environment) Test(org.testng.annotations.Test)

Example 28 with EntityTypeIdentity

use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.

the class StaticContentServiceImplTest method submitContentExisting.

@Test
public void submitContentExisting() {
    when(dataService.findOneById(STATIC_CONTENT, "home", StaticContent.class)).thenReturn(staticContent);
    doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(STATIC_CONTENT), EntityTypePermission.WRITE);
    assertTrue(this.staticContentService.submitContent("home", "<p>Updated Content!</p>"));
    verify(staticContent).setContent("<p>Updated Content!</p>");
    verify(dataService).update(STATIC_CONTENT, staticContent);
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 29 with EntityTypeIdentity

use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.

the class StaticContentServiceImplTest method submitContentNoStaticContentPermissions.

@Test(expectedExceptions = MolgenisDataAccessException.class, expectedExceptionsMessageRegExp = "No write permission on static content entity type.")
public void submitContentNoStaticContentPermissions() {
    // doReturn(true).when(permissionService).hasPermission(new PluginIdentity("home"), PluginPermission.WRITE);
    doReturn(false).when(permissionService).hasPermission(new EntityTypeIdentity(STATIC_CONTENT), EntityTypePermission.WRITE);
    this.staticContentService.submitContent("home", "<p>Updated Content!</p>");
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 30 with EntityTypeIdentity

use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.

the class AppsControllerTest method testInit.

@Test(dataProvider = "testInitProvider")
public void testInit(boolean hasWriteAppPermission) throws Exception {
    App app0 = mock(App.class);
    when(app0.getId()).thenReturn("id0");
    when(app0.getName()).thenReturn("name0");
    when(app0.getDescription()).thenReturn("description0");
    when(app0.isActive()).thenReturn(true);
    when(app0.getIconHref()).thenReturn("/icon0.png");
    App app1 = mock(App.class);
    when(app1.getId()).thenReturn("id1");
    when(app1.getName()).thenReturn("name1");
    when(app1.isActive()).thenReturn(false);
    @SuppressWarnings("unchecked") Query<App> query = mock(Query.class);
    when(dataService.query(APP, App.class)).thenReturn(query);
    Sort sort = mock(Sort.class);
    when(query.sort()).thenReturn(sort);
    when(query.findAll()).thenReturn(Stream.of(app0, app1));
    when(permissionService.hasPermission(new EntityTypeIdentity(APP), EntityTypePermission.WRITE)).thenReturn(hasWriteAppPermission);
    AppInfoDto appInfoDto0 = AppInfoDto.builder().setId("id0").setName("name0").setDescription("description0").setActive(true).setIconHref(new URI("/icon0.png")).build();
    AppInfoDto appInfoDto1 = AppInfoDto.builder().setId("id1").setName("name1").setActive(false).build();
    ResultActions resultActions = mockMvc.perform(get(AppsController.URI)).andExpect(status().isOk()).andExpect(view().name("view-apps")).andExpect(model().attribute("appEntityTypeId", APP));
    verify(sort).on(AppMetaData.NAME);
    if (hasWriteAppPermission) {
        resultActions.andExpect(model().attribute("apps", asList(appInfoDto0, appInfoDto1)));
    } else {
        resultActions.andExpect(model().attribute("apps", singletonList(appInfoDto0)));
    }
}
Also used : App(org.molgenis.apps.model.App) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Sort(org.molgenis.data.Sort) ResultActions(org.springframework.test.web.servlet.ResultActions) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)75 Test (org.testng.annotations.Test)57 EntityType (org.molgenis.data.meta.model.EntityType)40 WithMockUser (org.springframework.security.test.context.support.WithMockUser)39 Attribute (org.molgenis.data.meta.model.Attribute)16 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)8 MutableAcl (org.springframework.security.acls.model.MutableAcl)8 EntityTypePermission (org.molgenis.data.security.EntityTypePermission)6 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)6 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)6 Sid (org.springframework.security.acls.model.Sid)6 Entity (org.molgenis.data.Entity)5 Package (org.molgenis.data.meta.model.Package)5 EntityTypePermissionUtils.getCumulativePermission (org.molgenis.data.security.EntityTypePermissionUtils.getCumulativePermission)4 QueryImpl (org.molgenis.data.support.QueryImpl)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 File (java.io.File)3 Map (java.util.Map)3 ADD (org.molgenis.data.DatabaseAction.ADD)3 FileRepositoryCollection (org.molgenis.data.file.support.FileRepositoryCollection)3