use of org.sagebionetworks.bridge.exceptions.UnauthorizedException in project BridgeServer2 by Sage-Bionetworks.
the class DynamoAppDao method deactivateApp.
@Override
public void deactivateApp(String appId) {
checkNotNull(appId);
if (appWhitelist.contains(appId)) {
throw new UnauthorizedException(appId + " is protected by whitelist.");
}
App app = getApp(appId);
app.setActive(false);
updateApp(app);
}
use of org.sagebionetworks.bridge.exceptions.UnauthorizedException in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method unenroll_notAuthorizedAsAdmin.
@Test(expectedExceptions = UnauthorizedException.class)
public void unenroll_notAuthorizedAsAdmin() {
RequestContext.set(new RequestContext.Builder().withCallerUserId("adminUser").withCallerRoles(ImmutableSet.of(DEVELOPER)).build());
Account account = Account.create();
account.setId(TEST_USER_ID);
doThrow(new UnauthorizedException()).when(mockAccountService).editAccount(any(), any());
Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
service.unenroll(enrollment);
}
use of org.sagebionetworks.bridge.exceptions.UnauthorizedException in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method enroll_notAuthorizedAsAdmin.
@Test(expectedExceptions = UnauthorizedException.class)
public void enroll_notAuthorizedAsAdmin() {
RequestContext.set(new RequestContext.Builder().withCallerUserId("adminUser").withCallerRoles(ImmutableSet.of(DEVELOPER)).build());
Account account = Account.create();
account.setId(TEST_USER_ID);
doThrow(new UnauthorizedException()).when(mockAccountService).editAccount(any(), any());
Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
service.enroll(enrollment);
}
use of org.sagebionetworks.bridge.exceptions.UnauthorizedException in project BridgeServer2 by Sage-Bionetworks.
the class StudyValidatorTest method scheduleGuidScheduleUnauthorized.
@Test
public void scheduleGuidScheduleUnauthorized() {
study = createStudy();
study.setScheduleGuid(SCHEDULE_GUID);
when(mockScheduleService.getScheduleForStudy(TEST_APP_ID, study)).thenThrow(new UnauthorizedException());
assertValidatorMessage(validator, study, SCHEDULE_GUID_FIELD, SCHEDULE_GUID_OWNER_ERROR_MSG);
}
use of org.sagebionetworks.bridge.exceptions.UnauthorizedException in project BridgeServer2 by Sage-Bionetworks.
the class AppController method getAppMemberships.
@GetMapping(path = { "/v1/apps/memberships", "/v3/studies/memberships" }, produces = { APPLICATION_JSON_UTF8_VALUE })
public String getAppMemberships() throws Exception {
UserSession session = getAuthenticatedSession();
if (session.getParticipant().getRoles().isEmpty()) {
throw new UnauthorizedException(APP_ACCESS_EXCEPTION_MSG);
}
Stream<App> stream = null;
if (!session.isSynapseAuthenticated()) {
// If they have not signed in via Synapse, they cannot switch apps, so don't return any
stream = ImmutableList.<App>of().stream();
} else if (session.isInRole(SUPERADMIN)) {
// Superadmins can see all apps and can switch between all apps.
stream = appService.getApps().stream().filter(s -> s.isActive());
} else {
// Otherwise, apps are linked by Synapse user ID.
List<String> appIds = accountService.getAppIdsForUser(session.getParticipant().getSynapseUserId());
stream = appIds.stream().map(id -> appService.getApp(id)).filter(s -> s.isActive() && appIds.contains(s.getIdentifier()));
}
List<App> apps = stream.sorted(APP_COMPARATOR).collect(toList());
return APP_LIST_WRITER.writeValueAsString(new ResourceList<App>(apps, true));
}
Aggregations