From 21dd6e5f273e968245508d6a03a8ac7b6cfd3125 Mon Sep 17 00:00:00 2001 From: pujavs <43700552+pujavs@users.noreply.github.com> Date: Fri, 18 Nov 2022 19:42:25 +0530 Subject: [PATCH] fix(config-api): error handling for agama get and org patch (#3028) --- jans-config-api/common/pom.xml | 4 ++-- .../docs/jans-config-api-swagger-auto.yaml | 22 +++++++++---------- .../docs/jans-admin-ui-plugin-swagger.yaml | 6 ++--- .../plugins/sample/helloworld/pom.xml | 5 ----- jans-config-api/pom.xml | 4 ++-- .../rest/resource/auth/AgamaResource.java | 21 ++++++++++-------- .../resource/auth/OrganizationResource.java | 13 ++++++++--- 7 files changed, 40 insertions(+), 35 deletions(-) diff --git a/jans-config-api/common/pom.xml b/jans-config-api/common/pom.xml index 752c214cb58..0b1feb31499 100644 --- a/jans-config-api/common/pom.xml +++ b/jans-config-api/common/pom.xml @@ -34,10 +34,10 @@ - + javax.servlet javax.servlet-api diff --git a/jans-config-api/docs/jans-config-api-swagger-auto.yaml b/jans-config-api/docs/jans-config-api-swagger-auto.yaml index 4a0b2154c07..2bcba276d05 100644 --- a/jans-config-api/docs/jans-config-api-swagger-auto.yaml +++ b/jans-config-api/docs/jans-config-api-swagger-auto.yaml @@ -7178,18 +7178,18 @@ components: $ref: '#/components/schemas/AttributeValidation' tooltip: type: string - adminCanEdit: + adminCanAccess: type: boolean userCanAccess: type: boolean - adminCanView: - type: boolean - adminCanAccess: - type: boolean userCanView: type: boolean + adminCanView: + type: boolean userCanEdit: type: boolean + adminCanEdit: + type: boolean whitePagesCanView: type: boolean baseDn: @@ -7528,6 +7528,8 @@ components: format: int32 displayName: type: string + tokenBindingSupported: + type: boolean authenticationMethod: type: string enum: @@ -7539,8 +7541,6 @@ components: - tls_client_auth - self_signed_tls_client_auth - none - tokenBindingSupported: - type: boolean baseDn: type: string inum: @@ -7622,6 +7622,8 @@ components: idTokenLifetime: type: integer format: int32 + allowOfflineAccessWithoutConsent: + type: boolean CustomObjectAttribute: type: object properties: @@ -8343,6 +8345,8 @@ components: $ref: '#/components/schemas/EngineConfig' ssaConfiguration: $ref: '#/components/schemas/SsaConfiguration' + fapi: + type: boolean allResponseTypesSupported: uniqueItems: true type: array @@ -8352,8 +8356,6 @@ components: - code - token - id_token - fapi: - type: boolean enabledFeatureFlags: uniqueItems: true type: array @@ -8860,8 +8862,6 @@ components: type: string jsFaviconPath: type: string - organizationTitle: - type: string baseDn: type: string Scope: diff --git a/jans-config-api/plugins/docs/jans-admin-ui-plugin-swagger.yaml b/jans-config-api/plugins/docs/jans-admin-ui-plugin-swagger.yaml index e3c9c9b3e63..a03ee668a5d 100644 --- a/jans-config-api/plugins/docs/jans-admin-ui-plugin-swagger.yaml +++ b/jans-config-api/plugins/docs/jans-admin-ui-plugin-swagger.yaml @@ -462,7 +462,7 @@ paths: description: InternalServerError security: - oauth2: - - https://jans.io/oauth/jans-auth-server/config/adminui/user/permission.write + - https://jans.io/oauth/jans-auth-server/config/adminui/user/permission.delete /admin-ui/adminUIRoles/{adminUIRole}: get: tags: @@ -523,7 +523,7 @@ paths: description: InternalServerError security: - oauth2: - - https://jans.io/oauth/jans-auth-server/config/adminui/user/role.write + - https://jans.io/oauth/jans-auth-server/config/adminui/user/role.delete /admin-ui/adminUIRolePermissionsMapping/{adminUIRole}: get: tags: @@ -584,7 +584,7 @@ paths: description: InternalServerError security: - oauth2: - - https://jans.io/oauth/jans-auth-server/config/adminui/user/rolePermissionMapping.write + - https://jans.io/oauth/jans-auth-server/config/adminui/user/rolePermissionMapping.delete components: schemas: LicenseRequest: diff --git a/jans-config-api/plugins/sample/helloworld/pom.xml b/jans-config-api/plugins/sample/helloworld/pom.xml index 9c9db53ee43..d39cbe2a856 100644 --- a/jans-config-api/plugins/sample/helloworld/pom.xml +++ b/jans-config-api/plugins/sample/helloworld/pom.xml @@ -126,11 +126,6 @@ resteasy-jackson2-provider ${resteasy.version} - - org.jboss.resteasy - resteasy-json-p-provider - ${resteasy.version} - diff --git a/jans-config-api/pom.xml b/jans-config-api/pom.xml index b60ec6fff1e..0e9ac1e6bc2 100644 --- a/jans-config-api/pom.xml +++ b/jans-config-api/pom.xml @@ -372,11 +372,11 @@ - + org.apache.commons commons-collections4 diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AgamaResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AgamaResource.java index 78bf66ea075..bb7a43d03c0 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AgamaResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AgamaResource.java @@ -115,9 +115,9 @@ public Response getFlowByName(@PathParam(ApiConstants.QNAME) @NotNull String flo @Operation(summary = "Create a new agama flow", description = "Create a new agama flow", operationId = "post-agama-flow", tags = { "Configuration – Agama Flow" }, security = @SecurityRequirement(name = "oauth2", scopes = { ApiAccessConstants.AGAMA_WRITE_ACCESS })) - @RequestBody(description = "Agama Flow", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Flow.class), examples = @ExampleObject(name = "Request example" , value = "example/agama/agama.json"))) + @RequestBody(description = "Agama Flow", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Flow.class), examples = @ExampleObject(name = "Request example", value = "example/agama/agama.json"))) @ApiResponses(value = { - @ApiResponse(responseCode = "201", description = "Created", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Flow.class) , examples = @ExampleObject(name = "Response example" , value = "example/agama/agama.json"))), + @ApiResponse(responseCode = "201", description = "Created", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Flow.class), examples = @ExampleObject(name = "Response example", value = "example/agama/agama.json"))), @ApiResponse(responseCode = "401", description = "Unauthorized"), @ApiResponse(responseCode = "500", description = "InternalServerError") }) @POST @@ -146,9 +146,9 @@ public Response createFlow(@Valid Flow flow) @Operation(summary = "Create a new agama flow from source", description = "Create a new agama flow from source.", operationId = "post-agama-flow-from-source", tags = { "Configuration – Agama Flow" }, security = @SecurityRequirement(name = "oauth2", scopes = { ApiAccessConstants.AGAMA_WRITE_ACCESS })) - @RequestBody(description = "Agama Flow", content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(implementation = String.class) , examples = @ExampleObject(name = "Request example" , value = "example/agama/test-agama-source.json"))) + @RequestBody(description = "Agama Flow", content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(implementation = String.class), examples = @ExampleObject(name = "Request example", value = "example/agama/test-agama-source.json"))) @ApiResponses(value = { - @ApiResponse(responseCode = "201", description = "Created", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Flow.class) , examples = @ExampleObject(name = "Response example" , value = "example/agama/agama.json"))), + @ApiResponse(responseCode = "201", description = "Created", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Flow.class), examples = @ExampleObject(name = "Response example", value = "example/agama/agama.json"))), @ApiResponse(responseCode = "400", description = "Bad Request"), @ApiResponse(responseCode = "401", description = "Unauthorized"), @ApiResponse(responseCode = "500", description = "InternalServerError") }) @@ -187,9 +187,9 @@ public Response createFlowFromSource(@PathParam(ApiConstants.QNAME) @NotNull Str @Operation(summary = "Update agama flow from source file", description = "Update agama flow from source file.", operationId = "put-agama-flow-from-source", tags = { "Configuration – Agama Flow" }, security = @SecurityRequirement(name = "oauth2", scopes = { ApiAccessConstants.AGAMA_WRITE_ACCESS })) - @RequestBody(description = "String representing patch-document.", content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(implementation = String.class), examples = @ExampleObject(name = "Request example" , value = "example/agama/test-agama-source.json"))) + @RequestBody(description = "String representing patch-document.", content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(implementation = String.class), examples = @ExampleObject(name = "Request example", value = "example/agama/test-agama-source.json"))) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Ok", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Flow.class), examples = @ExampleObject(name = "Response example" , value = "example/agama/agama.json"))), + @ApiResponse(responseCode = "200", description = "Ok", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Flow.class), examples = @ExampleObject(name = "Response example", value = "example/agama/agama.json"))), @ApiResponse(responseCode = "401", description = "Unauthorized"), @ApiResponse(responseCode = "404", description = "Not Found"), @ApiResponse(responseCode = "500", description = "InternalServerError") }) @@ -223,9 +223,9 @@ public Response updateFlowSource(@PathParam(ApiConstants.QNAME) @NotNull String @Operation(summary = "Partially modify a Agama Flow", description = "Partially modify a Agama Flow", operationId = "patch-agama-flow", tags = { "Configuration – Agama Flow" }, security = @SecurityRequirement(name = "oauth2", scopes = { ApiAccessConstants.AGAMA_WRITE_ACCESS })) - @RequestBody(description = "JsonPatch object", content = @Content(mediaType = MediaType.APPLICATION_JSON_PATCH_JSON, array = @ArraySchema(schema = @Schema(implementation = JsonPatch.class)) , examples = @ExampleObject(name = "Request example" , value = "example/agama/agama-patch.json"))) + @RequestBody(description = "JsonPatch object", content = @Content(mediaType = MediaType.APPLICATION_JSON_PATCH_JSON, array = @ArraySchema(schema = @Schema(implementation = JsonPatch.class)), examples = @ExampleObject(name = "Request example", value = "example/agama/agama-patch.json"))) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Patched Agama Flow", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Flow.class), examples = @ExampleObject(name = "Response example" , value = "example/agama/agama.json"))), + @ApiResponse(responseCode = "200", description = "Patched Agama Flow", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Flow.class), examples = @ExampleObject(name = "Response example", value = "example/agama/agama.json"))), @ApiResponse(responseCode = "401", description = "Unauthorized"), @ApiResponse(responseCode = "404", description = "Not Found"), @ApiResponse(responseCode = "500", description = "InternalServerError") }) @@ -397,12 +397,15 @@ private Flow updateMetadata(Flow flow) { } private Flow minimize(Flow flow, boolean includeSource) { - + if (flow == null) { + return flow; + } flow.setTranspiled(null); flow.setTransHash(null); if (!includeSource) { flow.setSource(null); } + return flow; } diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/OrganizationResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/OrganizationResource.java index 44d91dfd3aa..ca8f4718a7a 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/OrganizationResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/OrganizationResource.java @@ -43,7 +43,7 @@ public class OrganizationResource extends ConfigBaseResource { @Operation(summary = "Retrieves organization configuration", description = "Retrieves organization configuration", operationId = "get-organization-config", tags = { "Organization Configuration" }, security = @SecurityRequirement(name = "oauth2", scopes = { - ApiAccessConstants.ORG_CONFIG_READ_ACCESS })) + ApiAccessConstants.ORG_CONFIG_READ_ACCESS })) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Ok", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = GluuOrganization.class), examples = @ExampleObject(name = "Response json example", value = "example/org/org.json"))), @ApiResponse(responseCode = "401", description = "Unauthorized"), @@ -68,8 +68,15 @@ public Response getOrganization() { public Response patchOrganization(@NotNull String pathString) throws JsonPatchException, IOException { logger.trace("Organization patch request - pathString:{} ", pathString); GluuOrganization organization = organizationService.getOrganization(); - organization = Jackson.applyPatch(pathString, organization); - organizationService.updateOrganization(organization); + try { + + organization = Jackson.applyPatch(pathString, organization); + organizationService.updateOrganization(organization); + + } catch (Exception ex) { + logger.error("Error while patching Organization details", ex); + thorwInternalServerException(ex); + } return Response.ok(organizationService.getOrganization()).build(); }