@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)); }
@Override public Optional<VreAuthorization> getAuthorization(String vreId, String userId) throws AuthorizationUnavailableException { Optional<VreAuthorization> authorizationValue = Optional.empty(); File file = getFileOfVre(vreId); authorizationValue = getAuthorization(userId, authorizationValue, file); if (!authorizationValue.isPresent()) { file = authorizationsFolder.resolve("authorizations.json").toFile(); authorizationValue = getAuthorization(userId, authorizationValue, file); } return authorizationValue; }
LocalFileVreAuthorizationAccess implements VreAuthorizationAccess { @Override public Optional<VreAuthorization> getAuthorization(String vreId, String userId) throws AuthorizationUnavailableException { Optional<VreAuthorization> authorizationValue = Optional.empty(); File file = getFileOfVre(vreId); authorizationValue = getAuthorization(userId, authorizationValue, file); if (!authorizationValue.isPresent()) { file = authorizationsFolder.resolve("authorizations.json").toFile(); authorizationValue = getAuthorization(userId, authorizationValue, file); } return authorizationValue; } }
LocalFileVreAuthorizationAccess implements VreAuthorizationAccess { @Override public Optional<VreAuthorization> getAuthorization(String vreId, String userId) throws AuthorizationUnavailableException { Optional<VreAuthorization> authorizationValue = Optional.empty(); File file = getFileOfVre(vreId); authorizationValue = getAuthorization(userId, authorizationValue, file); if (!authorizationValue.isPresent()) { file = authorizationsFolder.resolve("authorizations.json").toFile(); authorizationValue = getAuthorization(userId, authorizationValue, file); } return authorizationValue; } LocalFileVreAuthorizationAccess(Path authorizationsFolder); }
LocalFileVreAuthorizationAccess implements VreAuthorizationAccess { @Override public Optional<VreAuthorization> getAuthorization(String vreId, String userId) throws AuthorizationUnavailableException { Optional<VreAuthorization> authorizationValue = Optional.empty(); File file = getFileOfVre(vreId); authorizationValue = getAuthorization(userId, authorizationValue, file); if (!authorizationValue.isPresent()) { file = authorizationsFolder.resolve("authorizations.json").toFile(); authorizationValue = getAuthorization(userId, authorizationValue, file); } return authorizationValue; } LocalFileVreAuthorizationAccess(Path authorizationsFolder); @Override VreAuthorization getOrCreateAuthorization(String vreId, String userId, String userRole); @Override Optional<VreAuthorization> getAuthorization(String vreId, String userId); @Override void deleteVreAuthorizations(String vreId); }
LocalFileVreAuthorizationAccess implements VreAuthorizationAccess { @Override public Optional<VreAuthorization> getAuthorization(String vreId, String userId) throws AuthorizationUnavailableException { Optional<VreAuthorization> authorizationValue = Optional.empty(); File file = getFileOfVre(vreId); authorizationValue = getAuthorization(userId, authorizationValue, file); if (!authorizationValue.isPresent()) { file = authorizationsFolder.resolve("authorizations.json").toFile(); authorizationValue = getAuthorization(userId, authorizationValue, file); } return authorizationValue; } LocalFileVreAuthorizationAccess(Path authorizationsFolder); @Override VreAuthorization getOrCreateAuthorization(String vreId, String userId, String userRole); @Override Optional<VreAuthorization> getAuthorization(String vreId, String userId); @Override void deleteVreAuthorizations(String vreId); static final Logger LOG; }