Skip to content

Commit

Permalink
[SHIBUI-1063]
Browse files Browse the repository at this point in the history
Added an @Secured delete method for metadata sources. Also pulled in the
updated ErrorResponse from 1058.
  • Loading branch information
Bill Smith committed Jan 24, 2019
1 parent 2105029 commit 3c9063f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -26,6 +28,7 @@
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import javax.annotation.PostConstruct;
import javax.xml.ws.Response;
import java.net.URI;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -152,6 +155,20 @@ public Iterable<EntityDescriptorRepresentation> getDisabledAndNotOwnedByAdmin()
.collect(Collectors.toList());
}

@Secured("ROLE_ADMIN")
@DeleteMapping(value = "/EntityDescriptor/{resourceId}")
public ResponseEntity<?> deleteOne(@PathVariable String resourceId) {
EntityDescriptor ed = entityDescriptorRepository.findByResourceId(resourceId);
if (ed == null) {
return ResponseEntity.notFound().build();
} else if (ed.isServiceEnabled()) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new ErrorResponse(HttpStatus.FORBIDDEN, "Deleting an enabled Metadata Source is not allowed. Disable the source and try again."));
} else {
entityDescriptorRepository.delete(ed);
return ResponseEntity.noContent().build();
}
}

private static URI getResourceUriFor(EntityDescriptor ed) {
return ServletUriComponentsBuilder
.fromCurrentServletMapping().path("/api/EntityDescriptor")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.http.HttpStatus;

/**
* @author Bill Smith (wsmith@unicon.net)
Expand All @@ -15,4 +16,9 @@
public class ErrorResponse {
private String errorCode;
private String errorMessage;

public ErrorResponse(HttpStatus httpStatus, String errorMessage) {
this.errorCode = String.valueOf(httpStatus.value());
this.errorMessage = errorMessage;
}
}

0 comments on commit 3c9063f

Please sign in to comment.