use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.
the class DefaultAppBootstrapper method onApplicationEvent.
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
List<TableDescription> tables = annotationBasedTableCreator.getTables("org.sagebionetworks.bridge.dynamodb");
dynamoInitializer.init(tables);
s3Initializer.initBuckets();
RequestContext.set(new RequestContext.Builder().withCallerAppId(API_APP_ID).withCallerRoles(ImmutableSet.of(SUPERADMIN)).withCallerUserId("DefaultStudyBootstrapper").build());
// The integration bootstrap account should be ADMIN in production, and SUPERADMIN in other environments.
// It should have the Synapse user ID of the synapse.user set for the integration tests.
String adminEmail = bridgeConfig.get("admin.email");
String adminSynUserId = bridgeConfig.get("admin.synapse.user.id");
Roles adminRole = (bridgeConfig.getEnvironment() == PROD) ? ADMIN : SUPERADMIN;
boolean bootstrapUserConfigured = (adminEmail != null && adminSynUserId != null);
StudyParticipant admin = new StudyParticipant.Builder().withEmail(adminEmail).withSynapseUserId(adminSynUserId).withDataGroups(Sets.newHashSet(TEST_USER_GROUP)).withSharingScope(NO_SHARING).withRoles(Sets.newHashSet(adminRole)).build();
App app = createApp(API_APP_ID, "Test App", provided -> {
provided.setMinAgeOfConsent(18);
provided.setDataGroups(Sets.newHashSet(TEST_DATA_GROUPS));
provided.setTaskIdentifiers(Sets.newHashSet(TEST_TASK_IDENTIFIERS));
provided.setUserProfileAttributes(Sets.newHashSet("can_be_recontacted"));
});
if (bootstrapUserConfigured) {
createAccount(app, admin);
}
App app2 = createApp(API_2_APP_ID, "Test App 2", null);
if (bootstrapUserConfigured) {
createAccount(app2, admin);
}
App shared = createApp(SHARED_APP_ID, "Shared App", null);
if (bootstrapUserConfigured && bridgeConfig.getEnvironment() != Environment.PROD) {
createAccount(shared, admin);
}
}
use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.
the class BridgeUtilsTest method participantTemplateVariablesWorks.
@Test
public void participantTemplateVariablesWorks() {
StudyParticipant participant = new StudyParticipant.Builder().withFirstName("aFirstName").withLastName("aLastName").withEmail(EMAIL).withPhone(PHONE).withAttributes(ImmutableMap.of("first_prop", "A", "second prop", "B")).build();
Map<String, String> map = BridgeUtils.participantTemplateVariables(participant);
assertEquals(map.get("participantFirstName"), "aFirstName");
assertEquals(map.get("participantLastName"), "aLastName");
assertEquals(map.get("participantPhone"), "+19712486796");
assertEquals(map.get("participantPhoneRegion"), "US");
assertEquals(map.get("participant.first_prop"), "A");
assertEquals(map.get("participant.second prop"), "B");
assertEquals(map.get("participantEmail"), "email@email.com");
assertEquals(map.get("participantPhoneNationalFormat"), "(971) 248-6796");
}
use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method testSetUserSessionNullSessionToken.
@Test
public void testSetUserSessionNullSessionToken() throws Exception {
StudyParticipant participant = new StudyParticipant.Builder().withEmail("userEmail").withId(USER_ID).withHealthCode("healthCode").build();
UserSession session = new UserSession(participant);
try {
cacheProvider.setUserSession(session);
} catch (NullPointerException e) {
assertTrue(true, "NPE expected.");
} catch (Throwable e) {
fail(e.getMessage());
}
verify(transaction, never()).setex(eq(TOKEN_TO_USER_ID.toString()), anyInt(), anyString());
verify(transaction, never()).setex(eq(USER_ID_TO_SESSION.toString()), anyInt(), eq(DECRYPTED_SESSION_TOKEN));
verify(transaction, never()).exec();
}
use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method testRemoveSession.
@Test
public void testRemoveSession() {
StudyParticipant participant = new StudyParticipant.Builder().withId(USER_ID).build();
UserSession session = new UserSession(participant);
session.setSessionToken(DECRYPTED_SESSION_TOKEN);
cacheProvider.removeSession(session);
cacheProvider.getUserSession(DECRYPTED_SESSION_TOKEN);
verify(transaction).del(TOKEN_TO_USER_ID.toString());
verify(transaction).del(USER_ID_TO_SESSION.toString());
verify(transaction).exec();
}
use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method assertSession.
private void assertSession(String json) {
JedisOps jedisOps = mock(JedisOps.class);
when(jedisOps.get(TOKEN_TO_USER_ID.toString())).thenReturn(USER_ID);
when(jedisOps.get(USER_ID_TO_SESSION.toString())).thenReturn(json);
cacheProvider.setJedisOps(jedisOps);
UserSession session = cacheProvider.getUserSession(DECRYPTED_SESSION_TOKEN);
assertTrue(session.isAuthenticated());
assertEquals(session.getEnvironment(), Environment.LOCAL);
assertEquals(session.getSessionToken(), DECRYPTED_SESSION_TOKEN);
assertEquals(session.getInternalSessionToken(), "4f0937a5-6ebf-451b-84bc-fbf649b9e93c");
assertEquals(session.getId(), "6gq4jGXLmAxVbLLmVifKN4");
assertEquals(session.getAppId(), TEST_APP_ID);
StudyParticipant participant = session.getParticipant();
assertEquals(participant.getFirstName(), "Bridge");
assertEquals(participant.getLastName(), "IT");
assertEquals(participant.getEmail(), "bridgeit@sagebase.org");
assertEquals(participant.getSharingScope(), SharingScope.NO_SHARING);
assertEquals(participant.getCreatedOn(), DateTime.parse("2016-04-21T16:48:22.386Z"));
assertEquals(participant.getRoles(), Sets.newHashSet(Roles.ADMIN));
assertEquals(participant.getLanguages(), ImmutableList.of("en", "fr"));
assertEquals(participant.getExternalId(), "ABC");
assertEquals(ENCRYPTOR.decrypt(ENCRYPTED_SESSION_TOKEN), participant.getHealthCode());
SubpopulationGuid apiGuid = SubpopulationGuid.create(TEST_APP_ID);
Map<SubpopulationGuid, ConsentStatus> consentStatuses = session.getConsentStatuses();
ConsentStatus status = consentStatuses.get(apiGuid);
assertEquals(status.getName(), "Default Consent Group");
assertEquals(status.getSubpopulationGuid(), apiGuid.getGuid());
assertTrue(status.getSignedMostRecentConsent());
assertTrue(status.isRequired());
assertFalse(status.isConsented());
}
Aggregations