Search in sources :

Example 21 with VreAuthorization

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

the class LocalFileVreAuthorizationAccessTest method addAuthorizationCreatesANewFileForAnUnknownVre.

@Test
public void addAuthorizationCreatesANewFileForAnUnknownVre() throws Exception {
    String newVre = "newVRE";
    Optional<VreAuthorization> authorization = instance.getAuthorization(newVre, USER_ID);
    assertThat(authorization, is(not(present())));
    VreAuthorization createAuthorization = instance.getOrCreateAuthorization(newVre, USER_ID, UNVERIFIED_USER_ROLE);
    assertThat(createAuthorization, is(not(nullValue())));
    Optional<VreAuthorization> authorization1 = instance.getAuthorization(newVre, USER_ID);
    assertThat(authorization1, is(present()));
}
Also used : VreAuthorization(nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization) Test(org.junit.Test)

Example 22 with VreAuthorization

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

the class BasicPermissionFetcherTest method getPermissionsReturnsPermissionsForAdminInPrivateDataset.

@Test
public void getPermissionsReturnsPermissionsForAdminInPrivateDataset() throws Exception {
    VreAuthorization vreAuthorization = mock(VreAuthorization.class);
    given(vreAuthorization.hasAdminAccess()).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("testadminId"), dataSetMetaData2);
    assertThat(permissions, containsInAnyOrder(Permission.READ, Permission.ADMIN));
}
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 23 with VreAuthorization

use of nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization 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 24 with VreAuthorization

use of nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization 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 25 with VreAuthorization

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

the class LocalFileVreAuthorizationAccess method getAuthorization.

private Optional<VreAuthorization> getAuthorization(String userId, Optional<VreAuthorization> authorizationValue, File file) throws AuthorizationUnavailableException {
    if (file.exists()) {
        try {
            List<VreAuthorization> authorizations;
            synchronized (authorizationsFolder) {
                authorizations = objectMapper.readValue(file, new TypeReference<List<VreAuthorization>>() {
                });
            }
            authorizationValue = authorizations.stream().filter(authorization -> Objects.equals(authorization.getUserId(), userId)).findAny();
        } catch (IOException e) {
            throw new AuthorizationUnavailableException(e.getMessage());
        }
    }
    return authorizationValue;
}
Also used : TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) AuthorizationUnavailableException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationUnavailableException) VreAuthorization(nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization)

Aggregations

VreAuthorization (nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization)26 Test (org.junit.Test)22 File (java.io.File)5 Permission (nl.knaw.huygens.timbuctoo.v5.security.dto.Permission)5 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 IOException (java.io.IOException)2 BasicDataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData)2 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)2 AuthorizationUnavailableException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationUnavailableException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Before (org.junit.Before)1