Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jans-config-api): enhancements to saml api #7362 #7989

Merged
merged 6 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}

}