use of nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization in project timbuctoo by HuygensING.
the class LocalFileVreAuthorizationAccess method getOrCreateAuthorization.
@Override
public VreAuthorization getOrCreateAuthorization(String vreId, String userId, String userRole) throws AuthorizationUnavailableException {
Optional<VreAuthorization> authOptional = getAuthorization(vreId, userId);
if (authOptional.isPresent()) {
return authOptional.get();
} else {
try {
synchronized (authorizationsFolder) {
File file = getFileOfVre(vreId);
List<VreAuthorization> authorizations = Lists.newArrayList();
if (file.exists()) {
authorizations = objectMapper.readValue(file, new TypeReference<List<VreAuthorization>>() {
});
}
VreAuthorization vreAuthorization = VreAuthorization.create(vreId, userId, userRole);
authorizations.add(vreAuthorization);
objectMapper.writeValue(file, authorizations.toArray(new VreAuthorization[authorizations.size()]));
return vreAuthorization;
}
} catch (IOException e) {
throw new AuthorizationUnavailableException(e.getMessage());
}
}
}
use of nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization in project timbuctoo by HuygensING.
the class BasicPermissionFetcherTest method getPermissionsReturnsReadPermissionOnlyUserWithoutWritePermissionInDataSet.
@Test
public void getPermissionsReturnsReadPermissionOnlyUserWithoutWritePermissionInDataSet() throws Exception {
VreAuthorization vreAuthorization = mock(VreAuthorization.class);
given(vreAuthorization.isAllowedToWrite()).willReturn(false);
given(vreAuthorizationCrud.getAuthorization(anyString(), any(User.class))).willReturn(Optional.of(vreAuthorization));
Set<Permission> permissions = permissionFetcher.getPermissions(mock(User.class), dataSetMetaData);
assertThat(permissions, contains(Permission.READ));
}
use of nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization in project timbuctoo by HuygensING.
the class BasicPermissionFetcherTest method getPermissionsReturnsPermissionsForGivenUserAndDataSet.
@Test
public void getPermissionsReturnsPermissionsForGivenUserAndDataSet() throws Exception {
VreAuthorization vreAuthorization = mock(VreAuthorization.class);
given(vreAuthorization.isAllowedToWrite()).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.WRITE, Permission.READ));
}
use of nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization in project timbuctoo by HuygensING.
the class VreAuthorizationTest method isAllowedToWriteReturnsFalseIfTheRolesOnlyContainUnverifiedUser.
@Test
public void isAllowedToWriteReturnsFalseIfTheRolesOnlyContainUnverifiedUser() throws Exception {
VreAuthorization instance = VreAuthorization.create("", "", UNVERIFIED_USER_ROLE);
boolean allowedToWrite = instance.isAllowedToWrite();
assertThat(allowedToWrite, is(false));
}
use of nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization in project timbuctoo by HuygensING.
the class VreAuthorizationTest method hasAdminAccessReturnsTrueIfTheRolesContainUnverifiedUserAndAdmin.
@Test
public void hasAdminAccessReturnsTrueIfTheRolesContainUnverifiedUserAndAdmin() throws Exception {
VreAuthorization instance = VreAuthorization.create("", "", UNVERIFIED_USER_ROLE, ADMIN_ROLE);
boolean allowedToWrite = instance.hasAdminAccess();
assertThat(allowedToWrite, is(true));
}
Aggregations