From 27941822c28b911933cf0d04733633ae8bdee60b Mon Sep 17 00:00:00 2001 From: Madhumita Subramaniam Date: Fri, 13 Dec 2024 15:25:39 +0530 Subject: [PATCH] fix(jans-fido2) : #10080 fixed dependencies --- .../service/operation/AssertionService.java | 8 +- .../AuthenticationPersistenceService.java | 2 +- .../service/verifier/CommonVerifiers.java | 2 +- .../ws/rs/controller/AssertionController.java | 4 +- .../rs/controller/AttestationController.java | 142 +++++++++--------- 5 files changed, 74 insertions(+), 84 deletions(-) diff --git a/jans-fido2/server/src/main/java/io/jans/fido2/service/operation/AssertionService.java b/jans-fido2/server/src/main/java/io/jans/fido2/service/operation/AssertionService.java index c0cd62b28bb..7503bb0814c 100644 --- a/jans-fido2/server/src/main/java/io/jans/fido2/service/operation/AssertionService.java +++ b/jans-fido2/server/src/main/java/io/jans/fido2/service/operation/AssertionService.java @@ -7,24 +7,18 @@ package io.jans.fido2.service.operation; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.base.Strings; -import io.jans.entry.PublicKeyCredentialHints; -import io.jans.entry.Transports; -import io.jans.fido2.ctap.AttestationFormat; -import io.jans.fido2.ctap.AuthenticatorAttachment; import io.jans.fido2.exception.Fido2CompromisedDevice; import io.jans.fido2.exception.Fido2RuntimeException; import io.jans.fido2.model.assertion.AsserOptGenerateResponse; diff --git a/jans-fido2/server/src/main/java/io/jans/fido2/service/persist/AuthenticationPersistenceService.java b/jans-fido2/server/src/main/java/io/jans/fido2/service/persist/AuthenticationPersistenceService.java index 30b8dcbd3ca..4259b277546 100644 --- a/jans-fido2/server/src/main/java/io/jans/fido2/service/persist/AuthenticationPersistenceService.java +++ b/jans-fido2/server/src/main/java/io/jans/fido2/service/persist/AuthenticationPersistenceService.java @@ -15,7 +15,7 @@ import io.jans.fido2.model.assertion.AssertionErrorResponseType; import io.jans.fido2.model.attestation.AttestationErrorResponseType; import io.jans.fido2.model.error.ErrorResponseFactory; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import io.jans.as.common.model.common.User; diff --git a/jans-fido2/server/src/main/java/io/jans/fido2/service/verifier/CommonVerifiers.java b/jans-fido2/server/src/main/java/io/jans/fido2/service/verifier/CommonVerifiers.java index 833e7874151..a4c0ca2d86c 100644 --- a/jans-fido2/server/src/main/java/io/jans/fido2/service/verifier/CommonVerifiers.java +++ b/jans-fido2/server/src/main/java/io/jans/fido2/service/verifier/CommonVerifiers.java @@ -14,7 +14,7 @@ import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import com.fasterxml.jackson.databind.JsonNode; diff --git a/jans-fido2/server/src/main/java/io/jans/fido2/ws/rs/controller/AssertionController.java b/jans-fido2/server/src/main/java/io/jans/fido2/ws/rs/controller/AssertionController.java index 31d7ba243da..c8a3d61832a 100644 --- a/jans-fido2/server/src/main/java/io/jans/fido2/ws/rs/controller/AssertionController.java +++ b/jans-fido2/server/src/main/java/io/jans/fido2/ws/rs/controller/AssertionController.java @@ -13,7 +13,7 @@ import io.jans.fido2.model.error.ErrorResponseFactory; import io.jans.fido2.service.DataMapperService; import io.jans.fido2.service.operation.AssertionService; - +import jakarta.validation.constraints.NotNull; import io.jans.fido2.service.util.CommonUtilService; import io.jans.fido2.service.verifier.CommonVerifiers; import jakarta.enterprise.context.ApplicationScoped; @@ -22,7 +22,7 @@ import jakarta.ws.rs.core.Response; import org.slf4j.Logger; -import javax.validation.constraints.NotNull; + /** * serves request for /assertion endpoint exposed by FIDO2 sever diff --git a/jans-fido2/server/src/main/java/io/jans/fido2/ws/rs/controller/AttestationController.java b/jans-fido2/server/src/main/java/io/jans/fido2/ws/rs/controller/AttestationController.java index fba1e23434b..27c231b3c21 100644 --- a/jans-fido2/server/src/main/java/io/jans/fido2/ws/rs/controller/AttestationController.java +++ b/jans-fido2/server/src/main/java/io/jans/fido2/ws/rs/controller/AttestationController.java @@ -6,7 +6,8 @@ package io.jans.fido2.ws.rs.controller; -import com.fasterxml.jackson.databind.JsonNode; +import org.slf4j.Logger; + import io.jans.fido2.model.attestation.AttestationOptions; import io.jans.fido2.model.attestation.AttestationResult; import io.jans.fido2.model.attestation.PublicKeyCredentialCreationOptions; @@ -15,17 +16,16 @@ import io.jans.fido2.model.error.ErrorResponseFactory; import io.jans.fido2.service.DataMapperService; import io.jans.fido2.service.operation.AttestationService; -import io.jans.fido2.service.util.CommonUtilService; import io.jans.fido2.service.verifier.CommonVerifiers; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.ws.rs.*; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.core.Response.ResponseBuilder; -import org.slf4j.Logger; - -import javax.validation.constraints.NotNull; -import java.io.IOException; /** * serves request for /attestation endpoint exposed by FIDO2 sever @@ -37,69 +37,65 @@ @Path("/attestation") public class AttestationController { - @Inject - private Logger log; - - @Inject - private AttestationService attestationService; - - @Inject - private DataMapperService dataMapperService; - - @Inject - private CommonVerifiers commonVerifiers; - - @Inject - private AppConfiguration appConfiguration; - - @Inject - private ErrorResponseFactory errorResponseFactory; - - @POST - @Consumes({"application/json"}) - @Produces({"application/json"}) - @Path("/options") - public Response register(@NotNull AttestationOptions attestationOptions) { - return processRequest(() -> { - if (appConfiguration.getFido2Configuration() == null) { - throw errorResponseFactory.forbiddenException(); - } - PublicKeyCredentialCreationOptions result = attestationService.options(attestationOptions); - return Response.ok().entity(result).build(); - }); - } - - @POST - @Consumes({"application/json"}) - @Produces({"application/json"}) - @Path("/result") - public Response verify(@NotNull AttestationResult attestationResult) { - return processRequest(() -> { - if (appConfiguration.getFido2Configuration() == null) { - throw errorResponseFactory.forbiddenException(); - } - AttestationOrAssertionResponse result = attestationService.verify(attestationResult); - return Response.ok().entity(result).build(); - }); - } - - - - - - private Response processRequest(RequestProcessor processor) { - try { - return processor.process(); - } catch (WebApplicationException e) { - throw e; - } catch (Exception e) { - log.error("Unknown Error: {}", e.getMessage(), e); - throw errorResponseFactory.unknownError(e.getMessage()); - } - } - - @FunctionalInterface - private interface RequestProcessor { - Response process() throws Exception; - } + @Inject + private Logger log; + + @Inject + private AttestationService attestationService; + + @Inject + private DataMapperService dataMapperService; + + @Inject + private CommonVerifiers commonVerifiers; + + @Inject + private AppConfiguration appConfiguration; + + @Inject + private ErrorResponseFactory errorResponseFactory; + + @POST + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + @Path("/options") + public Response register(@NotNull AttestationOptions attestationOptions) { + return processRequest(() -> { + if (appConfiguration.getFido2Configuration() == null) { + throw errorResponseFactory.forbiddenException(); + } + PublicKeyCredentialCreationOptions result = attestationService.options(attestationOptions); + return Response.ok().entity(result).build(); + }); + } + + @POST + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + @Path("/result") + public Response verify(@NotNull AttestationResult attestationResult) { + return processRequest(() -> { + if (appConfiguration.getFido2Configuration() == null) { + throw errorResponseFactory.forbiddenException(); + } + AttestationOrAssertionResponse result = attestationService.verify(attestationResult); + return Response.ok().entity(result).build(); + }); + } + + private Response processRequest(RequestProcessor processor) { + try { + return processor.process(); + } catch (WebApplicationException e) { + throw e; + } catch (Exception e) { + log.error("Unknown Error: {}", e.getMessage(), e); + throw errorResponseFactory.unknownError(e.getMessage()); + } + } + + @FunctionalInterface + private interface RequestProcessor { + Response process() throws Exception; + } }