From 8bb8b700ae4986707d35af39e8811c80a5073023 Mon Sep 17 00:00:00 2001 From: pujavs <43700552+pujavs@users.noreply.github.com> Date: Fri, 2 Sep 2022 00:47:10 +0530 Subject: [PATCH] feat(jans-config-api): pagination functionality for attribute endoint (#2232) * feat(config-api): added pagination related param to request * feat(jans-config-api): pagination enhancement * feat(jans-config-api): pagination enhancement * feat(jans-config-api): pagination enhancement * feat(jans-config-api): pagination changes * feat(jans-config-api): pagination changes * feat(jans-config-api): pagination code * feat(jans-config-api): pagination code * feat(jans-config-api): pagination code * feat(jans-config-api): pagination code * feat(jans-config-api): pagination code --- .../io/jans/configapi/util/ApiConstants.java | 9 +- .../docs/jans-config-api-swagger.yaml | 112 ++++++++++++------ .../default/config-api-test.properties | 2 +- .../rest/resource/auth/AgamaResource.java | 2 +- .../resource/auth/AttributesResource.java | 76 +++++++----- .../rest/resource/auth/ClientsResource.java | 4 +- .../resource/auth/ConfigBaseResource.java | 13 +- .../resource/auth/CustomScriptResource.java | 2 +- .../rest/resource/auth/ScopesResource.java | 2 +- .../resource/auth/UmaResourcesResource.java | 2 +- .../service/auth/AttributeService.java | 41 +++++++ 11 files changed, 175 insertions(+), 90 deletions(-) diff --git a/jans-config-api/common/src/main/java/io/jans/configapi/util/ApiConstants.java b/jans-config-api/common/src/main/java/io/jans/configapi/util/ApiConstants.java index c1c46b16aa9..5414c40eea3 100644 --- a/jans-config-api/common/src/main/java/io/jans/configapi/util/ApiConstants.java +++ b/jans-config-api/common/src/main/java/io/jans/configapi/util/ApiConstants.java @@ -108,8 +108,6 @@ private ApiConstants() {} public static final String ACTIVE = "active"; public static final String INACTIVE = "inactive"; - - // API Protection public static final String PROTECTION_TYPE_OAUTH2 = "oauth2"; public static final String PROTECTION_TYPE_UMA = "uma"; @@ -127,5 +125,12 @@ private ApiConstants() {} public static final int DEFAULT_MAX_COUNT = 200; public static final String SORT_BY = "sortBy"; public static final String SORT_ORDER = "sortOrder"; + public static final String ASCENDING = "ascending"; + public static final String DESCENDING = "descending"; + public static final String TOTAL_ITEMS = "totalItems"; + public static final String ENTRIES_COUNT = "entriesCount"; + public static final String DATA = "data"; + + } \ No newline at end of file diff --git a/jans-config-api/docs/jans-config-api-swagger.yaml b/jans-config-api/docs/jans-config-api-swagger.yaml index 3101c7f7df7..75a5d816704 100644 --- a/jans-config-api/docs/jans-config-api-swagger.yaml +++ b/jans-config-api/docs/jans-config-api-swagger.yaml @@ -195,11 +195,12 @@ paths: $ref: '#/components/responses/InternalServerError' security: - oauth2: [ https://jans.io/oauth/config/fido2.readonly ] + /jans-config-api/api/v1/attributes: get: summary: Gets a list of Gluu attributes. description: 'Gets all attributes. Optionally max-size of the result, attribute status and pattern can be provided.' - operationId: get-attributes + operationId: get-all-attribute tags: - Attribute responses: @@ -208,11 +209,21 @@ paths: content: application/json: schema: - title: Gluu Attributes - description: List of all attribute. - type: array - items: - $ref: '#/components/schemas/GluuAttribute' + title: Gluu Attributes paginated result + description: Gluu Attributes paginated result + type: object + properties: + totalItems: + type: integer + description: Total number of records in the database. + entriesCount: + type: integer + description: Total number of records in the response. + data: + description: List of all attribute. + type: array + items: + $ref: '#/components/schemas/GluuAttribute' '401': description: Unauthorized '500': @@ -237,6 +248,30 @@ paths: in: query name: status description: Status of the attribute + - schema: + type: integer + default: 1 + in: query + name: startIndex + description: The 1-based index of the first query result. + - schema: + type: string + default: inum + in: query + name: sortBy + description: Attribute whose value will be used to order the returned response. + - schema: + type: string + default: ascending + enum: + - ascending + - descending + in: query + name: sortOrder + description: Order in which the sortBy param is applied. Allowed values are "ascending" and "descending". + + + post: summary: Adds a new attribute. description: Adds a new attribute. @@ -1018,7 +1053,7 @@ paths: $ref: '#/components/responses/InternalServerError' security: - oauth2: [https://jans.io/oauth/config/scripts.write] - + /jans-config-api/api/v1/config/scripts/name/{name}: parameters: - name: name @@ -2054,7 +2089,7 @@ paths: description: Internal Server Error security: - oauth2: [https://jans.io/oauth/config/openid/clients.write] - + /jans-config-api/api/v1/uma/resources: get: tags: @@ -2171,7 +2206,7 @@ paths: description: Internal Server Error security: - oauth2: [https://jans.io/oauth/config/uma/resources.readonly] - + delete: tags: - OAuth - UMA Resources @@ -2189,7 +2224,7 @@ paths: description: Internal Server Error security: - oauth2: [https://jans.io/oauth/config/uma/resources.delete] - + patch: tags: - OAuth - UMA Resources @@ -2221,8 +2256,8 @@ paths: description: Internal Server Error security: - oauth2: [https://jans.io/oauth/config/uma/resources.write] - - + + /jans-config-api/api/v1/uma/resources/clientId/{clientId}: parameters: - name: clientId @@ -2443,7 +2478,7 @@ paths: description: Internal Server Error security: - oauth2: [https://jans.io/oauth/config/scopes.write] - + /jans-config-api/api/v1/scopes/creator/{creatorId}: parameters: - schema: @@ -2476,7 +2511,7 @@ paths: description: Internal Server Error security: - oauth2: ['https://jans.io/oauth/config/scopes.readonly'] - + /jans-config-api/api/v1/scopes/type/{type}: parameters: - schema: @@ -2561,7 +2596,7 @@ paths: $ref: '#/components/responses/InternalServerError' security: - oauth2: [https://jans.io/oauth/config/agama.write] - + /jans-config-api/api/v1/agama/{qname}: parameters: - schema: @@ -2590,7 +2625,7 @@ paths: $ref: '#/components/responses/InternalServerError' security: - oauth2: [https://jans.io/oauth/config/agama.readonly] - + post: summary: Create a new agama flow from source. description: Create a new agama flow from source. @@ -2647,7 +2682,7 @@ paths: $ref: '#/components/responses/InternalServerError' security: - oauth2: [https://jans.io/oauth/config/agama.write] - + delete: summary: Deletes an agama flow based on Qname. description: Deletes an agama flow based on Qname. @@ -2665,7 +2700,7 @@ paths: description: Internal Server Error security: - oauth2: [https://jans.io/oauth/config/agama.delete] - + /jans-config-api/api/v1/agama/source/{qname}: parameters: - schema: @@ -2674,7 +2709,7 @@ paths: in: path description: flow qname. required: true - + put: summary: Update agama flow from source file. description: Update agama flow from source file. @@ -2700,7 +2735,7 @@ paths: $ref: '#/components/responses/InternalServerError' security: - oauth2: [https://jans.io/oauth/config/agama.write] - + /jans-config-api/api/v1/stat: get: summary: Provides server with basic statistic. @@ -2818,7 +2853,7 @@ paths: $ref: '#/components/schemas/StatsData' '500': description: Internal Server Error - + /jans-config-api/api/v1/jans-auth-server/session: get: summary: Returns current session. @@ -2843,7 +2878,7 @@ paths: $ref: '#/components/responses/Unauthorized' '500': description: Internal Server Error - + /jans-config-api/api/v1/jans-auth-server/session/{userDn}: parameters: - name: userDn @@ -4269,7 +4304,7 @@ components: example: 'https://server.example.com/jans-auth/restv1/par' requirePar: description: boolean value to indicate of Pushed Authorisation Request(PAR)is required. - type: boolean + type: boolean deviceAuthzEndpoint: type: string description: URL for the Device Authorization. @@ -4301,11 +4336,11 @@ components: mtlsEndSessionEndpoint: type: string description: URL for MTLS to which an RP can perform a redirect to request that the end user be logged out at the OP. - example: 'https://server.example.com/jans-auth/restv1/mtls/end_session' + example: 'https://server.example.com/jans-auth/restv1/mtls/end_session' mtlsJwksUri: type: string description: URL for MTLS of the OP\'s JSON Web Key Set (JWK) document. - example: 'https://server.example.com/jans-auth/restv1/mtls/jwks' + example: 'https://server.example.com/jans-auth/restv1/mtls/jwks' mtlsRegistrationEndpoint: type: string description: URL for MTLS Registration endpoint. @@ -4325,7 +4360,7 @@ components: mtlsDeviceAuthzEndpoint: type: string description: URL for MTLS Device Authorization endpoint. - example: 'https://server.example.com/jans-auth/restv1/mtls/device_authorization' + example: 'https://server.example.com/jans-auth/restv1/mtls/device_authorization' sessionAsJwt: type: boolean description: Boolean value true saves session data as a JWT. @@ -4398,7 +4433,7 @@ components: type: string enum: - mail - - uid + - uid responseTypesSupported: type: array description: A list of the OAuth 2.0 response_type values that this OP supports. @@ -4443,7 +4478,7 @@ components: description: Default Subject Type used for Dynamic Client Registration. enum: - public - - pairwise + - pairwise authorizationSigningAlgValuesSupported: type: array description: A list of the authorization signing algorithms supported. @@ -4470,9 +4505,9 @@ components: type: string enum: - RSA1_5 - - RSA-OAEP - - A128KW - - A256KW + - RSA-OAEP + - A128KW + - A256KW authorizationEncryptionEncValuesSupported: type: array description: A list of the authorization encryption algorithms supported. @@ -5576,9 +5611,9 @@ components: description: Expiry date of the Scope. type: string format: date - + - + ExtendedScope: allOf: # Combines the Scope and the inline model - $ref: '#/components/schemas/Scope' @@ -5590,7 +5625,7 @@ components: type: array items: $ref: '#/components/schemas/Client' - + CustomAttribute: title: CustomAttribute description: Attribute. @@ -5711,8 +5746,8 @@ components: jansDefaultPromptLogin: description: sets prompt=login to the authorization request, which causes the authorization server to force the user to sign in again before it will show the authorization prompt. type: boolean - - + + Client: title: Client object description: Client. @@ -7688,7 +7723,7 @@ components: codeError: type: string description: Errors in the flow source detected by Agama transpiler - + SessionId: title: Session details description: Session details @@ -7736,7 +7771,7 @@ components: description: Map containing permission. type: object additionalProperties: - type: boolean + type: boolean sessionAttributes: description: Session attributes type: object @@ -7753,4 +7788,3 @@ components: description: Session creation date. type: string format: date - \ No newline at end of file diff --git a/jans-config-api/profiles/default/config-api-test.properties b/jans-config-api/profiles/default/config-api-test.properties index 2e700a452bf..09c6bf12e13 100644 --- a/jans-config-api/profiles/default/config-api-test.properties +++ b/jans-config-api/profiles/default/config-api-test.properties @@ -1,7 +1,7 @@ # The URL of your Jans installation test.server=https://jenkins-config-api.gluu.org -test.scopes=https://jans.io/oauth/config/acrs.readonly https://jans.io/oauth/config/acrs.write https://jans.io/oauth/config/attributes.readonly https://jans.io/oauth/config/attributes.write https://jans.io/oauth/config/attributes.delete https://jans.io/oauth/config/cache.readonly https://jans.io/oauth/config/cache.write https://jans.io/oauth/config/openid/clients.readonly https://jans.io/oauth/config/openid/clients.write https://jans.io/oauth/config/openid/clients.delete https://jans.io/oauth/jans-auth-server/config/properties.readonly https://jans.io/oauth/jans-auth-server/config/properties.write https://jans.io/oauth/config/smtp.readonly https://jans.io/oauth/config/smtp.write https://jans.io/oauth/config/smtp.delete https://jans.io/oauth/config/database/couchbase.readonly https://jans.io/oauth/config/database/couchbase.write https://jans.io/oauth/config/database/couchbase.delete https://jans.io/oauth/config/scripts.readonly https://jans.io/oauth/config/scripts.write https://jans.io/oauth/config/scripts.delete https://jans.io/oauth/config/fido2.readonly https://jans.io/oauth/config/fido2.write https://jans.io/oauth/config/jwks.readonly https://jans.io/oauth/config/jwks.write https://jans.io/oauth/config/database/ldap.readonly https://jans.io/oauth/config/database/ldap.write https://jans.io/oauth/config/database/ldap.delete https://jans.io/oauth/config/logging.readonly https://jans.io/oauth/config/logging.write https://jans.io/oauth/config/scopes.readonly https://jans.io/oauth/config/scopes.write https://jans.io/oauth/config/scopes.delete https://jans.io/oauth/config/uma/resources.readonly https://jans.io/oauth/config/uma/resources.write https://jans.io/oauth/config/uma/resources.delete https://jans.io/oauth/config/database/sql.readonly https://jans.io/oauth/config/database/sql.write https://jans.io/oauth/config/database/sql.delete https://jans.io/oauth/config/stats.readonly jans_stat https://jans.io/scim/users.read https://jans.io/scim/users.write https://jans.io/oauth/config/scim/users.read https://jans.io/oauth/config/scim/users.write https://jans.io/scim/config.readonly https://jans.io/scim/config.write https://jans.io/oauth/config/organization.readonly https://jans.io/oauth/config/organization.write https://jans.io/oauth/config/user.readonly https://jans.io/oauth/config/user.write https://jans.io/oauth/config/user.delete +test.scopes=https://jans.io/oauth/config/acrs.readonly https://jans.io/oauth/config/acrs.write https://jans.io/oauth/config/attributes.readonly https://jans.io/oauth/config/attributes.write https://jans.io/oauth/config/attributes.delete https://jans.io/oauth/config/cache.readonly https://jans.io/oauth/config/cache.write https://jans.io/oauth/config/openid/clients.readonly https://jans.io/oauth/config/openid/clients.write https://jans.io/oauth/config/openid/clients.delete https://jans.io/oauth/jans-auth-server/config/properties.readonly https://jans.io/oauth/jans-auth-server/config/properties.write https://jans.io/oauth/config/smtp.readonly https://jans.io/oauth/config/smtp.write https://jans.io/oauth/config/smtp.delete https://jans.io/oauth/config/database/couchbase.readonly https://jans.io/oauth/config/database/couchbase.write https://jans.io/oauth/config/database/couchbase.delete https://jans.io/oauth/config/scripts.readonly https://jans.io/oauth/config/scripts.write https://jans.io/oauth/config/scripts.delete https://jans.io/oauth/config/fido2.readonly https://jans.io/oauth/config/fido2.write https://jans.io/oauth/config/jwks.readonly https://jans.io/oauth/config/jwks.write https://jans.io/oauth/config/database/ldap.readonly https://jans.io/oauth/config/database/ldap.write https://jans.io/oauth/config/database/ldap.delete https://jans.io/oauth/config/logging.readonly https://jans.io/oauth/config/logging.write https://jans.io/oauth/config/scopes.readonly https://jans.io/oauth/config/scopes.write https://jans.io/oauth/config/scopes.delete https://jans.io/oauth/config/uma/resources.readonly https://jans.io/oauth/config/uma/resources.write https://jans.io/oauth/config/uma/resources.delete https://jans.io/oauth/config/database/sql.readonly https://jans.io/oauth/config/database/sql.write https://jans.io/oauth/config/database/sql.delete https://jans.io/oauth/config/stats.readonly jans_stat https://jans.io/scim/users.read https://jans.io/scim/users.write https://jans.io/oauth/config/scim/users.read https://jans.io/oauth/config/scim/users.write https://jans.io/scim/config.readonly https://jans.io/scim/config.write https://jans.io/oauth/config/organization.readonly https://jans.io/oauth/config/organization.write https://jans.io/oauth/config/user.readonly https://jans.io/oauth/config/user.write https://jans.io/oauth/config/user.delete https://jans.io/oauth/config/agama.readonly https://jans.io/oauth/config/agama.write https://jans.io/oauth/config/agama.delete https://jans.io/oauth/jans-auth-server/session.readonly https://jans.io/oauth/jans-auth-server/session.delete revoke_session token.endpoint=https://jenkins-config-api.gluu.org/jans-auth/restv1/token token.grant.type=client_credentials 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 73ef68c7cd6..10e62f455aa 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 @@ -53,7 +53,7 @@ public class AgamaResource extends ConfigBaseResource { @GET @ProtectedApi(scopes = { ApiAccessConstants.AGAMA_READ_ACCESS }) public Response getFlows(@DefaultValue("") @QueryParam(value = ApiConstants.PATTERN) String pattern, - @DefaultValue(DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit, + @DefaultValue(ApiConstants.DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit, @DefaultValue("false") @QueryParam(value = ApiConstants.INCLUDE_SOURCE) boolean includeSource) { if (logger.isDebugEnabled()) { diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AttributesResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AttributesResource.java index eb3eb43ea76..909a28d7de3 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AttributesResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AttributesResource.java @@ -7,6 +7,8 @@ package io.jans.configapi.rest.resource.auth; import com.github.fge.jsonpatch.JsonPatchException; + +import io.jans.configapi.core.model.SearchRequest; import io.jans.configapi.core.rest.ProtectedApi; import io.jans.configapi.service.auth.AttributeService; import io.jans.configapi.util.ApiAccessConstants; @@ -14,17 +16,19 @@ import io.jans.configapi.util.AttributeNames; import io.jans.configapi.core.util.Jackson; import io.jans.model.GluuAttribute; - +import io.jans.orm.model.PagedResult; import jakarta.inject.Inject; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; + import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.util.Collections; +import java.util.Map; +import org.json.JSONObject; import org.slf4j.Logger; /** @@ -47,33 +51,17 @@ public class AttributesResource extends ConfigBaseResource { @GET @ProtectedApi(scopes = { ApiAccessConstants.ATTRIBUTES_READ_ACCESS }) - public Response getAttributes(@DefaultValue(DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit, + public Response getAttributes(@DefaultValue(ApiConstants.DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit, @DefaultValue("") @QueryParam(value = ApiConstants.PATTERN) String pattern, - @DefaultValue(ApiConstants.ALL) @QueryParam(value = ApiConstants.STATUS) String status) throws Exception { - List attributes = new ArrayList(); - - if (status.equalsIgnoreCase(ApiConstants.ALL)) { - if (!pattern.isEmpty() && pattern.length() >= 2) { - attributes = attributeService.searchAttributes(pattern, limit); - } else { - attributes = attributeService.searchAttributes(limit); - } - } else if (status.equalsIgnoreCase(ApiConstants.ACTIVE)) { - if (!pattern.isEmpty() && pattern.length() >= 2) { - attributes = attributeService.findAttributes(pattern, limit, true); - } else { - attributes = attributeService.searchAttributes(limit, true); - } - - } else if (status.equalsIgnoreCase(ApiConstants.INACTIVE)) { - if (!pattern.isEmpty() && pattern.length() >= 2) { - attributes = attributeService.findAttributes(pattern, limit, false); - } else { - attributes = attributeService.searchAttributes(limit, false); - } - } + @DefaultValue(ApiConstants.ALL) @QueryParam(value = ApiConstants.STATUS) String status, + @DefaultValue(ApiConstants.DEFAULT_LIST_START_INDEX) @QueryParam(value = ApiConstants.START_INDEX) int startIndex, + @DefaultValue(ApiConstants.INUM) @QueryParam(value = ApiConstants.SORT_BY) String sortBy, + @DefaultValue(ApiConstants.ASCENDING) @QueryParam(value = ApiConstants.SORT_ORDER) String sortOrder) { + + SearchRequest searchReq = createSearchRequest(attributeService.getDnForAttribute(null), pattern, sortBy, + sortOrder, startIndex, limit, null, null, this.getMaxCount()); - return Response.ok(attributes).build(); + return Response.ok(doSearch(searchReq, status)).build(); } @GET @@ -88,7 +76,7 @@ public Response getAttributeByInum(@PathParam(ApiConstants.INUM) @NotNull String @POST @ProtectedApi(scopes = { ApiAccessConstants.ATTRIBUTES_WRITE_ACCESS }) public Response createAttribute(@Valid GluuAttribute attribute) { - log.debug(" GluuAttribute details to add - attribute = " + attribute); + log.debug(" GluuAttribute details to add - attribute:{}", attribute); checkNotNull(attribute.getName(), AttributeNames.NAME); checkNotNull(attribute.getDisplayName(), AttributeNames.DISPLAY_NAME); checkResourceNotNull(attribute.getDataType(), AttributeNames.DATA_TYPE); @@ -103,7 +91,7 @@ public Response createAttribute(@Valid GluuAttribute attribute) { @PUT @ProtectedApi(scopes = { ApiAccessConstants.ATTRIBUTES_WRITE_ACCESS }) public Response updateAttribute(@Valid GluuAttribute attribute) { - log.debug(" GluuAttribute details to update - attribute = " + attribute); + log.debug(" GluuAttribute details to update - attribute:{}", attribute); String inum = attribute.getInum(); checkResourceNotNull(inum, GLUU_ATTRIBUTE); checkNotNull(attribute.getName(), AttributeNames.NAME); @@ -124,7 +112,7 @@ public Response updateAttribute(@Valid GluuAttribute attribute) { @Path(ApiConstants.INUM_PATH) public Response patchAtribute(@PathParam(ApiConstants.INUM) @NotNull String inum, @NotNull String pathString) throws JsonPatchException, IOException { - log.debug(" GluuAttribute details to patch - inum = " + inum + " , pathString = " + pathString); + log.debug(" GluuAttribute details to patch - inum:{} , pathString:{}", inum, pathString); GluuAttribute existingAttribute = attributeService.getAttributeByInum(inum); checkResourceNotNull(existingAttribute, GLUU_ATTRIBUTE); @@ -137,11 +125,35 @@ public Response patchAtribute(@PathParam(ApiConstants.INUM) @NotNull String inum @Path(ApiConstants.INUM_PATH) @ProtectedApi(scopes = { ApiAccessConstants.ATTRIBUTES_DELETE_ACCESS }) public Response deleteAttribute(@PathParam(ApiConstants.INUM) @NotNull String inum) { - log.debug(" GluuAttribute details to delete - inum = " + inum); + log.debug(" GluuAttribute details to delete - inum:{}", inum); GluuAttribute attribute = attributeService.getAttributeByInum(inum); checkResourceNotNull(attribute, GLUU_ATTRIBUTE); attributeService.removeAttribute(attribute); return Response.noContent().build(); } + private Map doSearch(SearchRequest searchReq, String status) { + + logger.debug("GluuAttribute search params - searchReq:{} , status:{} ", searchReq, status); + + PagedResult pagedResult = attributeService.searchGluuAttributes(searchReq, status); + + logger.debug("PagedResult - pagedResult:{}", pagedResult); + JSONObject dataJsonObject = new JSONObject(); + if (pagedResult != null) { + logger.debug("GluuAttributes fetched - pagedResult.getTotalEntriesCount():{}, pagedResult.getEntriesCount():{}, pagedResult.getEntries():{}",pagedResult.getTotalEntriesCount(), pagedResult.getEntriesCount(), pagedResult.getEntries()); + dataJsonObject.put(ApiConstants.TOTAL_ITEMS, pagedResult.getTotalEntriesCount()); + dataJsonObject.put(ApiConstants.ENTRIES_COUNT, pagedResult.getEntriesCount()); + dataJsonObject.put(ApiConstants.DATA, pagedResult.getEntries()); + } + else { + dataJsonObject.put(ApiConstants.TOTAL_ITEMS, 0); + dataJsonObject.put(ApiConstants.ENTRIES_COUNT, 0); + dataJsonObject.put(ApiConstants.DATA, Collections.emptyList()); + } + + logger.debug("GluuAttributes fetched new - dataJsonObject:{}, data:{} ", dataJsonObject, dataJsonObject.toMap()); + return dataJsonObject.toMap(); + } + } diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ClientsResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ClientsResource.java index 5bbbe06a1ff..f1ee2f9e0e0 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ClientsResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ClientsResource.java @@ -74,9 +74,9 @@ public class ClientsResource extends ConfigBaseResource { @GET @ProtectedApi(scopes = { ApiAccessConstants.OPENID_CLIENTS_READ_ACCESS }) public Response getOpenIdConnectClients( - @DefaultValue(DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit, + @DefaultValue(ApiConstants.DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit, @DefaultValue("") @QueryParam(value = ApiConstants.PATTERN) String pattern, - @DefaultValue(DEFAULT_LIST_START_INDEX) @QueryParam(value = ApiConstants.START_INDEX) int startIndex, + @DefaultValue(ApiConstants.DEFAULT_LIST_START_INDEX) @QueryParam(value = ApiConstants.START_INDEX) int startIndex, @QueryParam(value = ApiConstants.SORT_BY) String sortBy, @QueryParam(value = ApiConstants.SORT_ORDER) String sortOrder) throws EncryptionException { if (logger.isDebugEnabled()) { diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ConfigBaseResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ConfigBaseResource.java index 42c88dac66b..780156f0e51 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ConfigBaseResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ConfigBaseResource.java @@ -26,19 +26,12 @@ public class ConfigBaseResource extends BaseResource { @Inject ConfigurationFactory configurationFactory; - protected static final String READ_ACCESS = "config-api-read"; - protected static final String WRITE_ACCESS = "config-api-write"; - protected static final String DEFAULT_LIST_SIZE = ApiConstants.DEFAULT_LIST_SIZE; - // Pagination - protected static final String DEFAULT_LIST_START_INDEX = ApiConstants.DEFAULT_LIST_START_INDEX; - protected static final int DEFAULT_MAX_COUNT = ApiConstants.DEFAULT_MAX_COUNT; - protected int getMaxCount() { - logger.trace(" MaxCount details - ApiAppConfiguration.MaxCount():{}, DEFAULT_MAX_COUNT:{} ", - configurationFactory.getApiAppConfiguration().getMaxCount(), DEFAULT_MAX_COUNT); + logger.trace(" MaxCount details - ApiAppConfiguration.MaxCount():{}, ApiConstants.DEFAULT_MAX_COUNT:{} ", + configurationFactory.getApiAppConfiguration().getMaxCount(), ApiConstants.DEFAULT_MAX_COUNT); return (configurationFactory.getApiAppConfiguration().getMaxCount() > 0 ? configurationFactory.getApiAppConfiguration().getMaxCount() - : DEFAULT_MAX_COUNT); + : ApiConstants.DEFAULT_MAX_COUNT); } } diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/CustomScriptResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/CustomScriptResource.java index 94eeb5ccf3e..1a00852165c 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/CustomScriptResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/CustomScriptResource.java @@ -89,7 +89,7 @@ public Response getCustomScriptByName(@PathParam(ApiConstants.NAME) @NotNull Str @ProtectedApi(scopes = { ApiAccessConstants.SCRIPTS_READ_ACCESS }) public Response getCustomScriptsByTypePattern(@PathParam(ApiConstants.TYPE) @NotNull String type, @DefaultValue("") @QueryParam(value = ApiConstants.PATTERN) String pattern, - @DefaultValue(DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit) { + @DefaultValue(ApiConstants.DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit) { if (logger.isDebugEnabled()) { logger.debug("Custom Script to be fetched based on type - type:{} , pattern:{}, limit:{} ", escapeLog(type), escapeLog(pattern), escapeLog(limit)); diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ScopesResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ScopesResource.java index c93176ef8e1..d7429aed5d4 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ScopesResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ScopesResource.java @@ -60,7 +60,7 @@ public class ScopesResource extends ConfigBaseResource { @GET @ProtectedApi(scopes = { ApiAccessConstants.SCOPES_READ_ACCESS }) public Response getScopes(@DefaultValue("") @QueryParam(ApiConstants.TYPE) String type, - @DefaultValue(DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit, + @DefaultValue(ApiConstants.DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit, @DefaultValue("") @QueryParam(value = ApiConstants.PATTERN) String pattern, @DefaultValue("false") @QueryParam(value = ApiConstants.WITH_ASSOCIATED_CLIENTS) boolean withAssociatedClients) { log.debug("SCOPES to be fetched based on type:{}, limit:{}, pattern:{}", type, limit, pattern); diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/UmaResourcesResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/UmaResourcesResource.java index 2e69c22ad42..59746d7a402 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/UmaResourcesResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/UmaResourcesResource.java @@ -49,7 +49,7 @@ public class UmaResourcesResource extends ConfigBaseResource { @GET @ProtectedApi(scopes = { ApiAccessConstants.UMA_RESOURCES_READ_ACCESS }) public Response fetchUmaResources( - @DefaultValue(DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit, + @DefaultValue(ApiConstants.DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit, @DefaultValue("") @QueryParam(value = ApiConstants.PATTERN) String pattern) { logger.debug("UMA_RESOURCE to be fetched - limit:{}, pattern:{}", limit, pattern); final List resources; diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/AttributeService.java b/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/AttributeService.java index 7811aabde98..6d006180a30 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/AttributeService.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/AttributeService.java @@ -1,7 +1,16 @@ package io.jans.configapi.service.auth; +import io.jans.model.GluuAttribute; +import io.jans.as.common.util.AttributeConstants; +import io.jans.configapi.core.model.SearchRequest; +import io.jans.configapi.util.ApiConstants; +import io.jans.orm.PersistenceEntryManager; +import io.jans.orm.model.PagedResult; +import io.jans.orm.model.SortOrder; +import io.jans.orm.search.filter.Filter; import jakarta.enterprise.context.ApplicationScoped; +import org.apache.commons.lang.StringUtils; /** * @author Yuriy Zabrovarnyy @@ -13,4 +22,36 @@ public class AttributeService extends io.jans.as.common.service.AttributeService protected boolean isUseLocalCache() { return false; } + + public PagedResult searchGluuAttributes(SearchRequest searchRequest, String status) { + log.debug("Search GluuAttributes with searchRequest:{}, status:{}", searchRequest, status); + + String[] targetArray = new String[] { searchRequest.getFilter() }; + + Filter activeFilter = null; + if (ApiConstants.ACTIVE.equalsIgnoreCase(status)) { + activeFilter = Filter.createEqualityFilter(AttributeConstants.JANS_STATUS, "active"); + } else if (ApiConstants.INACTIVE.equalsIgnoreCase(status)) { + activeFilter = Filter.createEqualityFilter(AttributeConstants.JANS_STATUS, "inactive"); + } + + Filter displayNameFilter = Filter.createSubstringFilter(AttributeConstants.DISPLAY_NAME, null, targetArray, + null); + Filter descriptionFilter = Filter.createSubstringFilter(AttributeConstants.DESCRIPTION, null, targetArray, + null); + Filter nameFilter = Filter.createSubstringFilter(AttributeConstants.JANS_ATTR_NAME, null, targetArray, null); + Filter searchFilter = Filter.createORFilter(displayNameFilter, descriptionFilter, nameFilter); + + if (activeFilter != null) { + searchFilter = Filter.createORFilter(displayNameFilter, descriptionFilter, nameFilter, activeFilter); + } + + log.debug("Search GluuAttributes with searchFilter:{}", searchFilter); + + return persistenceEntryManager.findPagedEntries(getDnForAttribute(null), GluuAttribute.class, searchFilter, + null, searchRequest.getSortBy(), SortOrder.getByValue(searchRequest.getSortOrder()), + searchRequest.getStartIndex() - 1, searchRequest.getCount(), searchRequest.getMaxCount()); + + } + } \ No newline at end of file