Search in sources :

Example 26 with StudyParticipant

use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.

the class AuthenticationController method signUp.

@PostMapping({ "/v3/auth/signUp", "/api/v1/auth/signUp" })
@ResponseStatus(HttpStatus.CREATED)
public StatusMessage signUp() {
    JsonNode node = parseJson(JsonNode.class);
    StudyParticipant participant = parseJson(node, StudyParticipant.class);
    String appId = JsonUtils.asText(node, APP_ID_PROPERTY, STUDY_PROPERTY);
    getMetrics().setAppId(appId);
    App app = getAppOrThrowException(appId);
    authenticationService.signUp(app, participant);
    return new StatusMessage("Signed up.");
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) JsonNode(com.fasterxml.jackson.databind.JsonNode) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 27 with StudyParticipant

use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.

the class BaseController method getLanguages.

/**
 * Once we acquire a language for a user, we save it and use that language going forward. Changing their
 * language in the host operating system will not change the language they are using (since changing the
 * language might change their consent state). If they change their language by updating their UserProfile,
 * then they may have to reconsent in the new language they are using for the app. Any warnings to
 * that effect will need to be included in the application.
 */
List<String> getLanguages(UserSession session) {
    StudyParticipant participant = session.getParticipant();
    if (!participant.getLanguages().isEmpty()) {
        return participant.getLanguages();
    }
    RequestContext reqContext = RequestContext.get();
    List<String> languages = reqContext.getCallerLanguages();
    if (!languages.isEmpty()) {
        AccountId accountId = AccountId.forHealthCode(session.getAppId(), session.getHealthCode());
        accountService.editAccount(accountId, account -> account.setLanguages(languages));
        CriteriaContext newContext = new CriteriaContext.Builder().withLanguages(languages).withClientInfo(reqContext.getCallerClientInfo()).withHealthCode(session.getHealthCode()).withUserId(session.getId()).withUserDataGroups(session.getParticipant().getDataGroups()).withUserStudyIds(session.getParticipant().getStudyIds()).withAppId(session.getAppId()).build();
        sessionUpdateService.updateLanguage(session, newContext);
    }
    return languages;
}
Also used : AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) RequestContext(org.sagebionetworks.bridge.RequestContext) CriteriaContext(org.sagebionetworks.bridge.models.CriteriaContext)

Example 28 with StudyParticipant

use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.

the class AuthenticationServiceTest method getSessionFromAccount.

// Most of the other behaviors are tested in other methods. This test specifically tests the session created has
// the correct attributes.
@Test
public void getSessionFromAccount() {
    // Create inputs.
    App app = App.create();
    app.setIdentifier(TEST_APP_ID);
    app.setReauthenticationEnabled(true);
    setIpAddress(IP_ADDRESS);
    CriteriaContext context = new CriteriaContext.Builder().withAppId(TEST_APP_ID).build();
    Account account = Account.create();
    account.setId(TEST_USER_ID);
    StudyParticipant participant = new StudyParticipant.Builder().copyOf(PARTICIPANT).withOrgMembership(TEST_ORG_ID).build();
    // Mock pre-reqs.
    when(participantService.getParticipant(any(), any(Account.class), anyBoolean())).thenReturn(participant);
    when(config.getEnvironment()).thenReturn(Environment.LOCAL);
    when(consentService.getConsentStatuses(any(), any())).thenReturn(CONSENTED_STATUS_MAP);
    when(service.generateReauthToken()).thenReturn(REAUTH_TOKEN);
    when(sponsorService.getSponsoredStudyIds(TEST_APP_ID, TEST_ORG_ID)).thenReturn(USER_STUDY_IDS);
    // Execute and validate.
    UserSession session = service.getSessionFromAccount(app, context, account);
    assertSame(session.getParticipant(), participant);
    assertNotNull(session.getSessionToken());
    assertNotNull(session.getInternalSessionToken());
    assertTrue(session.isAuthenticated());
    assertEquals(session.getEnvironment(), Environment.LOCAL);
    assertEquals(session.getIpAddress(), IP_ADDRESS);
    assertEquals(session.getAppId(), TEST_APP_ID);
    assertEquals(session.getReauthToken(), REAUTH_TOKEN);
    assertEquals(session.getConsentStatuses(), CONSENTED_STATUS_MAP);
    verify(accountSecretDao).createSecret(AccountSecretType.REAUTH, TEST_USER_ID, REAUTH_TOKEN);
    RequestContext retValue = RequestContext.updateFromSession(session, sponsorService);
    assertEquals(retValue.getCallerAppId(), TEST_APP_ID);
    assertEquals(retValue.getOrgSponsoredStudies(), USER_STUDY_IDS);
    assertEquals(retValue.getCallerUserId(), TEST_USER_ID);
    assertEquals(retValue.getCallerOrgMembership(), TEST_ORG_ID);
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) Account(org.sagebionetworks.bridge.models.accounts.Account) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) RequestContext(org.sagebionetworks.bridge.RequestContext) CriteriaContext(org.sagebionetworks.bridge.models.CriteriaContext) Test(org.testng.annotations.Test)

