use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.
the class ConfigStoreIntegrationTestSetup method buildDictionary.
@Bean
public EntityDictionary buildDictionary(AutowireCapableBeanFactory beanFactory, ClassScanner scanner, @Autowired(required = false) DynamicConfiguration dynamicConfig, ElideConfigProperties settings, @Qualifier("entitiesToExclude") Set<Type<?>> entitiesToExclude) {
Map<String, Class<? extends Check>> checks = new HashMap<>();
if (settings.getDynamicConfig().isConfigApiEnabled()) {
checks.put(ConfigChecks.CAN_CREATE_CONFIG, ConfigChecks.CanCreate.class);
checks.put(ConfigChecks.CAN_READ_CONFIG, ConfigChecks.CanRead.class);
checks.put(ConfigChecks.CAN_DELETE_CONFIG, ConfigChecks.CanDelete.class);
checks.put(ConfigChecks.CAN_UPDATE_CONFIG, ConfigChecks.CanNotUpdate.class);
}
EntityDictionary dictionary = new EntityDictionary(// Checks
checks, // Role Checks
new HashMap<>(), new Injector() {
@Override
public void inject(Object entity) {
beanFactory.autowireBean(entity);
}
@Override
public <T> T instantiate(Class<T> cls) {
return beanFactory.createBean(cls);
}
}, // Serde Lookup
CoerceUtil::lookup, entitiesToExclude, scanner);
return dictionary;
}
use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.
the class GraphQLEndpointTest method setupTest.
@BeforeEach
public void setupTest() throws Exception {
HashMapDataStore inMemoryStore = new HashMapDataStore(DefaultClassScanner.getInstance(), Book.class.getPackage());
Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
checkMappings.put(UserChecks.IS_USER_1, UserChecks.IsUserId.One.class);
checkMappings.put(UserChecks.IS_USER_2, UserChecks.IsUserId.Two.class);
checkMappings.put(CommitChecks.IS_NOT_USER_3, CommitChecks.IsNotUser3.class);
elide = spy(new Elide(new ElideSettingsBuilder(inMemoryStore).withEntityDictionary(EntityDictionary.builder().checks(checkMappings).build()).withAuditLogger(audit).build()));
elide.doScans();
endpoint = new GraphQLEndpoint(elide);
DataStoreTransaction tx = inMemoryStore.beginTransaction();
// Initial data
Book book1 = new Book();
Author author1 = new Author();
Author author2 = new Author();
DisallowTransfer noShare = new DisallowTransfer();
book1.setId(1L);
book1.setTitle("My first book");
book1.setAuthors(Sets.newHashSet(author1));
author1.setId(1L);
author1.setName("Ricky Carmichael");
author1.setBooks(Sets.newHashSet(book1));
author1.setBookTitlesAndAwards(Stream.of(new AbstractMap.SimpleImmutableEntry<>("Bookz", "Pulitzer Prize"), new AbstractMap.SimpleImmutableEntry<>("Lost in the Data", "PEN/Faulkner Award")).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
author2.setId(2L);
author2.setName("The Silent Author");
author2.setBookTitlesAndAwards(Stream.of(new AbstractMap.SimpleImmutableEntry<>("Working Hard or Hardly Working", "Booker Prize")).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
noShare.setId(1L);
tx.createObject(book1, null);
tx.createObject(author1, null);
tx.createObject(author2, null);
tx.createObject(noShare, null);
tx.save(book1, null);
tx.save(author1, null);
tx.save(author2, null);
tx.save(noShare, null);
tx.commit(null);
}
use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.
the class GraphQLTableExportOperationTest method setupMocks.
@BeforeEach
public void setupMocks(@TempDir Path tempDir) {
dataStore = new HashMapDataStore(DefaultClassScanner.getInstance(), new HashSet<>(Arrays.asList(TableExport.class.getPackage(), ArtifactGroup.class.getPackage())));
Map<String, Class<? extends Check>> map = new HashMap<>();
map.put(AsyncAPIInlineChecks.AsyncAPIOwner.PRINCIPAL_IS_OWNER, AsyncAPIInlineChecks.AsyncAPIOwner.class);
map.put(AsyncAPIInlineChecks.AsyncAPIAdmin.PRINCIPAL_IS_ADMIN, AsyncAPIInlineChecks.AsyncAPIAdmin.class);
map.put(AsyncAPIInlineChecks.AsyncAPIStatusValue.VALUE_IS_CANCELLED, AsyncAPIInlineChecks.AsyncAPIStatusValue.class);
map.put(AsyncAPIInlineChecks.AsyncAPIStatusQueuedValue.VALUE_IS_QUEUED, AsyncAPIInlineChecks.AsyncAPIStatusQueuedValue.class);
elide = new Elide(new ElideSettingsBuilder(dataStore).withEntityDictionary(EntityDictionary.builder().checks(map).build()).withAuditLogger(new Slf4jLogger()).withExportApiPath("/export").build());
elide.doScans();
user = mock(User.class);
requestScope = mock(RequestScope.class);
asyncExecutorService = mock(AsyncExecutorService.class);
engine = new FileResultStorageEngine(tempDir.toString(), false);
when(asyncExecutorService.getElide()).thenReturn(elide);
when(requestScope.getApiVersion()).thenReturn(NO_VERSION);
when(requestScope.getUser()).thenReturn(user);
when(requestScope.getElideSettings()).thenReturn(elide.getElideSettings());
when(requestScope.getBaseUrlEndPoint()).thenReturn("https://elide.io");
}
use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.
the class JsonAPITableExportOperationTest method setupMocks.
@BeforeEach
public void setupMocks(@TempDir Path tempDir) {
dataStore = new HashMapDataStore(DefaultClassScanner.getInstance(), new HashSet<>(Arrays.asList(TableExport.class.getPackage(), ArtifactGroup.class.getPackage())));
Map<String, Class<? extends Check>> map = new HashMap<>();
map.put(AsyncAPIInlineChecks.AsyncAPIOwner.PRINCIPAL_IS_OWNER, AsyncAPIInlineChecks.AsyncAPIOwner.class);
map.put(AsyncAPIInlineChecks.AsyncAPIAdmin.PRINCIPAL_IS_ADMIN, AsyncAPIInlineChecks.AsyncAPIAdmin.class);
map.put(AsyncAPIInlineChecks.AsyncAPIStatusValue.VALUE_IS_CANCELLED, AsyncAPIInlineChecks.AsyncAPIStatusValue.class);
map.put(AsyncAPIInlineChecks.AsyncAPIStatusQueuedValue.VALUE_IS_QUEUED, AsyncAPIInlineChecks.AsyncAPIStatusQueuedValue.class);
elide = new Elide(new ElideSettingsBuilder(dataStore).withEntityDictionary(EntityDictionary.builder().checks(map).build()).withAuditLogger(new Slf4jLogger()).withExportApiPath("/export").build());
elide.doScans();
user = mock(User.class);
requestScope = mock(RequestScope.class);
asyncExecutorService = mock(AsyncExecutorService.class);
engine = new FileResultStorageEngine(tempDir.toString(), true);
when(asyncExecutorService.getElide()).thenReturn(elide);
when(requestScope.getApiVersion()).thenReturn(NO_VERSION);
when(requestScope.getUser()).thenReturn(user);
when(requestScope.getElideSettings()).thenReturn(elide.getElideSettings());
when(requestScope.getBaseUrlEndPoint()).thenReturn("https://elide.io");
}
use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.
the class AsyncExecutorServiceTest method setupMockElide.
@BeforeAll
public void setupMockElide() {
HashMapDataStore inMemoryStore = new HashMapDataStore(DefaultClassScanner.getInstance(), AsyncQuery.class.getPackage());
Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
elide = new Elide(new ElideSettingsBuilder(inMemoryStore).withEntityDictionary(EntityDictionary.builder().checks(checkMappings).build()).build());
asyncAPIDao = mock(DefaultAsyncAPIDAO.class);
testUser = mock(User.class);
scope = mock(RequestScope.class);
resultStorageEngine = mock(FileResultStorageEngine.class);
service = new AsyncExecutorService(elide, Executors.newFixedThreadPool(5), Executors.newFixedThreadPool(5), asyncAPIDao);
}
Aggregations