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