Skip to content

Commit

Permalink
Merge pull request #1041 from govuk-one-login/LIME-1276
Browse files Browse the repository at this point in the history
LIME-1276 new inputs for sending context and shared claims as raw JSON
  • Loading branch information
RachelRobGDS authored Oct 18, 2024
2 parents 28aecd9 + ef27ea7 commit 2b4f0c8
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private void initRoutes() throws Exception {
Spark.get("/evidence-request", coreStubHandler.evidenceRequest);
Spark.get("/authorize", coreStubHandler.authorize);
Spark.get("/user-search", coreStubHandler.userSearch);
Spark.post("/user-search", coreStubHandler.sendRawSharedClaim);
Spark.get("/edit-user", coreStubHandler.editUser);
Spark.post("/edit-user", coreStubHandler.updateUser);
Spark.get("/callback", coreStubHandler.doCallback);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package uk.gov.di.ipv.stub.core.config.uatuser;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.time.LocalDate;

@JsonInclude(JsonInclude.Include.NON_NULL)
public record DrivingPermit(
String personalNumber,
String issueNumber,
String issuedBy,
String fullAddress,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate expiryDate,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate issueDate) {}
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ public SharedClaims mapToSharedClaim(Identity identity, boolean agedDOB) {
List.of(new Name(parts)),
List.of(new DateOfBirth(agedDOB ? dateOfBirth.getAgedDOB() : dateOfBirth.getDOB())),
canonicalAddresses,
identity.nino() == null
? null
: List.of(new SocialSecurityRecord(identity.nino())));
identity.nino() == null ? null : List.of(new SocialSecurityRecord(identity.nino())),
null);
}

public PostcodeSharedClaims mapToAddressSharedClaims(String postcode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public record SharedClaims(
@JsonProperty("name") List<Name> name,
@JsonProperty("birthDate") List<DateOfBirth> birthDate,
@JsonProperty("address") List<CanonicalAddress> addresses,
@JsonProperty("socialSecurityRecord") List<SocialSecurityRecord> socialSecurityRecord) {}
@JsonProperty("socialSecurityRecord") List<SocialSecurityRecord> socialSecurityRecord,
@JsonProperty("drivingPermit") List<DrivingPermit> drivingPermit) {}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package uk.gov.di.ipv.stub.core.handlers;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.google.gson.*;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.Payload;
import com.nimbusds.jwt.JWTClaimsSet;
Expand All @@ -19,17 +19,10 @@
import spark.Request;
import spark.Response;
import spark.Route;
import spark.utils.StringUtils;
import uk.gov.di.ipv.stub.core.config.CoreStubConfig;
import uk.gov.di.ipv.stub.core.config.credentialissuer.CredentialIssuer;
import uk.gov.di.ipv.stub.core.config.uatuser.DisplayIdentity;
import uk.gov.di.ipv.stub.core.config.uatuser.EvidenceRequestClaims;
import uk.gov.di.ipv.stub.core.config.uatuser.FindDateOfBirth;
import uk.gov.di.ipv.stub.core.config.uatuser.FullName;
import uk.gov.di.ipv.stub.core.config.uatuser.Identity;
import uk.gov.di.ipv.stub.core.config.uatuser.IdentityMapper;
import uk.gov.di.ipv.stub.core.config.uatuser.PostcodeSharedClaims;
import uk.gov.di.ipv.stub.core.config.uatuser.SharedClaims;
import uk.gov.di.ipv.stub.core.config.uatuser.UKAddress;
import uk.gov.di.ipv.stub.core.config.uatuser.*;
import uk.gov.di.ipv.stub.core.utils.HandlerHelper;
import uk.gov.di.ipv.stub.core.utils.ViewHelper;

Expand Down Expand Up @@ -58,6 +51,7 @@ public class CoreStubHandler {
private final Map<String, CredentialIssuer> stateSession = new HashMap<>();
private HandlerHelper handlerHelper;
private Map<String, String> questionsMap = new HashMap<>();
private ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());

