Search in sources :

Example 6 with Check

use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.

the class DefaultAsyncAPIDAOTest method setupMocks.

@BeforeEach
public void setupMocks() {
    dataStore = mock(DataStore.class);
    asyncQuery = mock(AsyncQuery.class);
    asyncQueryResult = mock(AsyncQueryResult.class);
    filter = mock(FilterExpression.class);
    tx = mock(DataStoreTransaction.class);
    Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
    EntityDictionary dictionary = EntityDictionary.builder().checks(checkMappings).build();
    dictionary.bindEntity(AsyncQuery.class);
    dictionary.bindEntity(AsyncQueryResult.class);
    ElideSettings elideSettings = new ElideSettingsBuilder(dataStore).withEntityDictionary(dictionary).withJoinFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build()).withSubqueryFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build();
    elide = new Elide(elideSettings);
    when(dataStore.beginTransaction()).thenReturn(tx);
    asyncAPIDAO = new DefaultAsyncAPIDAO(elide.getElideSettings(), dataStore);
}
Also used : HashMap(java.util.HashMap) Check(com.yahoo.elide.core.security.checks.Check) AsyncQueryResult(com.yahoo.elide.async.models.AsyncQueryResult) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) DataStore(com.yahoo.elide.core.datastore.DataStore) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) ElideSettings(com.yahoo.elide.ElideSettings) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Elide(com.yahoo.elide.Elide) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with Check

use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.

the class AsyncAPICancelRunnableTest method setupMocks.

@BeforeEach
public void setupMocks() {
    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()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build());
    asyncAPIDao = mock(DefaultAsyncAPIDAO.class);
    cancelThread = new AsyncAPICancelRunnable(7, elide, asyncAPIDao);
    transactionRegistry = elide.getTransactionRegistry();
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMap(java.util.HashMap) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) Check(com.yahoo.elide.core.security.checks.Check) Elide(com.yahoo.elide.Elide) DefaultAsyncAPIDAO(com.yahoo.elide.async.service.dao.DefaultAsyncAPIDAO) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with Check

use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.

the class AsyncAPICleanerRunnableTest method setupMocks.

@BeforeEach
public void setupMocks() {
    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()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build());
    asyncAPIDao = mock(DefaultAsyncAPIDAO.class);
    dateUtil = mock(DateUtil.class);
    cleanerThread = new AsyncAPICleanerRunnable(7, elide, 7, asyncAPIDao, dateUtil);
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMap(java.util.HashMap) DateUtil(com.yahoo.elide.async.service.DateUtil) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) Check(com.yahoo.elide.core.security.checks.Check) Elide(com.yahoo.elide.Elide) DefaultAsyncAPIDAO(com.yahoo.elide.async.service.dao.DefaultAsyncAPIDAO) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with Check

use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.

the class ElideStandaloneSettings method getEntityDictionary.

/**
 * Gets the EntityDictionary for elide.
 * @param injector Service locator for web service for dependency injection.
 * @param dynamicConfiguration optional dynamic config object.
 * @param entitiesToExclude set of Entities to exclude from binding.
 * @return EntityDictionary object initialized.
 */
