forked from ls1intum/Artemis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/role instructor (ls1intum#48)
* added new role ROLE_INSTRUCTOR for courses and review all REST endpoints for security aspects: now we check the role first and additionally evaluate if the user is instructor or TA in the particular course to determine if the user can invoke a request. * add course start and end date and boolean flag for online courses
- Loading branch information
Showing
40 changed files
with
670 additions
and
368 deletions.
There are no files selected for viewing
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
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
30 changes: 0 additions & 30 deletions
30
src/main/java/de/tum/in/www1/exerciseapp/config/MethodSecurityConfig.java
This file was deleted.
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
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
65 changes: 0 additions & 65 deletions
65
src/main/java/de/tum/in/www1/exerciseapp/security/CustomPermissionEvaluator.java
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
src/main/java/de/tum/in/www1/exerciseapp/service/AuthorizationCheckService.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,81 @@ | ||
package de.tum.in.www1.exerciseapp.service; | ||
|
||
import de.tum.in.www1.exerciseapp.domain.*; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Service used to check whether user is authorized to perform actions on the entity. | ||
*/ | ||
@Service | ||
public class AuthorizationCheckService { | ||
|
||
private final Logger log = LoggerFactory.getLogger(AuthorizationCheckService.class); | ||
|
||
private final UserService userService; | ||
private Authority adminAuthority; | ||
|
||
public AuthorizationCheckService(UserService userService) { | ||
this.userService = userService; | ||
adminAuthority = new Authority(); | ||
adminAuthority.setName("ROLE_ADMIN"); | ||
} | ||
|
||
/** | ||
* Method used to check whether the current logged in user is authorized to view this course | ||
* @param course course to check the rights for | ||
* @return true, if user is authorized to view this course, otherwise false | ||
*/ | ||
public boolean isAuthorizedForCourse(Course course) { | ||
log.debug("Request to check access rights to course with id: {}", course.getId()); | ||
if(course == null) { | ||
return true; | ||
} | ||
User user = userService.getUserWithGroupsAndAuthorities(); | ||
if(user.getGroups().contains(course.getStudentGroupName()) | ||
|| user.getGroups().contains(course.getTeachingAssistantGroupName()) | ||
|| user.getGroups().contains(course.getInstructorGroupName()) | ||
|| user.getAuthorities().contains(adminAuthority)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
|
||
/** | ||
* Method used to check whether the current logged in user is authorized to view this exercise | ||
* @param exercise exercise to check the rights for | ||
* @return true, if user is authorized to view this exercise, otherwise false | ||
*/ | ||
public boolean isAuthorizedForExercise(Exercise exercise) { | ||
log.debug("Request to check access rights to exercise with id: {}", exercise.getId()); | ||
if(exercise == null) { | ||
return true; | ||
} | ||
Course correspondingCourse = exercise.getCourse(); | ||
return isAuthorizedForCourse(correspondingCourse); | ||
} | ||
|
||
/** | ||
* Method used to check whether the current logged in user is authorized to view this participation | ||
* @param participation participation to check the rights for | ||
* @return true, if user is authorized to view this participation, otherwise false | ||
*/ | ||
public boolean isAuthorizedForParticipation(Participation participation) { | ||
log.debug("Request to check access rights to participation with id: {}", participation.getId()); | ||
if(participation == null) { | ||
return true; | ||
} | ||
User user = userService.getUserWithGroupsAndAuthorities(); | ||
Course course = participation.getExercise().getCourse(); | ||
if(participation.getStudent().getLogin().equals(user.getLogin()) | ||
|| user.getGroups().contains(course.getTeachingAssistantGroupName()) | ||
|| user.getGroups().contains(course.getInstructorGroupName()) | ||
|| user.getAuthorities().contains(adminAuthority)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |
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
Oops, something went wrong.