Skip to content

Commit

Permalink
Merge branch 'main' into agam-htmlunit
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyz authored Dec 19, 2024
2 parents 74c262f + 5bec96c commit 2c51ad8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 13 deletions.
50 changes: 42 additions & 8 deletions jans-config-api/docs/jans-config-api-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -9305,6 +9339,10 @@ components:
type: boolean
whitePagesCanView:
type: boolean
adminCanAccess:
type: boolean
userCanAccess:
type: boolean
adminCanView:
type: boolean
userCanView:
Expand All @@ -9313,10 +9351,6 @@ components:
type: boolean
adminCanEdit:
type: boolean
adminCanAccess:
type: boolean
userCanAccess:
type: boolean
baseDn:
type: string
PatchRequest:
Expand Down Expand Up @@ -10954,10 +10988,10 @@ components:
type: array
items:
type: object
value:
type: object
displayValue:
type: string
value:
type: object
LocalizedString:
type: object
properties:
Expand Down Expand Up @@ -11733,10 +11767,10 @@ components:
ttl:
type: integer
format: int32
opbrowserState:
type: string
persisted:
type: boolean
opbrowserState:
type: string
SessionIdAccessMap:
type: object
properties:
Expand Down
4 changes: 2 additions & 2 deletions jans-config-api/plugins/docs/user-mgt-plugin-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -863,10 +863,10 @@ components:
type: array
items:
type: object
value:
type: object
displayValue:
type: string
value:
type: object
CustomUser:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
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;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
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;
Expand Down Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

}

0 comments on commit 2c51ad8

Please sign in to comment.