Search in sources :

Example 1 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class PaginationImplTest method testClassLevelOverride.

@Test
public void testClassLevelOverride() {
    @Paginate(maxLimit = 100000, defaultLimit = 10)
    class PaginationOverrideTest {
    }
    MultivaluedMap<String, String> queryParams = new MultivaluedStringMap();
    PaginationImpl pageData = PaginationImpl.parseQueryParams(ClassType.of(PaginationOverrideTest.class), queryParams, new ElideSettingsBuilder(null).withEntityDictionary(EntityDictionary.builder().build()).withDefaultPageSize(1).withDefaultMaxPageSize(1).build());
    assertEquals(0, pageData.getOffset());
    assertEquals(10, pageData.getLimit());
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) MultivaluedStringMap(org.glassfish.jersey.internal.util.collection.MultivaluedStringMap) Paginate(com.yahoo.elide.annotation.Paginate) Test(org.junit.jupiter.api.Test)

Example 2 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class AggregationStorePermissionExecutorTest method setup.

@BeforeAll
public void setup() {
    Map<String, Class<? extends Check>> checks = new HashMap<>();
    checks.put("user all", Role.ALL.class);
    checks.put("user none", Role.NONE.class);
    checks.put("filter check", FilterCheck.class);
    dictionary = TestDictionary.getTestDictionary(checks);
    elideSettings = new ElideSettingsBuilder(null).withEntityDictionary(dictionary).build();
}
Also used : Role(com.yahoo.elide.core.security.checks.prefab.Role) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMap(java.util.HashMap) FilterExpressionCheck(com.yahoo.elide.core.security.checks.FilterExpressionCheck) Check(com.yahoo.elide.core.security.checks.Check) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class ElideCustomSerdeRegistrationTest method testRegisterCustomSerde.

@Test
public void testRegisterCustomSerde() {
    // Create a fake Elide.  Don't actually bind any entities.
    HashMapDataStore wrapped = new HashMapDataStore(DefaultClassScanner.getInstance(), String.class.getPackage());
    InMemoryDataStore store = new InMemoryDataStore(wrapped);
    ElideSettings elideSettings = new ElideSettingsBuilder(store).withEntityDictionary(EntityDictionary.builder().build()).build();
    Elide elide = new Elide(elideSettings);
    elide.doScans();
    assertNotNull(CoerceUtil.lookup(Dummy.class));
    assertNotNull(CoerceUtil.lookup(DummyTwo.class));
    assertNotNull(CoerceUtil.lookup(DummyThree.class));
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) ElideSettings(com.yahoo.elide.ElideSettings) Elide(com.yahoo.elide.Elide) InMemoryDataStore(com.yahoo.elide.core.datastore.inmemory.InMemoryDataStore) Test(org.junit.jupiter.api.Test)

Example 4 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class PermissionExpressionBuilderTest method setupEntityDictionary.

@BeforeEach
public void setupEntityDictionary() {
    Map<String, Class<? extends Check>> checks = new HashMap<>();
    checks.put("user has all access", Role.ALL.class);
    checks.put("user has no access", Role.NONE.class);
    dictionary = TestDictionary.getTestDictionary(checks);
    ExpressionResultCache cache = new ExpressionResultCache();
    builder = new PermissionExpressionBuilder(cache, dictionary);
    elideSettings = new ElideSettingsBuilder(null).withEntityDictionary(dictionary).build();
}
Also used : Role(com.yahoo.elide.core.security.checks.prefab.Role) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMap(java.util.HashMap) Check(com.yahoo.elide.core.security.checks.Check) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class TableExportIT method tableExportModelAdminReadPermissions.

/**
 * Tests Read Permissions on TableExport Model for Admin Role.
 * @throws IOException IOException
 */