public CoreStubHandler(HandlerHelper handlerHelper) {
this.handlerHelper = handlerHelper;
Expand Down Expand Up @@ -138,6 +132,26 @@ private void setQuestions() {
return ViewHelper.render(modelMap, "search-results.mustache");
};

// Used where sharedClaim is entered as raw JSON string from browser for DL CRI
public Route sendRawSharedClaim =
(Request request, Response response) -> {
var credentialIssuer =
handlerHelper.findCredentialIssuer(
Objects.requireNonNull(request.queryParams("cri")));
String queryString = request.queryParams("claimsText");
// String context = request.queryParams("context");
SharedClaims sharedClaims;
try {
sharedClaims = objectMapper.readValue(queryString, SharedClaims.class);
LOGGER.info("Raw JSON in form input mapped to shared claims");
} catch (Exception e) {
LOGGER.error("Unable to map raw JSON in form input mapped to shared claims");
throw e;
}
sendAuthorizationRequest(request, response, credentialIssuer, sharedClaims);
return null;
};

public Route doCallback =
(Request request, Response response) -> {
var authorizationResponse = handlerHelper.getAuthorizationResponse(request);
Expand Down Expand Up @@ -267,7 +281,7 @@ private void setQuestions() {

private <T> void sendAuthorizationRequest(
Request request, Response response, CredentialIssuer credentialIssuer, T sharedClaims)
throws ParseException, JOSEException {
throws ParseException, JOSEException, JsonProcessingException {
State state = createNewState(credentialIssuer);
request.session().attribute("state", state);
EvidenceRequestClaims evidenceRequest = request.session().attribute("evidence_request");
Expand Down Expand Up @@ -357,17 +371,32 @@ private AuthorizationRequest createBackendAuthorizationRequest(
public Route backendGenerateInitialClaimsSet =
(Request request, Response response) -> {
var credentialIssuerId = Objects.requireNonNull(request.queryParams("cri"));
var rowNumber =
Integer.valueOf(Objects.requireNonNull(request.queryParams("rowNumber")));
// NINO has been added here temporarily for testing implementation of HMRC KBV CRI
var nino = request.queryParams("nino");

var credentialIssuer = handlerHelper.findCredentialIssuer(credentialIssuerId);
var identity = handlerHelper.findIdentityByRowNumber(rowNumber).withNino(nino);
var claimIdentity =
new IdentityMapper()
.mapToSharedClaim(
identity, CoreStubConfig.CORE_STUB_CONFIG_AGED_DOB);

Object claimIdentity;

// claimsText used where sharedClaim is entered as raw JSON string from browser for
// DL CRI
String claimsText = request.queryParams("claimsText");
String context = request.queryParams("context");

if (StringUtils.isEmpty(context)) {
var rowNumber =
Integer.valueOf(
Objects.requireNonNull(request.queryParams("rowNumber")));
// NINO has been added here temporarily for testing implementation of HMRC KBV
// CRI
var nino = request.queryParams("nino");

var identity = handlerHelper.findIdentityByRowNumber(rowNumber).withNino(nino);

claimIdentity =
new IdentityMapper()
.mapToSharedClaim(
identity, CoreStubConfig.CORE_STUB_CONFIG_AGED_DOB);
} else {
claimIdentity = objectMapper.readValue(claimsText, SharedClaims.class);
}

State state = createNewState(credentialIssuer);
LOGGER.info("Created State {} for {}", state.toJSONString(), credentialIssuerId);
Expand All @@ -379,7 +408,8 @@ private AuthorizationRequest createBackendAuthorizationRequest(
credentialIssuer,
new ClientID(CoreStubConfig.CORE_STUB_CLIENT_ID),
claimIdentity,
getEvidenceRequestClaims(request));
getEvidenceRequestClaims(request),
context);
};

private EvidenceRequestClaims getEvidenceRequestClaims(Request request) {
Expand Down Expand Up @@ -418,7 +448,6 @@ private EvidenceRequestClaims getEvidenceRequestClaims(Request request) {

// ClaimSets can go direct to JSON
response.type("application/json");
System.out.println("claimIdentity = " + claimIdentity);
return handlerHelper.createJWTClaimsSets(
state,
credentialIssuerId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,13 @@ public <T> AuthorizationRequest createAuthorizationJAR(
T sharedClaims,
EvidenceRequestClaims evidenceRequest,
String context)
throws JOSEException, java.text.ParseException {
throws JOSEException, java.text.ParseException, JsonProcessingException {
ClientID clientID = new ClientID(CoreStubConfig.CORE_STUB_CLIENT_ID);

JWTClaimsSet claimsSet =
createJWTClaimsSets(
state, credentialIssuer, clientID, sharedClaims, evidenceRequest, context);
// The only difference (frontend/backend) are the ClaimSets are created above
// for the
// The only difference (frontend/backend) are the ClaimSets are created above for the
// frontend and clientID is already set in the backend ClaimSet
LOGGER.info("ClaimsSets generated: {}", claimsSet);
return createBackEndAuthorizationJAR(credentialIssuer, claimsSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,24 @@
Experian UAT test users sheet</a></legend>
<form action="/authorize">
<input type="hidden" name="cri" value="{{cri}}">

<div class="govuk-form-group">
<input class="govuk-input govuk-input--width-3" id="rowNumber" name="rowNumber" type="text"
placeholder="3">
<button class="govuk-button" data-module="govuk-button">Go to {{criName}}</button>
</div>
</form>

<form action="/user-search" method="post">
<input type="hidden" name="cri" value="{{cri}}">
<div class="govuk-form-group">
<legend class="govuk-fieldset__legend govuk-label">Input context value as a string (e.g. check_details) </legend>
<input class="govuk-input govuk-input--width-20" id="context" name="context" type="text">
<legend class="govuk-fieldset__legend govuk-label" style="padding:5px,0,0,0,">Input shared claims raw JSON</legend>
<input class="govuk-input govuk-input--width-20" id="claimsText" name="claimsText" type="text">
<button class="govuk-button" data-module="govuk-button">Go to {{criName}}</button>
</div>
</form>

</main>
</div>

Expand Down

0 comments on commit 2b4f0c8

Please sign in to comment.