Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bearer tokens #137

Merged
merged 2 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Response buildAccessRequest(
@PathParam("dataset-id") String datasetId) throws WdkModelException, ConflictException, DataValidationException {
LOG.info("Handling an access request for user id " + userId + " and dataset id " + datasetId + "...");

if (userId != this.getSessionUser().getUserId() || this.getSessionUser().isGuest()) {
if (userId != this.getRequestingUser().getUserId() || this.getRequestingUser().isGuest()) {
return Response.status(Status.UNAUTHORIZED).build();
}

Expand Down Expand Up @@ -102,7 +102,7 @@ public DatasetAccessRequestAttributes retrieveDatasetRecordInstance(String datas
RecordClass datasetRecordClass = getRecordClassOrNotFound(DATASET_RECORD_CLASS);

List<RecordInstance> records = RecordClass.getRecordInstances(
getSessionUser(),
getRequestingUser(),
createPrimaryKeyValue(datasetRecordClass, datasetId)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public static SubmissionResult submitAccessRequest(AccessRequestParams params, W
// In one transaction...
// (1) insert a DB record for the new request and
// (2) email the request to the appropriate parties
String acctDbLink = wdkModel.getModelConfig().getAppDB().getAcctDbLink();
try (
Connection conn = wdkModel.getAccountDb().getDataSource().getConnection();
Connection conn = wdkModel.getAppDb().getDataSource().getConnection();
) {
conn.setAutoCommit(false);
String sql = insertRequestPreparedStatementBody();
String sql = insertRequestPreparedStatementBody(acctDbLink);

try (
PreparedStatement ps = insertRequestPreparedStatement(conn, sql, params);
Expand Down Expand Up @@ -65,9 +66,9 @@ public static SubmissionResult submitAccessRequest(AccessRequestParams params, W
return requestInitiated || params.inTestMode() ? SubmissionResult.SUCCESSFUL : SubmissionResult.ALREADY_REQUESTED;
}

private static String insertRequestPreparedStatementBody() {
private static String insertRequestPreparedStatementBody(String acctDbLink) {
return "INSERT INTO\n"
+ " studyaccess.end_users (\n"
+ " studyaccess.end_users" + acctDbLink + " (\n"
+ " user_id\n"
+ " , dataset_presenter_id\n"
+ " , purpose\n"
Expand All @@ -88,14 +89,14 @@ private static String insertRequestPreparedStatementBody() {
+ ", ? -- prior_auth\n"
+ ", (\n"
+ " SELECT restriction_level_id\n"
+ " FROM studyaccess.restriction_level"
+ " FROM studyaccess.restriction_level" + acctDbLink
+ " WHERE name = ?"
+ " ) -- restriction_level\n"
+ ", ? -- approval_status\n"
+ "FROM dual\n"
+ "WHERE NOT EXISTS (\n"
+ " SELECT user_id, dataset_presenter_id\n"
+ " FROM studyaccess.end_users\n"
+ " FROM studyaccess.end_users" + acctDbLink + "\n"
+ " WHERE user_id = ?\n"
+ " AND dataset_presenter_id = ?\n"
+ ")";
Expand Down