Skip to content

Commit

Permalink
fix(jans-fido2) : #10080 fixed dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
maduvena committed Dec 13, 2024
1 parent e0f55a0 commit 2794182
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
}
}

0 comments on commit 2794182

Please sign in to comment.