-
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.
mid-work save
- Loading branch information
Showing
8 changed files
with
195 additions
and
21 deletions.
There are no files selected for viewing
37 changes: 30 additions & 7 deletions
37
...d/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/ActivateController.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,23 +1,46 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.controller; | ||
|
|
||
| import javax.script.ScriptException; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.springframework.web.bind.annotation.PatchMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.repository.EntityDescriptorRepository; | ||
| import edu.internet2.tier.shibboleth.admin.ui.security.service.UserService; | ||
| import edu.internet2.tier.shibboleth.admin.ui.domain.filters.MetadataFilter; | ||
| import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.EntityDescriptorRepresentation; | ||
| import edu.internet2.tier.shibboleth.admin.ui.exception.EntityNotFoundException; | ||
| import edu.internet2.tier.shibboleth.admin.ui.exception.ForbiddenException; | ||
| import edu.internet2.tier.shibboleth.admin.ui.service.EntityDescriptorService; | ||
| import edu.internet2.tier.shibboleth.admin.ui.service.FilterService; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/activate") | ||
| public class ActivateController { | ||
|
|
||
| @Autowired | ||
| private UserService userService; | ||
| private EntityDescriptorService entityDescriptorService; | ||
|
|
||
| @Autowired | ||
| private EntityDescriptorRepository entityDescriptorRepo; | ||
|
|
||
|
|
||
| private FilterService filterService; | ||
|
|
||
| @PatchMapping(path = "/entityDescriptor/{resourceId}/{mode}") | ||
| @Transactional | ||
| public ResponseEntity<?> enableEntityDescriptor(@PathVariable String resourceId, @PathVariable String mode) throws EntityNotFoundException, ForbiddenException { | ||
| boolean status = "enable".equalsIgnoreCase(mode); | ||
| EntityDescriptorRepresentation edr = entityDescriptorService.updateEntityDescriptorEnabledStatus(resourceId, status); | ||
| return ResponseEntity.ok(edr); | ||
| } | ||
|
|
||
| // Enable/disable for : entity descriptor, provider, filter | ||
| @PatchMapping(path = "/MetadataResolvers/{metadataResolverId}/Filter/{resourceId}/{mode}") | ||
| @Transactional | ||
| public ResponseEntity<?> enableFilter(@PathVariable String metadataResolverId, @PathVariable String resourceId, @PathVariable String mode) throws EntityNotFoundException, ForbiddenException, ScriptException { | ||
| boolean status = "enable".equalsIgnoreCase(mode); | ||
| MetadataFilter persistedFilter = filterService.updateFilterEnabledStatus(metadataResolverId, resourceId, status); | ||
| return ResponseEntity.ok(persistedFilter); | ||
| } | ||
| // Enable/disable for : , provider | ||
| } |
32 changes: 32 additions & 0 deletions
32
...main/java/edu/internet2/tier/shibboleth/admin/ui/controller/ActivateExceptionHandler.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,32 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.controller; | ||
|
|
||
| import javax.script.ScriptException; | ||
|
|
||
| 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 edu.internet2.tier.shibboleth.admin.ui.exception.EntityNotFoundException; | ||
| import edu.internet2.tier.shibboleth.admin.ui.exception.ForbiddenException; | ||
|
|
||
| @ControllerAdvice(assignableTypes = {ActivateController.class}) | ||
| public class ActivateExceptionHandler extends ResponseEntityExceptionHandler { | ||
|
|
||
| @ExceptionHandler({ EntityNotFoundException.class }) | ||
| public ResponseEntity<?> handleEntityNotFoundException(EntityNotFoundException e, WebRequest request) { | ||
| return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponse(HttpStatus.NOT_FOUND, e.getMessage())); | ||
| } | ||
|
|
||
| @ExceptionHandler({ ForbiddenException.class }) | ||
| public ResponseEntity<?> handleForbiddenAccess(ForbiddenException e, WebRequest request) { | ||
| return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new ErrorResponse(String.valueOf(HttpStatus.FORBIDDEN.value()), e.getMessage())); | ||
| } | ||
|
|
||
| @ExceptionHandler({ ScriptException.class }) | ||
| public ResponseEntity<?> handleScriptException(ScriptException e, WebRequest request) { | ||
| return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ErrorResponse(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()), e.getMessage())); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...nd/src/main/java/edu/internet2/tier/shibboleth/admin/ui/exception/ForbiddenException.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,11 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.exception; | ||
|
|
||
| public class ForbiddenException extends Exception { | ||
| public ForbiddenException() { | ||
| super("You are not authorized to perform the requested operation."); | ||
| } | ||
|
|
||
| public ForbiddenException(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
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