use of nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationUnavailableException in project timbuctoo by HuygensING.
the class AzureVreAuthorizationAccess method deleteVreAuthorizations.
@Override
public void deleteVreAuthorizations(String vreId) throws AuthorizationUnavailableException {
String condition = TableQuery.generateFilterCondition("PartitionKey", TableQuery.QueryComparisons.EQUAL, vreId);
TableBatchOperation deletes = new TableBatchOperation();
for (DynamicTableEntity entity : table.execute(TableQuery.from(DynamicTableEntity.class).where(condition))) {
deletes.delete(entity);
}
try {
table.execute(deletes);
} catch (StorageException e) {
LOG.error("deleteVreAuthorizations failed", e);
throw new AuthorizationUnavailableException("Could not delete authorizations");
}
}
use of nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationUnavailableException 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.v5.security.exceptions.AuthorizationUnavailableException in project timbuctoo by HuygensING.
the class JsonBasedAuthorizerTest method createAuthorizationThrowsAnAuthCreateExWhenTheAuthorizationCollectionThrowsAnAuthUnavailableEx.
@Test(expected = AuthorizationCreationException.class)
public void createAuthorizationThrowsAnAuthCreateExWhenTheAuthorizationCollectionThrowsAnAuthUnavailableEx() throws Exception {
when(authorizationAccess.getOrCreateAuthorization(anyString(), anyString(), anyString())).thenThrow(new AuthorizationUnavailableException());
instance.createAuthorization(VRE_ID, userWithPid(USER_PID), UserRoles.USER_ROLE);
}
use of nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationUnavailableException 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