Search in sources :

Example 21 with ElideSettingsBuilder

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

the class PermissionAnnotationTest method setup.

@BeforeAll
public static void setup() {
    dictionary.bindEntity(FunWithPermissions.class);
    FunWithPermissions fun = new FunWithPermissions();
    fun.setId(1);
    AuditLogger testLogger = new TestAuditLogger();
    ElideSettings elideSettings = new ElideSettingsBuilder(null).withDefaultPageSize(10).withDefaultMaxPageSize(10).withAuditLogger(testLogger).withEntityDictionary(dictionary).build();
    RequestScope goodScope = new RequestScope(null, null, NO_VERSION, null, null, GOOD_USER, null, null, UUID.randomUUID(), elideSettings);
    funRecord = new PersistentResource<>(fun, goodScope.getUUIDFor(fun), goodScope);
    RequestScope badScope = new RequestScope(null, null, NO_VERSION, null, null, BAD_USER, null, null, UUID.randomUUID(), elideSettings);
    badRecord = new PersistentResource<>(fun, badScope.getUUIDFor(fun), badScope);
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) AuditLogger(com.yahoo.elide.core.audit.AuditLogger) TestAuditLogger(com.yahoo.elide.core.audit.TestAuditLogger) ElideSettings(com.yahoo.elide.ElideSettings) TestAuditLogger(com.yahoo.elide.core.audit.TestAuditLogger) FunWithPermissions(example.FunWithPermissions) RequestScope(com.yahoo.elide.core.RequestScope) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 22 with ElideSettingsBuilder

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

the class PermissionExpressionNormalizationVisitorTest method setUp.

@BeforeAll
public void setUp() {
    EntityDictionary dictionary = TestDictionary.getTestDictionary();
    ElideSettings elideSettings = new ElideSettingsBuilder(null).withEntityDictionary(dictionary).build();
    RequestScope requestScope = new RequestScope(null, null, NO_VERSION, null, null, null, null, null, UUID.randomUUID(), elideSettings);
    permissionExpressionVisitor = new PermissionExpressionVisitor(dictionary, (check -> new CheckExpression(check, null, requestScope, null, null)));
    normalizationVisitor = new PermissionExpressionNormalizationVisitor();
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) PermissionExpressionVisitor(com.yahoo.elide.core.security.visitors.PermissionExpressionVisitor) ElideSettings(com.yahoo.elide.ElideSettings) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RequestScope(com.yahoo.elide.core.RequestScope) PermissionExpressionNormalizationVisitor(com.yahoo.elide.core.security.visitors.PermissionExpressionNormalizationVisitor) CheckExpression(com.yahoo.elide.core.security.permissions.expressions.CheckExpression) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 23 with ElideSettingsBuilder

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

the class PersistentResourceFetcherTest method initializeQueryRunner.

@BeforeAll
public void initializeQueryRunner() {
    RSQLFilterDialect filterDialect = RSQLFilterDialect.builder().dictionary(dictionary).build();
    hashMapDataStore = new HashMapDataStore(DefaultClassScanner.getInstance(), Author.class.getPackage());
    settings = new ElideSettingsBuilder(hashMapDataStore).withEntityDictionary(dictionary).withJoinFilterDialect(filterDialect).withSubqueryFilterDialect(filterDialect).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build();
    settings.getSerdes().forEach(CoerceUtil::register);
    initializeMocks();
    Elide elide = new Elide(settings);
    elide.doScans();
    runner = new QueryRunner(elide, NO_VERSION);
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) CoerceUtil(com.yahoo.elide.core.utils.coerce.CoerceUtil) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) Elide(com.yahoo.elide.Elide) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 24 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder 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);
}
Also used : HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Check(com.yahoo.elide.core.security.checks.Check) DisallowTransfer(graphqlEndpointTestModels.DisallowTransfer) AbstractMap(java.util.AbstractMap) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Book(graphqlEndpointTestModels.Book) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Author(graphqlEndpointTestModels.Author) Elide(com.yahoo.elide.Elide) CommitChecks(graphqlEndpointTestModels.security.CommitChecks) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 25 with ElideSettingsBuilder

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

the class AsyncIT method asyncQueryModelAdminReadPermissions.

/**
 * Tests Read Permissions on AsyncQuery Model for Admin Role.
 * @throws IOException IOException
 */
@Test
public void asyncQueryModelAdminReadPermissions() throws IOException {
    ElideResponse response = null;
    String id = "edc4a871-dff2-4054-804e-d80075c08959";
    String query = "test-query";
    com.yahoo.elide.async.models.AsyncQuery queryObj = new com.yahoo.elide.async.models.AsyncQuery();
    queryObj.setId(id);
    queryObj.setQuery(query);
    queryObj.setQueryType(QueryType.JSONAPI_V1_0);
    queryObj.setPrincipalName("owner-user");
    dataStore.populateEntityDictionary(EntityDictionary.builder().checks(AsyncIntegrationTestApplicationResourceConfig.MAPPINGS).build());
    DataStoreTransaction tx = dataStore.beginTransaction();
    tx.createObject(queryObj, null);
    tx.commit(null);
    tx.close();
    Elide elide = new Elide(new ElideSettingsBuilder(dataStore).withEntityDictionary(EntityDictionary.builder().checks(AsyncIntegrationTestApplicationResourceConfig.MAPPINGS).build()).withAuditLogger(new TestAuditLogger()).build());
    elide.doScans();
    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, "/asyncQuery/" + id, new MultivaluedHashMap<>(), ownerUser, NO_VERSION);
    assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    // Principal has Admin Role
    response = elide.get(baseUrl, "/asyncQuery/" + id, new MultivaluedHashMap<>(), securityContextAdminUser, NO_VERSION);
    assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    // Principal without Admin Role
    response = elide.get(baseUrl, "/asyncQuery/" + 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) 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