@Test
public void tableExportModelAdminReadPermissions() throws IOException {
    ElideResponse response = null;
    String id = "edc4a871-dff2-4054-804e-d80075c08959";
    String query = "test-query";
    com.yahoo.elide.async.models.TableExport queryObj = new com.yahoo.elide.async.models.TableExport();
    queryObj.setId(id);
    queryObj.setQuery(query);
    queryObj.setResultType(ResultType.CSV);
    queryObj.setQueryType(QueryType.JSONAPI_V1_0);
    queryObj.setPrincipalName("owner-user");
    EntityDictionary dictionary = EntityDictionary.builder().checks(AsyncIntegrationTestApplicationResourceConfig.MAPPINGS).build();
    dataStore.populateEntityDictionary(dictionary);
    DataStoreTransaction tx = dataStore.beginTransaction();
    tx.createObject(queryObj, null);
    tx.commit(null);
    tx.close();
    Elide elide = new Elide(new ElideSettingsBuilder(dataStore).withEntityDictionary(dictionary).withAuditLogger(new TestAuditLogger()).build());
    User ownerUser = new User(() -> "owner-user");
    SecurityContextUser securityContextAdminUser = new SecurityContextUser(new SecurityContext() {

        @Override
        public Principal getUserPrincipal() {
            return () -> "1";
        }

        @Override
        public boolean isUserInRole(String s) {
            return true;
        }

        @Override
        public boolean isSecure() {
            return false;
        }

        @Override
        public String getAuthenticationScheme() {
            return null;
        }
    });
    SecurityContextUser securityContextNonAdminUser = new SecurityContextUser(new SecurityContext() {

        @Override
        public Principal getUserPrincipal() {
            return () -> "2";
        }

        @Override
        public boolean isUserInRole(String s) {
            return false;
        }

        @Override
        public boolean isSecure() {
            return false;
        }

        @Override
        public String getAuthenticationScheme() {
            return null;
        }
    });
    String baseUrl = "/";
    // Principal is Owner
    response = elide.get(baseUrl, "/tableExport/" + id, new MultivaluedHashMap<>(), ownerUser, NO_VERSION);
    assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    // Principal has Admin Role
    response = elide.get(baseUrl, "/tableExport/" + id, new MultivaluedHashMap<>(), securityContextAdminUser, NO_VERSION);
    assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    // Principal without Admin Role
    response = elide.get(baseUrl, "/tableExport/" + id, new MultivaluedHashMap<>(), securityContextNonAdminUser, NO_VERSION);
    assertEquals(HttpStatus.SC_NOT_FOUND, response.getResponseCode());
}
Also used : User(com.yahoo.elide.core.security.User) SecurityContextUser(com.yahoo.elide.jsonapi.resources.SecurityContextUser) SecurityContextUser(com.yahoo.elide.jsonapi.resources.SecurityContextUser) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) ElideResponse(com.yahoo.elide.ElideResponse) SecurityContext(javax.ws.rs.core.SecurityContext) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) TestAuditLogger(com.yahoo.elide.core.audit.TestAuditLogger) Elide(com.yahoo.elide.Elide) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Principal(java.security.Principal) Test(org.junit.jupiter.api.Test)

Aggregations

ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)30 Elide (com.yahoo.elide.Elide)20 Check (com.yahoo.elide.core.security.checks.Check)12 HashMap (java.util.HashMap)12 HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10 RequestScope (com.yahoo.elide.core.RequestScope)9 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)7 Test (org.junit.jupiter.api.Test)7 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)5 RSQLFilterDialect (com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)5 User (com.yahoo.elide.core.security.User)5 BeforeAll (org.junit.jupiter.api.BeforeAll)5 ElideSettings (com.yahoo.elide.ElideSettings)4 AsyncQuery (com.yahoo.elide.async.models.AsyncQuery)4 Slf4jLogger (com.yahoo.elide.core.audit.Slf4jLogger)4 TestAuditLogger (com.yahoo.elide.core.audit.TestAuditLogger)4 ElideResponse (com.yahoo.elide.ElideResponse)3 DefaultAsyncAPIDAO (com.yahoo.elide.async.service.dao.DefaultAsyncAPIDAO)3 FileResultStorageEngine (com.yahoo.elide.async.service.storageengine.FileResultStorageEngine)3