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);
}
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();
}
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);
}
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);
}
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());
}
Aggregations