Skip to content
Snippets Groups Projects

Resolve "Authorization endpoint"

5 files
+ 303
8
Compare changes
  • Side-by-side
  • Inline

Files

/*
* Labracore - A connecting core service for Labrador products
* Copyright (C) 2020- Delft University of Technology
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package nl.tudelft.labracore.controller;
import javax.transaction.Transactional;
import nl.tudelft.labracore.model.RoleType;
import nl.tudelft.labracore.security.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Transactional
@RestController
@RequestMapping("/api/auth")
public class AuthorizationController {
@Autowired
private AuthorizationService authService;
/**
* Checks whether a person already has a role in the edition.
*
* @param personId the id of the person
* @param editionId the id of the edition
* @return true if the person already has a role in the edition
*/
@GetMapping("/{personId}/role/{editionId}/edition")
public Boolean hasRoleInEdition(@PathVariable Long personId, @PathVariable Long editionId) {
return authService.hasRoleInEdition(personId, editionId);
}
/**
* Checks whether a person has a specific role in the edition.
*
* @param personId the id of the person
* @param editionId the id of the edition
* @param type the type of the role the person should have
* @return true if the person already has a role in the edition
*/
@GetMapping("/{personId}/specific-role/{editionId}/edition")
public Boolean hasSpecificRoleInEdition(@PathVariable Long personId,
@PathVariable Long editionId,
@RequestParam RoleType type) {
return authService.hasSpecificRoleInEdition(personId, editionId, type);
}
/**
* Checks whether a person has the authority to create a course edition for a course.
*
* @param personId the id of the person
* @param courseId the id of the course
* @return true if the person is the manager of the course
*/
@GetMapping("/{personId}/course-manager/{courseId}")
public Boolean isCourseManager(@PathVariable Long personId, @PathVariable Long courseId) {
return authService.isCourseManager(personId, courseId);
}
/**
* Checks whether a person can read course information. They must either a the manager of the course or
* have the role of teacher(-RO) in any of the course editions.
*
* @param personId the id of the person
* @param courseId the id of the course
* @return true if the person can read the data of a course
*/
@GetMapping("/{personId}/course-read/{courseId}")
public Boolean canReadCoure(@PathVariable Long personId, @PathVariable Long courseId) {
return authService.canReadCourse(personId, courseId);
}
}
Loading