-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #252 from tenbergen/251
Code lint & custom exception class
- Loading branch information
Showing
8 changed files
with
152 additions
and
173 deletions.
There are no files selected for viewing
96 changes: 47 additions & 49 deletions
96
...nd/peer-review-teams-microservice/src/main/java/edu/oswego/cs/database/TeamInterface.java
Large diffs are not rendered by default.
Oops, something went wrong.
16 changes: 8 additions & 8 deletions
16
...er-review-teams-microservice/src/main/java/edu/oswego/cs/services/IdentifyingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
package edu.oswego.cs.services; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.SecurityContext; | ||
|
||
import com.mongodb.client.MongoCollection; | ||
import com.mongodb.client.model.Filters; | ||
|
||
import edu.oswego.cs.util.CPRException; | ||
import org.bson.Document; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.SecurityContext; | ||
|
||
public class IdentifyingService { | ||
public void identifyingStudentService(SecurityContext securityContext, String studentID) { | ||
if (!securityContext.isUserInRole("professor")) { | ||
String userID = securityContext.getUserPrincipal().getName().split("@")[0]; | ||
if (!studentID.equals(userID)) | ||
throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity("User principal name doesn't match.").build()); | ||
throw new CPRException(Response.Status.FORBIDDEN, "User principal name doesn't match"); | ||
} | ||
} | ||
|
||
public void identifyingProfessorService(SecurityContext securityContext, MongoCollection<Document> courseCollection, String courseID) { | ||
if (securityContext.isUserInRole("professor")) { | ||
String userID = securityContext.getUserPrincipal().getName().split("@")[0]; | ||
Document courseDocument = courseCollection.find(Filters.eq("course_id", courseID)).first(); | ||
if (courseDocument == null) throw new CPRException(Response.Status.NOT_FOUND, "This professor does not exist."); | ||
String professorID = courseDocument.getString("professor_id"); | ||
if (!userID.equals(professorID)) | ||
throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity("User principal name doesn't match.").build()); | ||
if (!userID.equals(professorID)) | ||
throw new CPRException(Response.Status.FORBIDDEN, "User principal name doesn't match"); | ||
} | ||
} | ||
} |
110 changes: 49 additions & 61 deletions
110
.../peer-review-teams-microservice/src/main/java/edu/oswego/cs/services/SecurityService.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
backend/peer-review-teams-microservice/src/main/java/edu/oswego/cs/util/CPRException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package edu.oswego.cs.util; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.Response; | ||
|
||
public class CPRException extends WebApplicationException { | ||
public CPRException(Response.Status responseStatus, String errorMessage) { | ||
super(Response.status(responseStatus).entity(errorMessage).build()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...professor-assignment-microservice/src/main/java/edu/oswego/cs/rest/util/CPRException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package edu.oswego.cs.rest.util; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.Response; | ||
|
||
public class CPRException extends WebApplicationException { | ||
public CPRException(Response.Status responseStatus, String errorMessage) { | ||
super(Response.status(responseStatus).entity(errorMessage).build()); | ||
} | ||
} |