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()));
}
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));
}
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));
}
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));
}
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;
}
Aggregations