Search in sources :

Example 6 with Permission

use of nl.knaw.huygens.timbuctoo.v5.security.dto.Permission in project timbuctoo by HuygensING.

the class BasicPermissionFetcherTest method getPermissionsReturnsAdminAndReadPermissionsForAdminUserAndDataSet.

@Test
public void getPermissionsReturnsAdminAndReadPermissionsForAdminUserAndDataSet() throws Exception {
    VreAuthorization vreAuthorization = mock(VreAuthorization.class);
    given(vreAuthorization.hasAdminAccess()).willReturn(true);
    given(vreAuthorizationCrud.getAuthorization(anyString(), any(User.class))).willReturn(Optional.of(vreAuthorization));
    Set<Permission> permissions = permissionFetcher.getPermissions(mock(User.class), dataSetMetaData);
    assertThat(permissions, containsInAnyOrder(Permission.ADMIN, Permission.READ));
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) Permission(nl.knaw.huygens.timbuctoo.v5.security.dto.Permission) VreAuthorization(nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization) Test(org.junit.Test)

Example 7 with Permission

use of nl.knaw.huygens.timbuctoo.v5.security.dto.Permission in project timbuctoo by HuygensING.

the class BasicPermissionFetcherTest method getPermissionsReturnsPermissionsForUserWithWriteAccessInPrivateDataset.

@Test
public void getPermissionsReturnsPermissionsForUserWithWriteAccessInPrivateDataset() throws Exception {
    VreAuthorization vreAuthorization = mock(VreAuthorization.class);
    given(vreAuthorization.isAllowedToWrite()).willReturn(true);
    given(vreAuthorizationCrud.getAuthorization(anyString(), any(User.class))).willReturn(Optional.of(vreAuthorization));
    DataSetMetaData dataSetMetaData2 = mock(BasicDataSetMetaData.class);
    given(dataSetMetaData2.getDataSetId()).willReturn("testdatasetid");
    given(dataSetMetaData2.getOwnerId()).willReturn("testownerid");
    given(dataSetMetaData2.isPublished()).willReturn(false);
    Set<Permission> permissions = permissionFetcher.getPermissions(userWithId("testWriterId"), dataSetMetaData2);
    assertThat(permissions, containsInAnyOrder(Permission.READ, Permission.WRITE));
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) Permission(nl.knaw.huygens.timbuctoo.v5.security.dto.Permission) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) VreAuthorization(nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization) Test(org.junit.Test)

Example 8 with Permission

use of nl.knaw.huygens.timbuctoo.v5.security.dto.Permission in project timbuctoo by HuygensING.

the class BasicPermissionFetcherTest method getPermissionsDoesNotReturnReadPermissionForUnauthorizedUserInPrivateDataset.

@Test
public void getPermissionsDoesNotReturnReadPermissionForUnauthorizedUserInPrivateDataset() throws Exception {
    DataSetMetaData dataSetMetaData2 = mock(BasicDataSetMetaData.class);
    given(dataSetMetaData2.getDataSetId()).willReturn("testdatasetid");
    given(dataSetMetaData2.getOwnerId()).willReturn("testownerid");
    given(dataSetMetaData2.isPublished()).willReturn(false);
    Set<Permission> permissions = permissionFetcher.getPermissions(mock(User.class), dataSetMetaData2);
    assertThat(permissions, is(empty()));
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) Permission(nl.knaw.huygens.timbuctoo.v5.security.dto.Permission) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) Test(org.junit.Test)

Example 9 with Permission

use of nl.knaw.huygens.timbuctoo.v5.security.dto.Permission in project timbuctoo by HuygensING.

the class PermissionBasedFieldVisibilityTest method createDataSetWithUserPermissions.

private DataSet createDataSetWithUserPermissions(String combinedId, Set<Permission> permissions) {
    DataSetMetaData dataSetMetaData = createDataSetMetadata(combinedId);
    given(userPermissionCheck.getPermissions(dataSetMetaData)).willReturn(permissions);
    return createDataSet(dataSetMetaData);
}
Also used : DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData)

Example 10 with Permission

use of nl.knaw.huygens.timbuctoo.v5.security.dto.Permission in project timbuctoo by HuygensING.

the class UserPermissionCheckTest method getPermissionsReturnsNoPermissionsForEmptyUserIfPublicDataSet.

@Test
public void getPermissionsReturnsNoPermissionsForEmptyUserIfPublicDataSet() {
    PermissionFetcher permissionFetcher = mock(PermissionFetcher.class);
    Set<Permission> defaultPermissions = Sets.newHashSet(Permission.READ);
    UserPermissionCheck userPermissionCheck = new UserPermissionCheck(Optional.empty(), permissionFetcher, defaultPermissions);
    DataSetMetaData dataSetMetaData = mock(BasicDataSetMetaData.class);
    given(dataSetMetaData.isPublished()).willReturn(true);
    Set<Permission> permissions = userPermissionCheck.getPermissions(dataSetMetaData);
    assertEquals(Sets.newHashSet(Permission.READ), permissions);
}
Also used : PermissionFetcher(nl.knaw.huygens.timbuctoo.v5.security.PermissionFetcher) Permission(nl.knaw.huygens.timbuctoo.v5.security.dto.Permission) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) Test(org.junit.Test)

Aggregations

Permission (nl.knaw.huygens.timbuctoo.v5.security.dto.Permission)9 Test (org.junit.Test)8 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)7 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)7 BasicDataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData)6 VreAuthorization (nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Charsets (com.google.common.base.Charsets)1 Resources (com.google.common.io.Resources)1 Resources.getResource (com.google.common.io.Resources.getResource)1 GraphQLSchema (graphql.schema.GraphQLSchema)1 RuntimeWiring (graphql.schema.idl.RuntimeWiring)1 SchemaGenerator (graphql.schema.idl.SchemaGenerator)1 SchemaParser (graphql.schema.idl.SchemaParser)1 TypeDefinitionRegistry (graphql.schema.idl.TypeDefinitionRegistry)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1