Skip to content

Commit

Permalink
fi(jans-config-api): return 404 with body when trying to fetch a non-…
Browse files Browse the repository at this point in the history
…existing trust relationship #8162

Signed-off-by: Rolain Djeumen <uprightech@gmail.com>
  • Loading branch information
uprightech committed Mar 28, 2024
1 parent fd4a16d commit 3aef560
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions jans-config-api/plugins/docs/kc-saml-plugin-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,12 @@ paths:
$ref: '#/components/schemas/TrustRelationship'
"401":
description: Unauthorized
"404":
description: Trust relationship not found
content:
application/json:
schema:
$ref: '#/components/schemas/ApiError'
"500":
description: InternalServerError
security:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public Response getAllTrustRelationship() {
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Ok", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = TrustRelationship.class))),
@ApiResponse(responseCode = "401", description = "Unauthorized"),
@ApiResponse(responseCode = "404", description = "Trust relationship not found",content=@Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ApiError.class))),
@ApiResponse(responseCode = "500", description = "InternalServerError") })
@GET
@ProtectedApi(scopes = { Constants.SAML_READ_ACCESS })
Expand All @@ -87,11 +88,19 @@ public Response getTrustRelationshipById(
logger.info("Searching TrustRelationship by id: {}", escapeLog(id));
}

TrustRelationship trustRelationship = samlService.getTrustRelationshipByInum(id);

logger.info("TrustRelationship found by id:{}, trustRelationship:{}", id, trustRelationship);

return Response.ok(trustRelationship).build();
TrustRelationship trustrelationship = samlService.getTrustRelationshipByInum(id);
if(trustrelationship != null) {
logger.info("TrustRelationship found by id:{}, trustRelationship:{}", id, trustrelationship);
return Response.ok(trustrelationship).build();
}else {
logger.info("TrustRelationship with id {} not found",id);
ApiError error = new ApiError.ErrorBuilder()
.withCode(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()))
.withMessage("Trust relationship not found")
.andDescription(String.format("The TrustRelationship with id '%s' was not found",id))
.build();
return Response.status(Response.Status.NOT_FOUND).entity(error).build();
}
}

@Operation(summary = "Create Trust Relationship with Metadata File", description = "Create Trust Relationship with Metadata File", operationId = "post-trust-relationship-metadata-file", tags = {
Expand Down

0 comments on commit 3aef560

Please sign in to comment.