Skip to content

Commit

Permalink
feat(jans-config-api): enhancements to saml api #7362 (#7989)
Browse files Browse the repository at this point in the history
* feat(jans-config-api): enhancements to saml api
* added method to get the trustrelationship metadata as a stream

Signed-off-by: Rolain Djeumen <uprightech@gmail.com>

* feat(jans-config-api): enhancements to saml api
* added method to SamlIdpService to get file from the DocumentStore

Signed-off-by: Rolain Djeumen <uprightech@gmail.com>

* feat(jans-config-api): enhancements to saml api #7362
* added endpoint to retrieve file metadata for trustrelationship

Signed-off-by: Rolain Djeumen <uprightech@gmail.com>

* feat(jans-config-api): enhancements to saml api #7362
* added newly generate swagger yaml for kc-saml-plugino

Signed-off-by: Rolain Djeumen <uprightech@gmail.com>

* feat(jans-config-api): enhancements to saml api #7362
* pluralized the operationid for the endpoint retrieving all trust relationships

Signed-off-by: Rolain Djeumen <uprightech@gmail.com>

---------

Signed-off-by: Rolain Djeumen <uprightech@gmail.com>
Former-commit-id: 2e1b8b3
  • Loading branch information
uprightech authored Mar 7, 2024
1 parent fa53b6d commit a88cbaa
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
43 changes: 42 additions & 1 deletion jans-config-api/plugins/docs/kc-saml-plugin-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ paths:
- SAML - Trust Relationship
summary: Get all Trust Relationship
description: Get all TrustRelationship.
operationId: get-trust-relationship
operationId: get-trust-relationships
responses:
"200":
description: Ok
Expand Down Expand Up @@ -830,6 +830,47 @@ paths:
security:
- oauth2:
- https://jans.io/oauth/config/saml.readonly
/kc/saml/trust-relationship/sp-metadata-file/{id}:
get:
tags:
- SAML - Trust Relationship
summary: Get TrustRelationship file metadata
description: Get TrustRelationship file metadata
operationId: get-trust-relationship-file-metadata
parameters:
- name: id
in: path
description: TrustRelationship inum
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/xml:
schema:
type: string
format: binary
"400":
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ApiError'
"401":
description: Unauthorized
"404":
description: Not Found
content:
application/json:
schema:
$ref: '#/components/schemas/ApiError'
"500":
description: Internal Server Error
security:
- oauth2:
- https://jans.io/oauth/config/saml.readonly
/kc/saml/trust-relationship/process-sp-meta-file:
post:
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class TrustRelationshipResource extends BaseResource {
@Inject
SamlService samlService;

@Operation(summary = "Get all Trust Relationship", description = "Get all TrustRelationship.", operationId = "get-trust-relationship", tags = {
@Operation(summary = "Get all Trust Relationship", description = "Get all TrustRelationship.", operationId = "get-trust-relationships", tags = {
"SAML - Trust Relationship" }, security = @SecurityRequirement(name = "oauth2", scopes = {
Constants.SAML_READ_ACCESS }))
@ApiResponses(value = {
Expand Down Expand Up @@ -240,6 +240,36 @@ public Response deleteTrustRelationship(
return Response.noContent().build();
}

@Operation(summary="Get TrustRelationship file metadata", description="Get TrustRelationship file metadata",
operationId = "get-trust-relationship-file-metadata", tags = {"SAML - Trust Relationship"},
security = @SecurityRequirement(name = "oauth2", scopes= {Constants.SAML_READ_ACCESS}),
responses = {
@ApiResponse(responseCode="200",description="OK",content= @Content(mediaType = MediaType.APPLICATION_XML,schema = @Schema(type="string",format="binary"))),
@ApiResponse(responseCode="400",description="Bad Request",content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ApiError.class, description = "BadRequestException"))),
@ApiResponse(responseCode="401",description="Unauthorized"),
@ApiResponse(responseCode="404",description="Not Found",content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ApiError.class, description = "NotFoundException"))),
@ApiResponse(responseCode="500",description="Internal Server Error")
}
)
@Path(Constants.SP_METADATA_FILE_PATH+Constants.ID_PATH_PARAM)
@GET
@ProtectedApi(scopes = {Constants.SAML_READ_ACCESS})
public Response gettrustRelationshipFileMetadata(
@Parameter(description="TrustRelationship inum") @PathParam(Constants.ID) @NotNull String id) {

logger.info("getTrustRelationshipFileMeta(). ID: - {}",id);
TrustRelationship trustrelationship = samlService.getTrustRelationshipByInum(id);
checkResourceNotNull(trustrelationship,SAML_TRUST_RELATIONSHIP);
if(trustrelationship.getSpMetaDataSourceType() != MetadataSourceType.FILE) {
throwBadRequestException("TrustRelationship metadatasource type isn't a FILE");
}
InputStream fs = samlService.getTrustRelationshipMetadataFile(trustrelationship);
if(fs == null) {
return getNotFoundError(String.format("metadata file for tr '%s' ",id));
}
return Response.ok(fs,MediaType.APPLICATION_XML).build();
}

@Operation(summary = "Process unprocessed metadata files", description = "Process unprocessed metadata files", operationId = "post-metadata-files", tags = {
"SAML - Trust Relationship" }, security = @SecurityRequirement(name = "oauth2", scopes = {
Constants.SAML_WRITE_ACCESS }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ public boolean renameMetadata(String metadataPath, String destinationMetadataPat
return false;
}

public InputStream getFileFromDocumentStore(String path) {

logger.debug("Get file from DocumentStore. Path: {}",path);
try {
return documentStoreService.readDocumentAsStream(path);
}catch(Exception e) {
logger.error("Failed to get file '{}' from DocumentStore",path);
return null;
}
}

private String getTempMetadataFilename(String metadataFolder, String fileName) {
logger.info("documentStoreService:{}, localDocumentStoreService:{}, metadataFolder:{}, fileName:{}",
documentStoreService, localDocumentStoreService, metadataFolder, fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,5 +359,11 @@ public void processUnprocessedSpMetadataFiles() {

}
}

public InputStream getTrustRelationshipMetadataFile(TrustRelationship trustrelationship) {

log.debug("Get trustrelationship metadata file");
return samlIdpService.getFileFromDocumentStore(trustrelationship.getSpMetaDataFN());
}

}

0 comments on commit a88cbaa

Please sign in to comment.