1515import org .springframework .beans .factory .annotation .Autowired ;
1616import org .springframework .beans .factory .annotation .Value ;
1717import org .springframework .http .ResponseEntity ;
18- import org .springframework .security .access .annotation . Secured ;
18+ import org .springframework .security .access .prepost . PreAuthorize ;
1919import org .springframework .security .acls .model .Permission ;
2020import org .springframework .security .core .Authentication ;
2121import org .springframework .web .bind .annotation .GetMapping ;
5050 */
5151@ RestController
5252@ RequestMapping ("/api/teacher" )
53- @ Secured ({ "ROLE_TEACHER" })
5453public class TeacherAPIController extends UserAPIController {
5554
5655 @ Autowired
@@ -66,6 +65,7 @@ public class TeacherAPIController extends UserAPIController {
6665 private String googleClientSecret ;
6766
6867 @ GetMapping ("/runs" )
68+ @ PreAuthorize ("hasRole('ROLE_TEACHER')" )
6969 List <HashMap <String , Object >> getRuns (Authentication auth ,
7070 @ RequestParam (required = false ) Integer max ) {
7171 User user = userService .retrieveUserByUsername (auth .getName ());
@@ -90,6 +90,7 @@ private List<HashMap<String, Object>> getRunsList(User user, List<Run> runs) {
9090 }
9191
9292 @ GetMapping ("/run/{runId}" )
93+ @ PreAuthorize ("hasRole('ROLE_TEACHER')" )
9394 HashMap <String , Object > getRun (Authentication auth , @ PathVariable Long runId )
9495 throws ObjectNotFoundException {
9596 User user = userService .retrieveUserByUsername (auth .getName ());
@@ -111,6 +112,7 @@ protected HashMap<String, Object> getRunMap(User user, Run run) {
111112 }
112113
113114 @ GetMapping ("/projectlastrun/{projectId}" )
115+ @ PreAuthorize ("hasRole('ROLE_TEACHER')" )
114116 HashMap <String , Object > getProjectLastRun (Authentication auth , @ PathVariable Long projectId ) {
115117 User user = userService .retrieveUserByUsername (auth .getName ());
116118 List <Run > runsOfProject = runService .getProjectRuns (projectId );
@@ -124,12 +126,13 @@ HashMap<String, Object> getProjectLastRun(Authentication auth, @PathVariable Lon
124126 }
125127
126128 @ GetMapping ("/usernames" )
129+ @ PreAuthorize ("hasRole('ROLE_TEACHER')" )
127130 List <String > getAllTeacherUsernames () {
128131 return userDetailsService .retrieveAllTeacherUsernames ();
129132 }
130133
131134 @ PostMapping ("/register" )
132- @ Secured ({ "ROLE_ANONYMOUS" } )
135+ @ PreAuthorize ( "permitAll()" )
133136 ResponseEntity <Map <String , Object >> createTeacherAccount (
134137 @ RequestBody Map <String , String > teacherFields , HttpServletRequest request )
135138 throws DuplicateUsernameException , InvalidNameException {
@@ -252,6 +255,7 @@ private List<Integer> getSharedOwnerPermissionsList(Run run, User user) {
252255 }
253256
254257 @ PostMapping ("/run/create" )
258+ @ PreAuthorize ("hasRole('ROLE_TEACHER')" )
255259 HashMap <String , Object > createRun (Authentication auth , HttpServletRequest request ,
256260 @ RequestParam Long projectId , @ RequestParam String periods , @ RequestParam boolean isSurvey ,
257261 @ RequestParam Integer maxStudentsPerTeam , @ RequestParam Long startDate ,
@@ -275,6 +279,7 @@ private Set<String> createPeriodNamesSet(String periodsString) {
275279 }
276280
277281 @ PostMapping ("/profile/update" )
282+ @ PreAuthorize ("hasRole('ROLE_TEACHER')" )
278283 SimpleResponse updateProfile (Authentication auth , @ RequestParam String displayName ,
279284 @ RequestParam String email , @ RequestParam String city , @ RequestParam String state ,
280285 @ RequestParam String country , @ RequestParam String schoolName ,
@@ -294,6 +299,7 @@ SimpleResponse updateProfile(Authentication auth, @RequestParam String displayNa
294299 }
295300
296301 @ PostMapping ("/run/add/period" )
302+ @ PreAuthorize ("hasRole('ROLE_TEACHER')" )
297303 HashMap <String , Object > addPeriodToRun (Authentication auth , @ RequestParam Long runId ,
298304 @ RequestParam String periodName ) throws ObjectNotFoundException {
299305 User user = userService .retrieveUserByUsername (auth .getName ());
@@ -318,6 +324,7 @@ HashMap<String, Object> addPeriodToRun(Authentication auth, @RequestParam Long r
318324 }
319325
320326 @ PostMapping ("/run/delete/period" )
327+ @ PreAuthorize ("hasRole('ROLE_TEACHER')" )
321328 HashMap <String , Object > deletePeriodFromRun (Authentication auth , @ RequestParam Long runId ,
322329 @ RequestParam String periodName ) throws ObjectNotFoundException , PeriodNotFoundException {
323330 User user = userService .retrieveUserByUsername (auth .getName ());
@@ -341,6 +348,7 @@ HashMap<String, Object> deletePeriodFromRun(Authentication auth, @RequestParam L
341348 }
342349
343350 @ PostMapping ("/run/update/studentsperteam" )
351+ @ PreAuthorize ("hasRole('ROLE_TEACHER')" )
344352 HashMap <String , Object > editRunStudentsPerTeam (Authentication auth , @ RequestParam Long runId ,
345353 @ RequestParam ("maxStudentsPerTeam" ) Integer newMax ) throws ObjectNotFoundException {
346354 User user = userService .retrieveUserByUsername (auth .getName ());
@@ -363,6 +371,7 @@ HashMap<String, Object> editRunStudentsPerTeam(Authentication auth, @RequestPara
363371 }
364372
365373 @ PostMapping ("/run/update/starttime" )
374+ @ PreAuthorize ("hasRole('ROLE_TEACHER')" )
366375 HashMap <String , Object > editRunStartTime (Authentication authentication , @ RequestParam Long runId ,
367376 @ RequestParam Long startTime ) throws ObjectNotFoundException {
368377 User user = userService .retrieveUserByUsername (authentication .getName ());
@@ -386,6 +395,7 @@ HashMap<String, Object> editRunStartTime(Authentication authentication, @Request
386395 }
387396
388397 @ PostMapping ("/run/update/endtime" )
398+ @ PreAuthorize ("hasRole('ROLE_TEACHER')" )
389399 HashMap <String , Object > editRunEndTime (Authentication authentication , @ RequestParam Long runId ,
390400 @ RequestParam (required = false ) Long endTime ) throws ObjectNotFoundException {
391401 User user = userService .retrieveUserByUsername (authentication .getName ());
@@ -408,6 +418,7 @@ HashMap<String, Object> editRunEndTime(Authentication authentication, @RequestPa
408418 }
409419
410420 @ PostMapping ("/run/update/islockedafterenddate" )
421+ @ PreAuthorize ("hasRole('ROLE_TEACHER')" )
411422 HashMap <String , Object > editRunIsLockedAfterEndDate (Authentication authentication ,
412423 @ RequestParam Long runId , @ RequestParam Boolean isLockedAfterEndDate )
413424 throws ObjectNotFoundException {
0 commit comments