diff --git a/jans-config-api/plugins/docs/kc-saml-plugin-swagger.yaml b/jans-config-api/plugins/docs/kc-saml-plugin-swagger.yaml index c6275308780..2e3f092dddc 100644 --- a/jans-config-api/plugins/docs/kc-saml-plugin-swagger.yaml +++ b/jans-config-api/plugins/docs/kc-saml-plugin-swagger.yaml @@ -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: diff --git a/jans-config-api/plugins/kc-saml-plugin/src/main/java/io/jans/configapi/plugin/saml/rest/TrustRelationshipResource.java b/jans-config-api/plugins/kc-saml-plugin/src/main/java/io/jans/configapi/plugin/saml/rest/TrustRelationshipResource.java index 677d35f3ae3..c7111fa21c3 100644 --- a/jans-config-api/plugins/kc-saml-plugin/src/main/java/io/jans/configapi/plugin/saml/rest/TrustRelationshipResource.java +++ b/jans-config-api/plugins/kc-saml-plugin/src/main/java/io/jans/configapi/plugin/saml/rest/TrustRelationshipResource.java @@ -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 }) @@ -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 = {