Search in sources :

Example 1 with AuthorizationUnavailableException

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");
    }
}
Also used : DynamicTableEntity(com.microsoft.azure.storage.table.DynamicTableEntity) TableBatchOperation(com.microsoft.azure.storage.table.TableBatchOperation) StorageException(com.microsoft.azure.storage.StorageException) AuthorizationUnavailableException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationUnavailableException)

Example 2 with AuthorizationUnavailableException

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());
        }
    }
}
Also used : TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(java.io.File) AuthorizationUnavailableException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationUnavailableException) VreAuthorization(nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization)

Example 3 with AuthorizationUnavailableException

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);
}
Also used : AuthorizationUnavailableException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationUnavailableException) Test(org.junit.Test)

Example 4 with AuthorizationUnavailableException

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;
}
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

AuthorizationUnavailableException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationUnavailableException)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 IOException (java.io.IOException)2 VreAuthorization (nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization)2 StorageException (com.microsoft.azure.storage.StorageException)1 DynamicTableEntity (com.microsoft.azure.storage.table.DynamicTableEntity)1 TableBatchOperation (com.microsoft.azure.storage.table.TableBatchOperation)1 File (java.io.File)1 Test (org.junit.Test)1