diff --git a/jans-config-api/docs/jans-config-api-swagger.yaml b/jans-config-api/docs/jans-config-api-swagger.yaml index 53ae67f689c..c1a1c82474a 100644 --- a/jans-config-api/docs/jans-config-api-swagger.yaml +++ b/jans-config-api/docs/jans-config-api-swagger.yaml @@ -497,6 +497,40 @@ paths: security: - oauth2: - https://jans.io/oauth/config/agama.readonly + /api/v1/agama-repo/download: + get: + tags: + - Agama + summary: Download agama project. + description: Download agama project. + operationId: get-agama-project + parameters: + - name: downloadLink + in: query + description: Agama project download Link + schema: + type: string + responses: + "200": + description: Agama project + content: + application/json: + schema: + type: string + format: binary + "204": + description: No Content + "401": + description: Unauthorized + "404": + description: Not Found + "500": + description: InternalServerError + security: + - oauth2: + - https://jans.io/oauth/config/agama-repo.readonly + - https://jans.io/oauth/config/agama-repo.write + - https://jans.io/oauth/config/read-all /api/v1/agama-repo: get: tags: @@ -9305,6 +9339,10 @@ components: type: boolean whitePagesCanView: type: boolean + adminCanAccess: + type: boolean + userCanAccess: + type: boolean adminCanView: type: boolean userCanView: @@ -9313,10 +9351,6 @@ components: type: boolean adminCanEdit: type: boolean - adminCanAccess: - type: boolean - userCanAccess: - type: boolean baseDn: type: string PatchRequest: @@ -10954,10 +10988,10 @@ components: type: array items: type: object - value: - type: object displayValue: type: string + value: + type: object LocalizedString: type: object properties: @@ -11733,10 +11767,10 @@ components: ttl: type: integer format: int32 - opbrowserState: - type: string persisted: type: boolean + opbrowserState: + type: string SessionIdAccessMap: type: object properties: diff --git a/jans-config-api/plugins/docs/user-mgt-plugin-swagger.yaml b/jans-config-api/plugins/docs/user-mgt-plugin-swagger.yaml index a23d9c4e828..9113a738b01 100644 --- a/jans-config-api/plugins/docs/user-mgt-plugin-swagger.yaml +++ b/jans-config-api/plugins/docs/user-mgt-plugin-swagger.yaml @@ -863,10 +863,10 @@ components: type: array items: type: object - value: - type: object displayValue: type: string + value: + type: object CustomUser: type: object properties: diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AgamaRepoResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AgamaRepoResource.java index f5b46ba582a..05f281c53e8 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AgamaRepoResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AgamaRepoResource.java @@ -16,6 +16,7 @@ import io.jans.configapi.util.ApiConstants; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; @@ -23,8 +24,10 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.*; -import jakarta.inject.Inject; +import static io.jans.as.model.util.Util.escapeLog; +import java.io.IOException; +import jakarta.inject.Inject; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; @@ -68,5 +71,29 @@ public class AgamaRepoResource extends ConfigBaseResource { public Response getAllAgamaRepositories() { return Response.ok(agamaRepoService.getAllAgamaRepositories()).build(); } - + + @Operation(summary = "Download agama project.", description = "Download agama project.", operationId = "get-agama-project", tags = { + "Agama" }, security = @SecurityRequirement(name = "oauth2", scopes = { + ApiAccessConstants.AGAMA_REPO_READ_ACCESS, ApiAccessConstants.AGAMA_REPO_WRITE_ACCESS, + ApiAccessConstants.SUPER_ADMIN_READ_ACCESS })) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Agama project", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = String.class, format = "binary"))), + @ApiResponse(responseCode = "204", description = "No Content"), + @ApiResponse(responseCode = "401", description = "Unauthorized"), + @ApiResponse(responseCode = "404", description = "Not Found"), + @ApiResponse(responseCode = "500", description = "InternalServerError") }) + @GET + @ProtectedApi(scopes = { ApiAccessConstants.AGAMA_REPO_READ_ACCESS }, groupScopes = { + ApiAccessConstants.AGAMA_REPO_WRITE_ACCESS }, superScopes = { ApiAccessConstants.SUPER_ADMIN_READ_ACCESS }) + @Produces(MediaType.APPLICATION_JSON) + @Path("/download") + public Response getAgamaProject( + @Parameter(description = "Agama project download Link") @QueryParam(value = "downloadLink") String downloadLink) + throws IOException { + if (logger.isInfoEnabled()) { + logger.info(" Agama Project File downloadLink :{}", escapeLog(downloadLink)); + } + return Response.ok(agamaRepoService.getAgamaProject(downloadLink)).build(); + } + } \ No newline at end of file diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/AgamaRepoService.java b/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/AgamaRepoService.java index 6bec8c06226..8bb5cd5ec6b 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/AgamaRepoService.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/AgamaRepoService.java @@ -2,10 +2,21 @@ import com.fasterxml.jackson.databind.JsonNode; +import io.jans.as.model.util.Util; import io.jans.configapi.service.status.StatusCheckerTimer; +import io.jans.util.exception.InvalidAttributeException; +import static io.jans.as.model.util.Util.escapeLog; + +import java.io.IOException; +import java.net.URLDecoder; +import java.net.URL; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.io.IOUtils; import org.slf4j.Logger; @ApplicationScoped @@ -20,5 +31,17 @@ public class AgamaRepoService { public JsonNode getAllAgamaRepositories() { return statusCheckerTimer.getAllAgamaRepositories(); } - + + public byte[] getAgamaProject(String downloadLink) throws IOException { + if (logger.isInfoEnabled()) { + logger.info("Fetch Agama Project File from :{}", escapeLog(downloadLink)); + } + if (StringUtils.isBlank(downloadLink)) { + throw new InvalidAttributeException("Agama Project url is null!!!"); + } + String url = URLDecoder.decode(downloadLink, Util.UTF8_STRING_ENCODING); + logger.info("Decoded Agama Project url :{}", url); + return Base64.encodeBase64(IOUtils.toByteArray((new URL(url)).openStream()), true); + } + } \ No newline at end of file