-
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.
Group controller refactoring
- Loading branch information
Showing
7 changed files
with
123 additions
and
79 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
46 changes: 46 additions & 0 deletions
46
...ternet2/tier/shibboleth/admin/ui/security/controller/GroupControllerExceptionHandler.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,46 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.security.controller; | ||
|
|
||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.ControllerAdvice; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| import org.springframework.web.context.request.WebRequest; | ||
| import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; | ||
| import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.controller.ErrorResponse; | ||
| import edu.internet2.tier.shibboleth.admin.ui.exception.EntityNotFoundException; | ||
| import edu.internet2.tier.shibboleth.admin.ui.security.exception.GroupDeleteException; | ||
| import edu.internet2.tier.shibboleth.admin.ui.security.exception.GroupExistsConflictException; | ||
|
|
||
| @ControllerAdvice(assignableTypes = {GroupController.class}) | ||
| public class GroupControllerExceptionHandler extends ResponseEntityExceptionHandler { | ||
|
|
||
| @ExceptionHandler({ EntityNotFoundException.class }) | ||
| public ResponseEntity<?> handleEntityNotFoundException(EntityNotFoundException e, WebRequest request) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.setLocation(ServletUriComponentsBuilder.fromCurrentServletMapping().path("/api/admin/groups").build().toUri()); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.NOT_FOUND).headers(headers) | ||
| .body(new ErrorResponse(String.valueOf(HttpStatus.NOT_FOUND.value()), e.getMessage())); | ||
| } | ||
|
|
||
| @ExceptionHandler({ GroupDeleteException.class }) | ||
| public ResponseEntity<?> handleForbiddenAccess(GroupDeleteException e, WebRequest request) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.setLocation(ServletUriComponentsBuilder.fromCurrentServletMapping().path("/api/admin/groups/{resourceId}").build().toUri()); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.CONFLICT).headers(headers) | ||
| .body(new ErrorResponse(String.valueOf(HttpStatus.CONFLICT.value()), e.getMessage())); | ||
| } | ||
|
|
||
| @ExceptionHandler({ GroupExistsConflictException.class }) | ||
| public ResponseEntity<?> handleGroupExistsConflict(GroupExistsConflictException e, WebRequest request) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.setLocation(ServletUriComponentsBuilder.fromCurrentServletMapping().path("/api/admin/groups").build().toUri()); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).headers(headers) | ||
| .body(new ErrorResponse(String.valueOf(HttpStatus.METHOD_NOT_ALLOWED.value()), e.getMessage())); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
.../java/edu/internet2/tier/shibboleth/admin/ui/security/exception/GroupDeleteException.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,7 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.security.exception; | ||
|
|
||
| public class GroupDeleteException extends Exception { | ||
| public GroupDeleteException(String message) { | ||
| super(message); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
...u/internet2/tier/shibboleth/admin/ui/security/exception/GroupExistsConflictException.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,7 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.security.exception; | ||
|
|
||
| public class GroupExistsConflictException extends Exception { | ||
| public GroupExistsConflictException(String message) { | ||
| super(message); | ||
| } | ||
| } |
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