Example 29 with StudyParticipant

use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.

the class AppServiceTest method createAppAndUsersDefaultsPasswordPolicy.

@Test
public void createAppAndUsersDefaultsPasswordPolicy() throws SynapseException {
    app.setPasswordPolicy(null);
    app.setExternalIdRequiredOnSignup(false);
    app.setSynapseDataAccessTeamId(null);
    app.setSynapseProjectId(null);
    List<StudyParticipant> participants = ImmutableList.of(new StudyParticipant.Builder().withEmail(TEST_USER_EMAIL).withSynapseUserId(TEST_USER_SYNAPSE_ID).withRoles(ImmutableSet.of(DEVELOPER)).build());
    IdentifierHolder holder = new IdentifierHolder("user-id");
    when(mockParticipantService.createParticipant(any(), any(), anyBoolean())).thenReturn(holder);
    AccessControlList acl = new AccessControlList();
    acl.setResourceAccess(new HashSet<>());
    when(mockSynapseClient.createTeam(any())).thenReturn(team);
    when(mockSynapseClient.createEntity(any())).thenReturn(project);
    when(mockSynapseClient.getACL(any())).thenReturn(acl);
    EntityView view = new EntityView();
    view.setScopeIds(new ArrayList<>());
    when(mockSynapseClient.getEntity(SYNAPSE_TRACKING_VIEW_ID, EntityView.class)).thenReturn(view);
    AppAndUsers mockAppAndUsers = new AppAndUsers(ImmutableList.of("12345678"), app, participants);
    service.createAppAndUsers(mockAppAndUsers);
    verify(mockAppDao).createApp(appCaptor.capture());
    assertNotNull(appCaptor.getValue().getPasswordPolicy());
}
Also used : AccessControlList(org.sagebionetworks.repo.model.AccessControlList) IdentifierHolder(org.sagebionetworks.bridge.models.accounts.IdentifierHolder) EntityView(org.sagebionetworks.repo.model.table.EntityView) AppAndUsers(org.sagebionetworks.bridge.models.apps.AppAndUsers) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Example 30 with StudyParticipant

use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.

the class AppServiceTest method createAppAndUsersWithEmptyUser.

@Test(expectedExceptions = InvalidEntityException.class, expectedExceptionsMessageRegExp = ".*users are required.*")
public void createAppAndUsersWithEmptyUser() throws SynapseException {
    // mock
    App app = getTestApp();
    app.setSynapseProjectId(null);
    app.setSynapseDataAccessTeamId(null);
    List<StudyParticipant> mockUsers = new ArrayList<>();
    AppAndUsers mockAppAndUsers = new AppAndUsers(TEST_ADMIN_IDS, app, mockUsers);
    // execute
    service.createAppAndUsers(mockAppAndUsers);
}
Also used : DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) App(org.sagebionetworks.bridge.models.apps.App) AppAndUsers(org.sagebionetworks.bridge.models.apps.AppAndUsers) ArrayList(java.util.ArrayList) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Aggregations

StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)307 Test (org.testng.annotations.Test)246 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)58 App (org.sagebionetworks.bridge.models.apps.App)54 RequestContext (org.sagebionetworks.bridge.RequestContext)43 JsonNode (com.fasterxml.jackson.databind.JsonNode)26 CriteriaContext (org.sagebionetworks.bridge.models.CriteriaContext)25 Account (org.sagebionetworks.bridge.models.accounts.Account)22 AppAndUsers (org.sagebionetworks.bridge.models.apps.AppAndUsers)19 PostMapping (org.springframework.web.bind.annotation.PostMapping)17 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)16 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)14 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)14 IdentifierHolder (org.sagebionetworks.bridge.models.accounts.IdentifierHolder)13 SubpopulationGuid (org.sagebionetworks.bridge.models.subpopulations.SubpopulationGuid)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 ConsentStatus (org.sagebionetworks.bridge.models.accounts.ConsentStatus)9 Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)9 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)8 DateTime (org.joda.time.DateTime)7