Search in sources :

Example 1 with IdentifierHolder

use of org.sagebionetworks.bridge.models.accounts.IdentifierHolder 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 2 with IdentifierHolder

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

the class AuthenticationServiceTest method signIn_oldExternalIdsFormatForExistingAccountReturnsQuietly.

@Test
public void signIn_oldExternalIdsFormatForExistingAccountReturnsQuietly() {
    StudyParticipant participant = new StudyParticipant.Builder().withExternalId(EXTERNAL_ID).build();
    AccountId accountId = AccountId.forExternalId(TEST_APP_ID, EXTERNAL_ID);
    when(accountService.getAccount(accountId)).thenReturn(Optional.of(account));
    IdentifierHolder retValue = service.signUp(app, participant);
    assertEquals(retValue.getIdentifier(), TEST_USER_ID);
    verify(accountService).getAccount(accountId);
    verify(studyService, never()).getStudyIds(TEST_APP_ID);
    verify(participantService, never()).createParticipant(app, participant, true);
}
Also used : IdentifierHolder(org.sagebionetworks.bridge.models.accounts.IdentifierHolder) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Example 3 with IdentifierHolder

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

the class AppServiceTest method createSynapseProjectTeamAccessTeamIdExists.

@Test(expectedExceptions = EntityAlreadyExistsException.class, expectedExceptionsMessageRegExp = "App already has a team ID.")
public void createSynapseProjectTeamAccessTeamIdExists() throws SynapseException {
    // mock
    App app = getTestApp();
    app.setSynapseProjectId(null);
    app.setExternalIdRequiredOnSignup(false);
    app.setPasswordPolicy(PasswordPolicy.DEFAULT_PASSWORD_POLICY);
    StudyParticipant mockUser1 = new StudyParticipant.Builder().withSynapseUserId(TEST_USER_SYNAPSE_ID).withEmail(TEST_USER_EMAIL).withRoles(ImmutableSet.of(Roles.RESEARCHER, Roles.DEVELOPER)).build();
    when(mockParticipantService.createParticipant(any(), any(), anyBoolean())).thenReturn(new IdentifierHolder("userId"));
    AppAndUsers mockAppAndUsers = new AppAndUsers(TEST_ADMIN_IDS, app, ImmutableList.of(mockUser1));
    // execute
    service.createAppAndUsers(mockAppAndUsers);
}
Also used : DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) App(org.sagebionetworks.bridge.models.apps.App) IdentifierHolder(org.sagebionetworks.bridge.models.accounts.IdentifierHolder) AppAndUsers(org.sagebionetworks.bridge.models.apps.AppAndUsers) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Example 4 with IdentifierHolder

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

the class AuthenticationService method signUp.

public IdentifierHolder signUp(App app, StudyParticipant participant) {
    checkNotNull(app);
    checkNotNull(participant);
    // field (not the externalIds map).
    if (participant.getExternalId() != null && participant.getExternalIds().isEmpty()) {
        // For apps that create accounts prior to calling sign up from the app (which happens), check and if
        // the account with this external ID already exists, return quietly.
        AccountId accountId = AccountId.forExternalId(app.getIdentifier(), participant.getExternalId());
        Account account = accountService.getAccount(accountId).orElse(null);
        if (account != null) {
            return new IdentifierHolder(account.getId());
        }
        // Or, they are probably calling signup with an external ID and a password, but no study. Try to
        // guess a reasonable default. If we can't the participant is returned as is and will fail
        // to be created by ParticipantService.
        participant = findDefaultStudyForExternalId(app, participant);
    }
    try {
        // can be assigned to this user.
        return participantService.createParticipant(app, participant, true);
    } catch (EntityAlreadyExistsException e) {
        AccountId accountId = null;
        // throw a different exception EAEE that we must catch and address here.
        if ("ExternalIdentifier".equals(e.getEntityClass())) {
            String identifier = (String) e.getEntityKeys().get("identifier");
            accountId = AccountId.forExternalId(app.getIdentifier(), identifier);
            LOG.info("Sign up attempt using assigned external ID '" + identifier + "'");
        } else if ("Account".equals(e.getEntityClass())) {
            String userId = (String) e.getEntityKeys().get("userId");
            accountId = AccountId.forId(app.getIdentifier(), userId);
            LOG.info("Sign up attempt using credential that exists in account '" + userId + "'");
        } else {
            LOG.error("Sign up attempt threw unanticipated EntityAlreadyExistsException: " + e.getMessage());
            return null;
        }
        // Suppress this and send an email to notify the user that the account already exists. From
        // this call, we simply return a 200 the same as any other sign up. Otherwise the response
        // reveals that the credential has been taken.
        accountWorkflowService.notifyAccountExists(app, accountId);
        return null;
    }
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) IdentifierHolder(org.sagebionetworks.bridge.models.accounts.IdentifierHolder) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) EntityAlreadyExistsException(org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException)

Example 5 with IdentifierHolder

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

the class AppService method createAppAndUsers.

public App createAppAndUsers(AppAndUsers appAndUsers) throws SynapseException {
    checkNotNull(appAndUsers);
    // Validate AppAndUsers
    Validate.entityThrowingException(appAndUsersValidator, appAndUsers);
    // Create app
    App app = createApp(appAndUsers.getApp());
    // Create users and send password reset email
    for (StudyParticipant user : appAndUsers.getUsers()) {
        IdentifierHolder identifierHolder = participantService.createParticipant(app, user, false);
        // send resetting password email as well
        participantService.requestResetPassword(app, identifierHolder.getIdentifier());
    }
    // Add admins and users to the Synapse project and access teams. All IDs have been validated.
    List<String> synapseUserIds = appAndUsers.getUsers().stream().map(StudyParticipant::getSynapseUserId).collect(toList());
    createSynapseProjectTeam(appAndUsers.getAdminIds(), synapseUserIds, app);
    return app;
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) IdentifierHolder(org.sagebionetworks.bridge.models.accounts.IdentifierHolder) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant)

Aggregations

IdentifierHolder (org.sagebionetworks.bridge.models.accounts.IdentifierHolder)17 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)14 Test (org.testng.annotations.Test)10 App (org.sagebionetworks.bridge.models.apps.App)5 AppAndUsers (org.sagebionetworks.bridge.models.apps.AppAndUsers)4 RequestContext (org.sagebionetworks.bridge.RequestContext)3 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)3 Account (org.sagebionetworks.bridge.models.accounts.Account)3 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)3 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)2 Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)2 EntityView (org.sagebionetworks.repo.model.table.EntityView)2 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 BridgeServiceException (org.sagebionetworks.bridge.exceptions.BridgeServiceException)1 ConsentRequiredException (org.sagebionetworks.bridge.exceptions.ConsentRequiredException)1 EntityAlreadyExistsException (org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException)1 CriteriaContext (org.sagebionetworks.bridge.models.CriteriaContext)1 ConsentStatus (org.sagebionetworks.bridge.models.accounts.ConsentStatus)1