default EntityDictionary getEntityDictionary(ServiceLocator injector, ClassScanner scanner, Optional<DynamicConfiguration> dynamicConfiguration, Set<Type<?>> entitiesToExclude) {
    Map<String, Class<? extends Check>> checks = new HashMap<>();
    if (getAnalyticProperties().enableDynamicModelConfigAPI()) {
        checks.put(ConfigChecks.CAN_CREATE_CONFIG, ConfigChecks.CanNotCreate.class);
        checks.put(ConfigChecks.CAN_READ_CONFIG, ConfigChecks.CanNotRead.class);
        checks.put(ConfigChecks.CAN_DELETE_CONFIG, ConfigChecks.CanNotDelete.class);
        checks.put(ConfigChecks.CAN_UPDATE_CONFIG, ConfigChecks.CanNotUpdate.class);
    }
    EntityDictionary dictionary = new EntityDictionary(// Checks
    new HashMap<>(), // Role Checks
    new HashMap<>(), new Injector() {

        @Override
        public void inject(Object entity) {
            injector.inject(entity);
        }

        @Override
        public <T> T instantiate(Class<T> cls) {
            return injector.create(cls);
        }
    }, // Serde Lookup
    CoerceUtil::lookup, entitiesToExclude, scanner);
    dynamicConfiguration.map(DynamicConfiguration::getRoles).orElseGet(Collections::emptySet).forEach(role -> dictionary.addRoleCheck(role, new Role.RoleMemberCheck(role)));
    return dictionary;
}
Also used : HashMap(java.util.HashMap) Check(com.yahoo.elide.core.security.checks.Check) CoerceUtil(com.yahoo.elide.core.utils.coerce.CoerceUtil) DynamicConfiguration(com.yahoo.elide.modelconfig.DynamicConfiguration) Injector(com.yahoo.elide.core.dictionary.Injector) ConfigChecks(com.yahoo.elide.modelconfig.store.models.ConfigChecks) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 10 with Check

use of com.yahoo.elide.core.security.checks.Check in project elide by yahoo.

the class ElideAutoConfiguration method buildDictionary.

/**
 * Creates the entity dictionary for Elide which contains static metadata about Elide models.
 * Override to load check classes or life cycle hooks.
 * @param beanFactory Injector to inject Elide models.
 * @param dynamicConfig An instance of DynamicConfiguration.
 * @param settings Elide configuration settings.
 * @param entitiesToExclude set of Entities to exclude from binding.
 * @return a newly configured EntityDictionary.
 */
@Bean
@ConditionalOnMissingBean
@Scope(SCOPE_PROTOTYPE)
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.CanNotCreate.class);
        checks.put(ConfigChecks.CAN_READ_CONFIG, ConfigChecks.CanNotRead.class);
        checks.put(ConfigChecks.CAN_DELETE_CONFIG, ConfigChecks.CanNotDelete.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);
    if (isAggregationStoreEnabled(settings) && isDynamicConfigEnabled(settings)) {
        dynamicConfig.getRoles().forEach(role -> {
            dictionary.addRoleCheck(role, new Role.RoleMemberCheck(role));
        });
    }
    return dictionary;
}
Also used : HashMap(java.util.HashMap) Check(com.yahoo.elide.core.security.checks.Check) Role(com.yahoo.elide.core.security.checks.prefab.Role) CoerceUtil(com.yahoo.elide.core.utils.coerce.CoerceUtil) Injector(com.yahoo.elide.core.dictionary.Injector) ConfigChecks(com.yahoo.elide.modelconfig.store.models.ConfigChecks) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Scope(org.springframework.context.annotation.Scope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

Check (com.yahoo.elide.core.security.checks.Check)22 HashMap (java.util.HashMap)17 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)13 BeforeEach (org.junit.jupiter.api.BeforeEach)11 Elide (com.yahoo.elide.Elide)9 RequestScope (com.yahoo.elide.core.RequestScope)8 HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)8 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)8 Role (com.yahoo.elide.core.security.checks.prefab.Role)6 FilterExpressionCheck (com.yahoo.elide.core.security.checks.FilterExpressionCheck)5 AsyncQuery (com.yahoo.elide.async.models.AsyncQuery)4 Injector (com.yahoo.elide.core.dictionary.Injector)4 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)4 User (com.yahoo.elide.core.security.User)4 UserCheck (com.yahoo.elide.core.security.checks.UserCheck)4 Type (com.yahoo.elide.core.type.Type)4 DefaultAsyncAPIDAO (com.yahoo.elide.async.service.dao.DefaultAsyncAPIDAO)3 FileResultStorageEngine (com.yahoo.elide.async.service.storageengine.FileResultStorageEngine)3 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)3 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)3