Search in sources :

Example 6 with VreAuthorization

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

the class VreAuthorizationTest method isAllowedToWriteReturnsTrueIfTheRolesContainUser.

@Test
public void isAllowedToWriteReturnsTrueIfTheRolesContainUser() throws Exception {
    VreAuthorization instance = VreAuthorization.create("", "", USER_ROLE);
    boolean allowedToWrite = instance.isAllowedToWrite();
    assertThat(allowedToWrite, is(true));
}
Also used : VreAuthorization(nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization) Test(org.junit.Test)

Example 7 with VreAuthorization

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

the class AzureAccessTest method testVreAuthorization.

@Test
public void testVreAuthorization() throws Exception {
    AzureVreAuthorizationAccess instance = new AzureVreAuthorizationAccess(tableClient);
    Optional<VreAuthorization> beforeCreate = instance.getAuthorization("vreId", "userId");
    VreAuthorization created = instance.getOrCreateAuthorization("vreId", "userId", "role1");
    Optional<VreAuthorization> afterCreate = instance.getAuthorization("vreId", "userId");
    assertThat(beforeCreate, is(not(present())));
    assertThat(afterCreate.get(), is(created));
}
Also used : VreAuthorization(nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization) Test(org.junit.Test)

Example 8 with VreAuthorization

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

the class LocalFileVreAuthorizationAccessTest method getAuthorizationCheckesTheGeneralAccessOfTheUserWhenHeHasNoAccessOnTheDataSet.

@Test
public void getAuthorizationCheckesTheGeneralAccessOfTheUserWhenHeHasNoAccessOnTheDataSet() throws Exception {
    File file = new File(authorizationsFolder.toFile(), "authorizations.json");
    file.createNewFile();
    String testAuthInfo = "[{\"vreId\":\"test_vre\",\"userId\":\"33707283d426f900d4d33707283d426f9testing\"," + "\"roles\":[\"ADMIN\"]}]\n";
    Files.write(file.toPath(), testAuthInfo.getBytes());
    String userId = "33707283d426f900d4d33707283d426f9testing";
    Optional<VreAuthorization> authorization = instance.getAuthorization(VRE, userId);
    assertThat(authorization, is(present()));
    assertThat(authorization.get().hasAdminAccess(), is(true));
}
Also used : File(java.io.File) VreAuthorization(nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization) Test(org.junit.Test)

Example 9 with VreAuthorization

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

the class LocalFileVreAuthorizationAccessTest method addAuthorizationIgnoresTheSecondAdditionForUserToAVre.

@Test
public void addAuthorizationIgnoresTheSecondAdditionForUserToAVre() throws Exception {
    String unknownUser = "unknownUser";
    instance.getOrCreateAuthorization(VRE, unknownUser, UNVERIFIED_USER_ROLE);
    VreAuthorization authorization2 = instance.getOrCreateAuthorization(VRE, unknownUser, ADMIN_ROLE);
    assertThat(authorization2.getRoles(), contains(UNVERIFIED_USER_ROLE));
}
Also used : VreAuthorization(nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization) Test(org.junit.Test)

Example 10 with VreAuthorization

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

the class LocalFileVreAuthorizationAccessTest method setup.

@Before
public void setup() throws Exception {
    authorizationsFolder = makeTempDir();
    vreAuthPath = authorizationsFolder.resolve(VRE);
    vreAuthPath.toFile().mkdirs();
    VreAuthorization[] authorizations = { VreAuthorization.create(VRE, USER_ID, "USER"), VreAuthorization.create(VRE, USER_ID_WITHOUT_WRITE_PERMISSIONS, UNVERIFIED_USER_ROLE) };
    File file = vreAuthPath.resolve(AUTH_FILE).toFile();
    objectMapper = new ObjectMapper();
    objectMapper.writeValue(file, authorizations);
    instance = new LocalFileVreAuthorizationAccess(authorizationsFolder);
}
Also used : File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VreAuthorization(nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization) Before(org.junit.Before)

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