diff --git a/jans-config-api/docs/jans-config-api-swagger.yaml b/jans-config-api/docs/jans-config-api-swagger.yaml index fb5cc87adac..330acf30d51 100644 --- a/jans-config-api/docs/jans-config-api-swagger.yaml +++ b/jans-config-api/docs/jans-config-api-swagger.yaml @@ -7644,9 +7644,7 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/SessionId' + $ref: '#/components/schemas/SessionPagedResult' examples: Response json example: description: Response json example @@ -9215,20 +9213,20 @@ components: type: string selected: type: boolean - whitePagesCanView: + userCanView: + type: boolean + adminCanView: type: boolean adminCanEdit: type: boolean userCanEdit: type: boolean - userCanView: - type: boolean - adminCanView: - type: boolean adminCanAccess: type: boolean userCanAccess: type: boolean + whitePagesCanView: + type: boolean baseDn: type: string PatchRequest: @@ -11630,10 +11628,10 @@ components: ttl: type: integer format: int32 - opbrowserState: - type: string persisted: type: boolean + opbrowserState: + type: string SessionIdAccessMap: type: object properties: @@ -11643,6 +11641,22 @@ components: type: boolean xml: name: map + SessionPagedResult: + type: object + properties: + start: + type: integer + format: int32 + totalEntriesCount: + type: integer + format: int32 + entriesCount: + type: integer + format: int32 + entries: + type: array + items: + $ref: '#/components/schemas/SessionId' User: type: object properties: @@ -11701,22 +11715,6 @@ components: type: array items: $ref: '#/components/schemas/UserAuthenticator' - SessionPagedResult: - type: object - properties: - start: - type: integer - format: int32 - totalEntriesCount: - type: integer - format: int32 - entriesCount: - type: integer - format: int32 - entries: - type: array - items: - $ref: '#/components/schemas/SessionId' TokenAttributes: type: object properties: diff --git a/jans-config-api/plugins/docs/fido2-plugin-swagger.yaml b/jans-config-api/plugins/docs/fido2-plugin-swagger.yaml index 05db36f8139..c3ff5dfe6db 100644 --- a/jans-config-api/plugins/docs/fido2-plugin-swagger.yaml +++ b/jans-config-api/plugins/docs/fido2-plugin-swagger.yaml @@ -200,14 +200,17 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/Fido2RegistrationEntry' + $ref: '#/components/schemas/Fido2RegistrationEntryPagedResult' examples: Response example: description: Response example value: | { + "start": 0, + "totalEntriesCount": 3, + "entriesCount": 3, + "entries": [ + { "dn": "jansId=1c88c1cb-8e32-4b79-b244-c9f677ca5654,ou=fido2_register,inum=1e73f801-22c2-4c19-a757-f96a87a5c713,ou=people,o=jans", "id": "1c88c1cb-8e32-4b79-b244-c9f677ca5654", "challange": "2vCSaPMIt4tZpkO8_rDG-v3QoXBYMB1aqCAXFgA4q0Y", @@ -321,6 +324,8 @@ paths: "registrationStatus": "registered", "baseDn": "jansId=6e196a5d-122b-4f06-8ff8-6f41b32bc2a6,ou=fido2_register,inum=1e73f801-22c2-4c19-a757-f96a87a5c713,ou=people,o=jans" } + ] + } "401": description: Unauthorized "500": diff --git a/jans-config-api/plugins/fido2-plugin/src/main/java/io/jans/configapi/plugin/fido2/rest/Fido2RegistrationResource.java b/jans-config-api/plugins/fido2-plugin/src/main/java/io/jans/configapi/plugin/fido2/rest/Fido2RegistrationResource.java index 407965db6d6..dbd2e67b864 100644 --- a/jans-config-api/plugins/fido2-plugin/src/main/java/io/jans/configapi/plugin/fido2/rest/Fido2RegistrationResource.java +++ b/jans-config-api/plugins/fido2-plugin/src/main/java/io/jans/configapi/plugin/fido2/rest/Fido2RegistrationResource.java @@ -15,7 +15,6 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; @@ -28,7 +27,6 @@ import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; -import java.util.List; import org.slf4j.Logger; @@ -106,7 +104,7 @@ public Response getFido2RegistrationEntryById( "Fido2 - Registration" }, security = @SecurityRequirement(name = "oauth2", scopes = { Constants.FIDO2_CONFIG_READ_ACCESS })) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Ok", content = @Content(mediaType = MediaType.APPLICATION_JSON, array = @ArraySchema(schema = @Schema(implementation = Fido2RegistrationEntry.class)), examples = @ExampleObject(name = "Response example", value = "example/fido2/get-all-fido2-data.json"))), + @ApiResponse(responseCode = "200", description = "Ok", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Fido2RegistrationEntryPagedResult.class), examples = @ExampleObject(name = "Response example", value = "example/fido2/search-fido2-registration-data.json"))), @ApiResponse(responseCode = "401", description = "Unauthorized"), @ApiResponse(responseCode = "500", description = "InternalServerError") }) @GET @@ -115,7 +113,8 @@ public Response getFido2RegistrationEntryById( public Response findAllRegisteredByUsername( @Parameter(description = "User name") @PathParam("username") @NotNull String username) { logger.info("FIDO2 registration entries by username."); - List entries = fido2RegistrationService.findAllRegisteredByUsername(username); + checkNotNull(username, "User name"); + PagedResult entries = fido2RegistrationService.getFido2RegisteredByUsername(username); logger.info("FIDO2 registration entries by entries:{}", entries); return Response.ok(entries).build(); } diff --git a/jans-config-api/plugins/fido2-plugin/src/main/java/io/jans/configapi/plugin/fido2/service/Fido2RegistrationService.java b/jans-config-api/plugins/fido2-plugin/src/main/java/io/jans/configapi/plugin/fido2/service/Fido2RegistrationService.java index 9596415dcc3..c70fb57d73b 100644 --- a/jans-config-api/plugins/fido2-plugin/src/main/java/io/jans/configapi/plugin/fido2/service/Fido2RegistrationService.java +++ b/jans-config-api/plugins/fido2-plugin/src/main/java/io/jans/configapi/plugin/fido2/service/Fido2RegistrationService.java @@ -11,6 +11,7 @@ import io.jans.as.model.config.StaticConfiguration; import io.jans.configapi.configuration.ConfigurationFactory; import io.jans.configapi.core.util.DataUtil; +import io.jans.configapi.plugin.fido2.util.Constants; import io.jans.configapi.util.ApiConstants; import io.jans.model.SearchRequest; import io.jans.orm.PersistenceEntryManager; @@ -41,6 +42,9 @@ @ApplicationScoped public class Fido2RegistrationService { + private static final String JANS_STATUS = "jansStatus"; + private static final String PERSON_INUM = "personInum"; + @Inject private Logger log; @@ -93,11 +97,11 @@ public PagedResult searchFido2Registration(SearchRequest Filter displayNameFilter = Filter.createSubstringFilter("displayName", null, targetArray, null); Filter descriptionFilter = Filter.createSubstringFilter("jansRegistrationData", null, targetArray, null); - Filter statusFilter = Filter.createSubstringFilter("jansStatus", null, targetArray, null); + Filter statusFilter = Filter.createSubstringFilter(JANS_STATUS, null, targetArray, null); Filter notificationConfFilter = Filter.createSubstringFilter("jansDeviceNotificationConf", null, targetArray, null); Filter deviceDataFilter = Filter.createSubstringFilter("jansDeviceData", null, targetArray, null); - Filter personInumFilter = Filter.createSubstringFilter("personInum", null, targetArray, null); + Filter personInumFilter = Filter.createSubstringFilter(PERSON_INUM, null, targetArray, null); Filter inumFilter = Filter.createSubstringFilter("jansId", null, targetArray, null); filters.add(Filter.createORFilter(displayNameFilter, descriptionFilter, statusFilter, @@ -115,7 +119,8 @@ public PagedResult searchFido2Registration(SearchRequest getDnFido2RegistrationEntry(null), persistenceEntryManager); } - fieldValueFilters.add(Filter.createORFilter(filters)); + searchFilter = Filter.createANDFilter(Filter.createORFilter(filters), + Filter.createANDFilter(fieldValueFilters)); log.info(" Final - Fido2Registration searchFilter:{}", searchFilter); @@ -142,11 +147,41 @@ public List findAllRegisteredByUsername(String username) return Collections.emptyList(); } - Filter searchFilter = Filter.createANDFilter(Filter.createEqualityFilter("personInum", userInum), - Filter.createEqualityFilter("jansStatus", Fido2RegistrationStatus.registered.getValue())); + Filter searchFilter = Filter.createANDFilter(Filter.createEqualityFilter(PERSON_INUM, userInum), + Filter.createEqualityFilter(JANS_STATUS, Fido2RegistrationStatus.registered.getValue())); + + log.info("Fido2 Registered by searchFilter:{}", searchFilter); + return persistenceEntryManager.findEntries(getDnFido2RegistrationEntry(baseDn), Fido2RegistrationEntry.class, + searchFilter); + } + + public PagedResult getFido2RegisteredByUsername(String username) { + if (log.isInfoEnabled()) { + log.info("Fetch Fido2 Registered by username:{}", escapeLog(username)); + } + PagedResult fido2RegistrationEntry = null; + String userInum = userFido2Srv.getUserInum(username); + log.info("Find Fido2 Registered by userInum:{}", userInum); + if (userInum == null) { + return fido2RegistrationEntry; + } + + String baseDn = getBaseDnForFido2RegistrationEntries(userInum); + log.info("Find Fido2 Registered by baseDn:{}", baseDn); + if (persistenceEntryManager.hasBranchesSupport(baseDn) && !containsBranch(baseDn)) { + return fido2RegistrationEntry; + } + + Filter searchFilter = Filter.createANDFilter(Filter.createEqualityFilter(PERSON_INUM, userInum), + Filter.createEqualityFilter(JANS_STATUS, Fido2RegistrationStatus.registered.getValue())); + + log.info("Fido2 Registered by searchFilter:{}", searchFilter); + + return persistenceEntryManager.findPagedEntries(getDnFido2RegistrationEntry(baseDn), + Fido2RegistrationEntry.class, searchFilter, null, Constants.JANSID, SortOrder.ASCENDING, + Integer.parseInt(ApiConstants.DEFAULT_LIST_START_INDEX), + Integer.parseInt(ApiConstants.DEFAULT_LIST_SIZE), getRecordMaxCount()); - log.info("Find Fido2 Registered by searchFilter:{}", searchFilter); - return persistenceEntryManager.findEntries(getDnFido2RegistrationEntry(null), Fido2RegistrationEntry.class, searchFilter); } public String getBaseDnForFido2RegistrationEntries(String userInum) { diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/SessionResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/SessionResource.java index ee725e0ac22..f00012b955a 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/SessionResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/SessionResource.java @@ -15,7 +15,6 @@ import io.jans.orm.model.PagedResult; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; @@ -53,16 +52,22 @@ private class SessionPagedResult extends PagedResult { "Auth - Session Management" }, security = @SecurityRequirement(name = "oauth2", scopes = { ApiAccessConstants.JANS_AUTH_SESSION_READ_ACCESS, "revoke_session" })) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Ok", content = @Content(mediaType = MediaType.APPLICATION_JSON, array = @ArraySchema(schema = @Schema(implementation = SessionId.class)), examples = @ExampleObject(name = "Response json example", value = "example/session/get-session.json"))), + @ApiResponse(responseCode = "200", description = "Ok", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = SessionPagedResult.class), examples = @ExampleObject(name = "Response json example", value = "example/session/get-session.json"))), @ApiResponse(responseCode = "401", description = "Unauthorized"), @ApiResponse(responseCode = "500", description = "InternalServerError") }) @GET @ProtectedApi(scopes = { ApiAccessConstants.JANS_AUTH_SESSION_READ_ACCESS }, groupScopes = {}, superScopes = { ApiAccessConstants.SUPER_ADMIN_READ_ACCESS }) public Response getAllSessions() { - final List sessions = sessionService.getSessions(); - logger.debug("sessions:{}", sessions); - return Response.ok(sessions).build(); + + SearchRequest searchReq = createSearchRequest(sessionService.getDnForSession(null), null, ApiConstants.JANSID, + ApiConstants.ASCENDING, Integer.parseInt(ApiConstants.DEFAULT_LIST_START_INDEX), + Integer.parseInt(ApiConstants.DEFAULT_LIST_SIZE), null, null, this.getMaxCount(), null, + SessionId.class); + + SessionPagedResult sessionPagedResult = searchSession(searchReq); + logger.info("Session fetched sessionPagedResult:{}", sessionPagedResult); + return Response.ok(sessionPagedResult).build(); } @Operation(summary = "Search session", description = "Search session", operationId = "search-session", tags = { diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/TokenResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/TokenResource.java index 153e7145dac..e1993cd33b5 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/TokenResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/TokenResource.java @@ -44,6 +44,8 @@ public class TokenResource extends ConfigBaseResource { private class TokenEntityPagedResult extends PagedResult { }; + private static final String TOKEN_NOT_FOUND = "Token identified by %s not found."; + @Inject TokenService tokenService; @@ -71,7 +73,9 @@ public Response getTokenById( checkNotNull(tknCde, ApiConstants.TOKEN_CODE); TokenEntity tokenEntity = this.tokenService.getTokenEntityByCode(tknCde); - + if (tokenEntity == null) { + throwNotFoundException("Not Found", String.format(TOKEN_NOT_FOUND, tknCde)); + } logger.info("Token fetched tokenEntity:{}", tokenEntity); return Response.ok(tokenEntity).build(); diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/SessionService.java b/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/SessionService.java index 021ee8256ca..cfd622f922a 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/SessionService.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/SessionService.java @@ -40,7 +40,8 @@ public class SessionService { private static final String SID_MSG = "Get Session by sid:{}"; private static final String SID_ERROR = "Failed to load session entry with sid "; - private static final List SESSION_ATTR = Arrays.asList("acr","scope","auth_user","client_id","acr_values","redirect_uri","response_type"); + private static final List SESSION_ATTR = Arrays.asList("acr", "scope", "auth_user", "client_id", + "acr_values", "redirect_uri", "response_type"); @Inject private Logger logger; @@ -149,8 +150,8 @@ public PagedResult searchSession(SearchRequest searchRequest) { persistenceEntryManager); } - fieldValueFilters.add(Filter.createORFilter(filters)); - searchFilter = Filter.createANDFilter(fieldValueFilters); + searchFilter = Filter.createANDFilter(Filter.createORFilter(filters), + Filter.createANDFilter(fieldValueFilters)); logger.info("Session searchFilter:{}", searchFilter); @@ -299,14 +300,14 @@ private List modifyFilter(List fieldFilterData for (FieldFilterData fieldFilterData : fieldFilterDataList) { if (fieldFilterData != null && StringUtils.isNotBlank(fieldFilterData.getField())) { String field = fieldFilterData.getField(); - if(StringUtils.isBlank(field)) { + if (StringUtils.isBlank(field)) { continue; } if ("jansUsrDN".equalsIgnoreCase(field)) { // get Dn fieldFilterData.setValue(getDnForUser(fieldFilterData.getValue())); - }else if(SESSION_ATTR.contains(field)) { - fieldFilterData.setField("jansSessAttr."+field); + } else if (SESSION_ATTR.contains(field)) { + fieldFilterData.setField("jansSessAttr." + field); } } } diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/TokenService.java b/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/TokenService.java index be0e58866dc..8bd7a93c140 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/TokenService.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/TokenService.java @@ -62,6 +62,7 @@ public TokenEntity getTokenEntityByCode(String tknCde) { tokenEntity = persistenceEntryManager.find(TokenEntity.class, getDnForTokenEntity(tknCde)); } catch (Exception ex) { logger.error("Failed to get Token identified by tknCde:{" + tknCde + "}", ex); + return tokenEntity; } return tokenEntity; }