From 5790fc7751f53934c45d058854e80641f49f245b Mon Sep 17 00:00:00 2001 From: Mirko Stojmenovic <58424206+mirkostojmenovic-frejaeid@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:06:32 +0200 Subject: [PATCH 1/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e9a8fa..183d6f9 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ To add a dependency on Freja eID Client using Maven, use the following: com.verisec.frejaeid FrejaEidClient - 2.22.0 + 2.25.0 ``` From ba424e25cba727229cc008897d188b9a5fff58b0 Mon Sep 17 00:00:00 2001 From: Mirko Stojmenovic Date: Wed, 23 Oct 2024 16:42:15 +0200 Subject: [PATCH 2/2] Added support for OriginDeviceDetails and Freja Cookie --- FrejaEidClient/pom.xml | 2 +- .../get/AuthenticationResult.java | 8 +- .../init/InitiateAuthenticationRequest.java | 37 ++++--- ...InitiateAuthenticationRequestBuilders.java | 53 +++++---- .../frejaeid/client/beans/common/Result.java | 32 +++++- .../beans/general/OriginDeviceDetails.java | 103 ++++++++++++++++++ .../beans/general/RequestedAttributes.java | 1 - .../get/OrganisationIdResult.java | 8 +- .../client/beans/sign/get/SignResult.java | 8 +- .../beans/sign/init/InitiateSignRequest.java | 20 +++- .../init/InitiateSignRequestBuilders.java | 18 ++- ...iateAuthenticationRequestBuildersTest.java | 41 +++++-- .../init/InitiateSignRequestBuildersTest.java | 52 ++++++--- .../AuthenticationClientGetResultTest.java | 31 ++++-- .../OrganisationIdClientGetResultTest.java | 44 +++++--- .../client/impl/SignClientGetResultTest.java | 37 +++++-- .../http/AuthenticationClientHttpTest.java | 5 +- .../frejaeid/client/http/CommonHttpTest.java | 1 + .../http/OrganisationIdClientHttpTest.java | 2 +- .../client/http/SignClientHttpTest.java | 4 +- 20 files changed, 377 insertions(+), 130 deletions(-) create mode 100644 FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/OriginDeviceDetails.java diff --git a/FrejaEidClient/pom.xml b/FrejaEidClient/pom.xml index 029071c..2cc6d7d 100644 --- a/FrejaEidClient/pom.xml +++ b/FrejaEidClient/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.verisec.frejaeid FrejaEidClient - 2.25.1-SNAPSHOT + 2.26.0-SNAPSHOT jar FrejaEidClient diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/authentication/get/AuthenticationResult.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/authentication/get/AuthenticationResult.java index 56807e7..dbfa441 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/authentication/get/AuthenticationResult.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/authentication/get/AuthenticationResult.java @@ -7,8 +7,7 @@ import com.verisec.frejaeid.client.enums.TransactionStatus; /** - * Contains transaction reference, transaction status, details and requested - * attributes. + * Contains transaction reference, transaction status, details, requested attributes and freja cookie. */ public class AuthenticationResult extends Result { @@ -16,8 +15,9 @@ public class AuthenticationResult extends Result { public AuthenticationResult(@JsonProperty(value = "authRef") String reference, @JsonProperty(value = "status") TransactionStatus status, @JsonProperty(value = "details") String details, - @JsonProperty(value = "requestedAttributes") RequestedAttributes requestedAttributes) { - super(reference, status, details, requestedAttributes); + @JsonProperty(value = "requestedAttributes") RequestedAttributes requestedAttributes, + @JsonProperty(value = "frejaCookie") String frejaCookie) { + super(reference, status, details, requestedAttributes, frejaCookie); } /** diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/authentication/init/InitiateAuthenticationRequest.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/authentication/init/InitiateAuthenticationRequest.java index a0725e9..bf32489 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/authentication/init/InitiateAuthenticationRequest.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/authentication/init/InitiateAuthenticationRequest.java @@ -6,6 +6,7 @@ import com.verisec.frejaeid.client.beans.authentication.init.InitiateAuthenticationRequestBuilders.UserInfoBuilder; import com.verisec.frejaeid.client.beans.common.RelyingPartyRequest; import com.verisec.frejaeid.client.beans.general.AttributeToReturnInfo; +import com.verisec.frejaeid.client.beans.general.OriginDeviceDetails; import com.verisec.frejaeid.client.beans.general.SsnUserInfo; import com.verisec.frejaeid.client.enums.MinRegistrationLevel; import com.verisec.frejaeid.client.enums.UserConfirmationMethod; @@ -25,6 +26,7 @@ public class InitiateAuthenticationRequest implements RelyingPartyRequest { private final String relyingPartyId; private final String orgIdIssuer; private final UserConfirmationMethod userConfirmationMethod; + private final OriginDeviceDetails originDeviceDetails; /** * Returns instance of {@linkplain InitiateAuthenticationRequest} with: @@ -73,14 +75,17 @@ private InitiateAuthenticationRequest( @JsonProperty(value = "minRegistrationLevel") MinRegistrationLevel minRegistrationLevel, @JsonProperty(value = "attributesToReturn") Set attributesToReturn, @JsonProperty(value = "orgIdIssuer") String orgIdIssuer, - @JsonProperty(value = "userConfirmationMethod") UserConfirmationMethod userConfirmationMethod) { - this(userInfoType, userInfo, minRegistrationLevel, attributesToReturn, null, orgIdIssuer, userConfirmationMethod); + @JsonProperty(value = "userConfirmationMethod") UserConfirmationMethod userConfirmationMethod, + @JsonProperty(value = "originDeviceDetails") OriginDeviceDetails originDeviceDetails) { + this(userInfoType, userInfo, minRegistrationLevel, attributesToReturn, null, orgIdIssuer, + userConfirmationMethod, originDeviceDetails); } InitiateAuthenticationRequest( UserInfoType userInfoType, String userInfo, MinRegistrationLevel minRegistrationLevel, Set attributesToReturn, String relyingPartyId, - String orgIdIssuer, UserConfirmationMethod userConfirmationMethod) { + String orgIdIssuer, UserConfirmationMethod userConfirmationMethod, + OriginDeviceDetails originDeviceDetails) { this.userInfoType = userInfoType; this.userInfo = userInfo; this.minRegistrationLevel = minRegistrationLevel; @@ -88,6 +93,8 @@ private InitiateAuthenticationRequest( this.relyingPartyId = relyingPartyId; this.orgIdIssuer = orgIdIssuer; this.userConfirmationMethod = userConfirmationMethod; + this.originDeviceDetails = originDeviceDetails; + } @JsonIgnore @@ -119,10 +126,14 @@ public UserConfirmationMethod getUserConfirmationMethod() { return userConfirmationMethod; } + public OriginDeviceDetails getOriginDeviceDetails() { + return originDeviceDetails; + } + @Override public int hashCode() { return Objects.hash(userInfoType, userInfo, minRegistrationLevel, attributesToReturn, relyingPartyId, - orgIdIssuer, userConfirmationMethod); + orgIdIssuer, userConfirmationMethod, originDeviceDetails); } @Override @@ -165,19 +176,19 @@ public boolean equals(Object obj) { if (this.userConfirmationMethod != other.userConfirmationMethod) { return false; } + if (!Objects.equals(this.originDeviceDetails, other.originDeviceDetails)) { + return false; + } return true; } @Override public String toString() { - return "InitiateAuthenticationRequest{" + - "userInfoType=" + userInfoType + - ", userInfo='" + userInfo + '\'' + - ", minRegistrationLevel=" + minRegistrationLevel + - ", attributesToReturn=" + attributesToReturn + - ", relyingPartyId='" + relyingPartyId + '\'' + - ", orgIdIssuer='" + orgIdIssuer + '\'' + - ", userConfirmationMethod=" + userConfirmationMethod + - '}'; + return "InitiateAuthenticationRequest{" + "userInfoType=" + userInfoType + ", userInfo='" + userInfo + '\'' + + ", minRegistrationLevel=" + minRegistrationLevel + ", attributesToReturn=" + attributesToReturn + + ", relyingPartyId='" + relyingPartyId + '\'' + ", orgIdIssuer='" + orgIdIssuer + '\'' + + ", userConfirmationMethod=" + userConfirmationMethod + + ", originDeviceDetails=" + originDeviceDetails + + '}'; } } diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/authentication/init/InitiateAuthenticationRequestBuilders.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/authentication/init/InitiateAuthenticationRequestBuilders.java index 8ed012b..1d18d7e 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/authentication/init/InitiateAuthenticationRequestBuilders.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/authentication/init/InitiateAuthenticationRequestBuilders.java @@ -1,6 +1,7 @@ package com.verisec.frejaeid.client.beans.authentication.init; import com.verisec.frejaeid.client.beans.general.AttributeToReturnInfo; +import com.verisec.frejaeid.client.beans.general.OriginDeviceDetails; import com.verisec.frejaeid.client.beans.general.SsnUserInfo; import com.verisec.frejaeid.client.enums.*; import com.verisec.frejaeid.client.exceptions.FrejaEidClientInternalException; @@ -14,11 +15,10 @@ public class InitiateAuthenticationRequestBuilders { public static class UserInfoBuilder { /** - * Sets email as userInfo and {@linkplain UserInfoType#EMAIL} as - * {@linkplain UserInfoType} for initiating transaction. + * Sets email as userInfo and {@linkplain UserInfoType#EMAIL} as {@linkplain UserInfoType} for initiating + * transaction. * - * @param email user's email that will be used to identify the end user. - * Maximum length is 256 characters. + * @param email user's email that will be used to identify the end user. Maximum length is 256 characters. * @return request builder */ public SetOptionalParamsBuilder setEmail(String email) { @@ -26,26 +26,23 @@ public SetOptionalParamsBuilder setEmail(String email) { } /** - * Sets ssnUserInfo as userInfo and {@linkplain UserInfoType#SSN} as - * {@linkplain UserInfoType} for initiating transaction. + * Sets ssnUserInfo as userInfo and {@linkplain UserInfoType#SSN} as {@linkplain UserInfoType} for initiating + * transaction. * - * @param ssnUserInfo instance {@linkplain SsnUserInfo} that contains - * personal number and country of user that will be used to identify the - * end user. + * @param ssnUserInfo instance {@linkplain SsnUserInfo} that contains personal number and country of user that + * will be used to identify the end user. * @return request builder - * @throws FrejaEidClientInternalException if error occurs when - * generating JSON content from ssnUserInfo + * @throws FrejaEidClientInternalException if error occurs when generating JSON content from ssnUserInfo */ public SetOptionalParamsBuilder setSsn(SsnUserInfo ssnUserInfo) throws FrejaEidClientInternalException { return new SetOptionalParamsBuilder(UserInfoType.SSN, UserInfoUtil.convertSsnUserInfo(ssnUserInfo)); } /** - * Sets phoneNumber as userInfo and {@link UserInfoType#PHONE} as - * {@linkplain UserInfoType} for initiating transaction. + * Sets phoneNumber as userInfo and {@link UserInfoType#PHONE} as {@linkplain UserInfoType} for initiating + * transaction. * - * @param phoneNumber user's phone number that will be used to identify - * the end user in format +467123456789. + * @param phoneNumber user's phone number that will be used to identify the end user in format +467123456789. * @return request builder */ public SetOptionalParamsBuilder setPhoneNumber(String phoneNumber) { @@ -53,8 +50,7 @@ public SetOptionalParamsBuilder setPhoneNumber(String phoneNumber) { } /** - * Sets {@linkplain UserInfoType#INFERRED} as {@linkplain UserInfoType} - * for initiating transaction. + * Sets {@linkplain UserInfoType#INFERRED} as {@linkplain UserInfoType} for initiating transaction. * * @return request builder */ @@ -63,11 +59,10 @@ public SetOptionalParamsBuilder setInferred() { } /** - * Sets organisation id as userInfo and {@link UserInfoType#ORG_ID} as - * {@linkplain UserInfoType} for initiating transaction. + * Sets organisation id as userInfo and {@link UserInfoType#ORG_ID} as {@linkplain UserInfoType} for initiating + * transaction. * - * @param identifier user's identifier that was previously set by - * organisation + * @param identifier user's identifier that was previously set by organisation * @return request builder */ public SetOptionalParamsBuilder setOrganisationId(String identifier) { @@ -85,6 +80,7 @@ public static class SetOptionalParamsBuilder { private String relyingPartyId = null; private String orgIdIssuer = null; private UserConfirmationMethod userConfirmationMethod = null; + private OriginDeviceDetails originDeviceDetails = null; private SetOptionalParamsBuilder(UserInfoType userInfoType, String userInfo) { this.userInfoType = userInfoType; @@ -165,9 +161,22 @@ public SetOptionalParamsBuilder setUserConfirmationMethod(UserConfirmationMethod return this; } + /** + * OriginDeviceDetails contains information about the end user device from which the transaction was + * initiated. + * + * @param originDeviceDetails information about the end user device + * @return request builder + */ + public SetOptionalParamsBuilder setOriginDeviceDetails(OriginDeviceDetails originDeviceDetails) { + this.originDeviceDetails = originDeviceDetails; + return this; + } + public InitiateAuthenticationRequest build() { return new InitiateAuthenticationRequest(userInfoType, userInfo, minRegistrationLevel, attributesToReturn, - relyingPartyId, orgIdIssuer, userConfirmationMethod); + relyingPartyId, orgIdIssuer, userConfirmationMethod, + originDeviceDetails); } } diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/common/Result.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/common/Result.java index 7502860..0b2238d 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/common/Result.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/common/Result.java @@ -15,16 +15,19 @@ public abstract class Result implements FrejaHttpResponse { private final TransactionStatus status; private final String details; private final RequestedAttributes requestedAttributes; + private final String frejaCookie; @JsonCreator public Result(String reference, @JsonProperty(value = "status") TransactionStatus status, @JsonProperty(value = "details") String details, - @JsonProperty(value = "requestedAttributes") RequestedAttributes requestedAttributes) { + @JsonProperty(value = "requestedAttributes") RequestedAttributes requestedAttributes, + @JsonProperty(value = "frejaCookie") String frejaCookie) { this.reference = reference; this.status = status; this.details = details; this.requestedAttributes = requestedAttributes; + this.frejaCookie = frejaCookie; } public String getReference() { @@ -59,9 +62,21 @@ public RequestedAttributes getRequestedAttributes() { return requestedAttributes; } + /** + * + * @return Cookie to be set in end-user browser. + * Each time an initAuthentication is called, the cookie obtained through + * "Cookie" header of the HTTP request shall be passed to Freja's REST API. + * After transaction is confirmed, a new cookie is received from Freja API, + * and shall be forwarded to end-user browser via the "Set-Cookie" HTTP header. + */ + public String getFrejaCookie() { + return frejaCookie; + } + @Override public int hashCode() { - return Objects.hash(reference, status, details, requestedAttributes); + return Objects.hash(reference, status, details, requestedAttributes, frejaCookie); } @Override @@ -82,13 +97,20 @@ public boolean equals(Object obj) { if (!Objects.equals(this.details, other.details)) { return false; } - return Objects.equals(this.requestedAttributes, other.requestedAttributes); + if (!Objects.equals(this.requestedAttributes, other.requestedAttributes)) { + return false; + } + return Objects.equals(this.frejaCookie, other.frejaCookie); } @Override public String toString() { - return "Result{" + "reference=" + reference + ", status=" + status + ", details=" + details + ", " + - "requestedAttributes=" + requestedAttributes + '}'; + return "Result{" + "reference=" + reference + + ", status=" + status + + ", details=" + details + + ", requestedAttributes=" + requestedAttributes + + ", frejaCookie=" + frejaCookie + + '}'; } } diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/OriginDeviceDetails.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/OriginDeviceDetails.java new file mode 100644 index 0000000..85ba838 --- /dev/null +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/OriginDeviceDetails.java @@ -0,0 +1,103 @@ +package com.verisec.frejaeid.client.beans.general; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; + +/** + * + * @author mirko.stojmenovic + */ +public class OriginDeviceDetails { + + private final String frejaCookie; + private final String userAgent; + private final String userIpAddress; + private final FlowType flowType; + + public enum FlowType { + SAME_DEVICE, + ANOTHER_DEVICE + } + /** + * Creates instance of {@linkplain OriginDeviceDetails}. + * + * @param frejaCookie Cookie to be set and received from end-user browser. + * Each time an initAuthentication is called, the cookie obtained through + * "Cookie" header of the HTTP request shall be passed to Freja's REST API. + * After transaction is confirmed, a new cookie is received from Freja API, + * and shall be forwarded to end-user browser via the "Set-Cookie" HTTP header. + * @return information of end user's device + */ + public static OriginDeviceDetails create(String frejaCookie) { + return new OriginDeviceDetails(frejaCookie, null, null, null); + } + + public static OriginDeviceDetails create(String frejaCookie, String userAgent, String userIpAddress, + FlowType flowType) { + return new OriginDeviceDetails(frejaCookie, userAgent, userIpAddress, flowType); + } + + @JsonCreator + private OriginDeviceDetails(@JsonProperty("frejaCookie") String frejaCookie, + @JsonProperty("userAgent") String userAgent, + @JsonProperty("userIpAddress") String userIpAddress, + @JsonProperty("flowType") FlowType flowType) { + this.frejaCookie = frejaCookie; + this.userAgent = userAgent; + this.userIpAddress = userIpAddress; + this.flowType = flowType; + } + + public String getFrejaCookie() { + return frejaCookie; + } + + public String getUserAgent() { + return userAgent; + } + + public String getUserIpAddress() { + return userIpAddress; + } + + public FlowType getFlowType() { + return flowType; + } + + @Override + public int hashCode() { + return Objects.hash(frejaCookie, userAgent, userIpAddress, flowType); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final OriginDeviceDetails other = (OriginDeviceDetails) obj; + if (!Objects.equals(this.frejaCookie, other.frejaCookie)) { + return false; + } + if (!Objects.equals(this.userAgent, other.userAgent)) { + return false; + } + if (!Objects.equals(this.userIpAddress, other.userIpAddress)) { + return false; + } + return this.flowType == other.flowType; + } + + @Override + public String toString() { + return "OriginDeviceDetails{" + "frejaCookie=" + frejaCookie + ", userAgent=" + userAgent + ", userIpAddress=" + + userIpAddress + ", flowType=" + flowType + '}'; + } + +} diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/RequestedAttributes.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/RequestedAttributes.java index 54ec9de..15e147b 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/RequestedAttributes.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/RequestedAttributes.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.verisec.frejaeid.client.beans.covidcertificate.CovidCertificates; import com.verisec.frejaeid.client.enums.RegistrationLevel; -import sun.nio.ch.Net; import java.util.List; import java.util.Objects; diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/get/OrganisationIdResult.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/get/OrganisationIdResult.java index cecf5c9..39b8376 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/get/OrganisationIdResult.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/get/OrganisationIdResult.java @@ -6,16 +6,16 @@ import com.verisec.frejaeid.client.enums.TransactionStatus; /** - * Contains transaction reference, transaction status, details and requested - * attributes. + * Contains transaction reference, transaction status, details and freja cookie. */ public class OrganisationIdResult extends Result { @JsonCreator public OrganisationIdResult(@JsonProperty(value = "orgIdRef") String reference, @JsonProperty(value = "status") TransactionStatus status, - @JsonProperty(value = "details") String details) { - super(reference, status, details, null); + @JsonProperty(value = "details") String details, + @JsonProperty(value = "frejaCookie") String frejaCookie) { + super(reference, status, details, null, frejaCookie); } /** diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/sign/get/SignResult.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/sign/get/SignResult.java index 75ef01a..1795fa5 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/sign/get/SignResult.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/sign/get/SignResult.java @@ -7,8 +7,7 @@ import com.verisec.frejaeid.client.enums.TransactionStatus; /** - * Contains transaction reference, transaction status, details and requested - * attributes. + * Contains transaction reference, transaction status, details, requested attributes and freja cookie. */ public class SignResult extends Result { @@ -16,8 +15,9 @@ public class SignResult extends Result { public SignResult(@JsonProperty(value = "signRef") String reference, @JsonProperty(value = "status") TransactionStatus status, @JsonProperty(value = "details") String details, - @JsonProperty(value = "requestedAttributes") RequestedAttributes requestedAttributes) { - super(reference, status, details, requestedAttributes); + @JsonProperty(value = "requestedAttributes") RequestedAttributes requestedAttributes, + @JsonProperty(value = "frejaCookie") String frejaCookie) { + super(reference, status, details, requestedAttributes, frejaCookie); } /** diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/sign/init/InitiateSignRequest.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/sign/init/InitiateSignRequest.java index 9ce8c3c..1894ac5 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/sign/init/InitiateSignRequest.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/sign/init/InitiateSignRequest.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.verisec.frejaeid.client.beans.common.RelyingPartyRequest; import com.verisec.frejaeid.client.beans.general.AttributeToReturnInfo; +import com.verisec.frejaeid.client.beans.general.OriginDeviceDetails; import com.verisec.frejaeid.client.beans.general.SsnUserInfo; import com.verisec.frejaeid.client.beans.sign.init.InitiateSignRequestBuilders.UserInfoBuilder; import com.verisec.frejaeid.client.enums.*; @@ -29,6 +30,7 @@ public class InitiateSignRequest implements RelyingPartyRequest { private final String relyingPartyId; private final String orgIdIssuer; private final UserConfirmationMethod userConfirmationMethod; + private final OriginDeviceDetails originDeviceDetails; /** * Returns instance of {@linkplain InitiateSignRequest} with: @@ -48,7 +50,7 @@ public class InitiateSignRequest implements RelyingPartyRequest { public static InitiateSignRequest createDefaultWithEmail(String email, String title, String text) { return new InitiateSignRequest(UserInfoType.EMAIL, email, MinRegistrationLevel.PLUS, title, null, null, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(text), SignatureType.SIMPLE, - null, null, null, null); + null, null, null, null, null); } /** @@ -73,7 +75,7 @@ public static InitiateSignRequest createDefaultWithSsn(SsnUserInfo ssnUserInfo, throws FrejaEidClientInternalException { return new InitiateSignRequest(UserInfoType.SSN, UserInfoUtil.convertSsnUserInfo(ssnUserInfo), MinRegistrationLevel.PLUS, title, null, null, DataToSignType.SIMPLE_UTF8_TEXT, - DataToSign.create(text), SignatureType.SIMPLE, null, null, null, null); + DataToSign.create(text), SignatureType.SIMPLE, null, null, null, null, null); } /** @@ -100,7 +102,8 @@ public static UserInfoBuilder createCustom() { @JsonProperty(value = "attributesToReturn") Set attributesToReturn, @JsonProperty(value = "relyingPartyId") String relyingPartyId, @JsonProperty(value = "orgIdIssuer") String orgIdIssuer, - @JsonProperty(value = "userConfirmationMethod") UserConfirmationMethod userConfirmationMethod) { + @JsonProperty(value = "userConfirmationMethod") UserConfirmationMethod userConfirmationMethod, + @JsonProperty(value = "originDeviceDetails") OriginDeviceDetails originDeviceDetails) { this.userInfoType = userInfoType; this.userInfo = userInfo; this.title = title; @@ -114,6 +117,7 @@ public static UserInfoBuilder createCustom() { this.relyingPartyId = relyingPartyId; this.orgIdIssuer = orgIdIssuer; this.userConfirmationMethod = userConfirmationMethod; + this.originDeviceDetails = originDeviceDetails; } public UserInfoType getUserInfoType() { @@ -169,11 +173,15 @@ public UserConfirmationMethod getUserConfirmationMethod() { return userConfirmationMethod; } + public OriginDeviceDetails getOriginDeviceDetails() { + return originDeviceDetails; + } + @Override public int hashCode() { return Objects.hash( userInfoType, userInfo, title, minRegistrationLevel, pushNotification, expiry, dataToSignType, - dataToSign, signatureType, relyingPartyId, orgIdIssuer, userConfirmationMethod); + dataToSign, signatureType, relyingPartyId, orgIdIssuer, userConfirmationMethod, originDeviceDetails); } @Override @@ -234,6 +242,9 @@ public boolean equals(Object obj) { if (this.userConfirmationMethod != other.userConfirmationMethod) { return false; } + if (!Objects.equals(this.originDeviceDetails, other.originDeviceDetails)) { + return false; + } return true; } @@ -253,6 +264,7 @@ public String toString() { ", relyingPartyId='" + relyingPartyId + '\'' + ", orgIdIssuer='" + orgIdIssuer + '\'' + ", userConfirmationMethod=" + userConfirmationMethod + + ", originDeviceDetails=" + originDeviceDetails + '}'; } } diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/sign/init/InitiateSignRequestBuilders.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/sign/init/InitiateSignRequestBuilders.java index 026aa13..d81cdcf 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/sign/init/InitiateSignRequestBuilders.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/sign/init/InitiateSignRequestBuilders.java @@ -1,6 +1,7 @@ package com.verisec.frejaeid.client.beans.sign.init; import com.verisec.frejaeid.client.beans.general.AttributeToReturnInfo; +import com.verisec.frejaeid.client.beans.general.OriginDeviceDetails; import com.verisec.frejaeid.client.beans.general.SsnUserInfo; import com.verisec.frejaeid.client.enums.*; import com.verisec.frejaeid.client.exceptions.FrejaEidClientInternalException; @@ -91,6 +92,7 @@ public static class SetOptionalParamsBuilder { private String relyingPartyId = null; private String orgIdIssuer = null; private UserConfirmationMethod userConfirmationMethod = null; + private OriginDeviceDetails originDeviceDetails = null; private SetOptionalParamsBuilder(UserInfoType userInfoType, String userInfo) { this.userInfoType = userInfoType; @@ -264,11 +266,25 @@ public SetOptionalParamsBuilder setUserConfirmationMethod(UserConfirmationMethod this.userConfirmationMethod = userConfirmationMethod; return this; } + + + /** + * OriginDeviceDetails contains information about the end user device from which the transaction was + * initiated. + * + * @param originDeviceDetails information about the end user device + * @return request builder + */ + public SetOptionalParamsBuilder setOriginDeviceDetails(OriginDeviceDetails originDeviceDetails) { + this.originDeviceDetails = originDeviceDetails; + return this; + } + public InitiateSignRequest build() { return new InitiateSignRequest(userInfoType, userInfo, minRegistrationLevel, title, pushNotification, expiry, dataToSignType, dataToSign, signatureType, attributesToReturn, - relyingPartyId, orgIdIssuer, userConfirmationMethod); + relyingPartyId, orgIdIssuer, userConfirmationMethod, originDeviceDetails); } } diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/beans/authentication/init/InitiateAuthenticationRequestBuildersTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/beans/authentication/init/InitiateAuthenticationRequestBuildersTest.java index 8c6058f..096a953 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/beans/authentication/init/InitiateAuthenticationRequestBuildersTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/beans/authentication/init/InitiateAuthenticationRequestBuildersTest.java @@ -1,6 +1,7 @@ package com.verisec.frejaeid.client.beans.authentication.init; import com.verisec.frejaeid.client.beans.general.AttributeToReturnInfo; +import com.verisec.frejaeid.client.beans.general.OriginDeviceDetails; import com.verisec.frejaeid.client.beans.general.SsnUserInfo; import com.verisec.frejaeid.client.enums.*; import com.verisec.frejaeid.client.exceptions.FrejaEidClientInternalException; @@ -22,6 +23,7 @@ public class InitiateAuthenticationRequestBuildersTest { private static final String RELYING_PARTY_ID = "relyingPartyId"; private static final String ORGANISATION_ID = "orgId"; private static final String ORG_ID_ISSUER = "orgIdIssuer"; + private static final OriginDeviceDetails ORIGIN_DEVICE_DETAILS = OriginDeviceDetails.create("frejaCookie"); private static final Set REQUESTED_ATTRIBUTES = new HashSet<>(); @BeforeClass @@ -57,7 +59,7 @@ private static AttributeToReturnInfo attributeOf(AttributeToReturn attributeToRe public void createDefaultEmailRequest() { InitiateAuthenticationRequest expectedInitiateAuthenticationRequest = new InitiateAuthenticationRequest( - UserInfoType.EMAIL, EMAIL, MinRegistrationLevel.BASIC, null, null, null, null); + UserInfoType.EMAIL, EMAIL, MinRegistrationLevel.BASIC, null, null, null, null, null); InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.createDefaultWithEmail(EMAIL); Assert.assertEquals(expectedInitiateAuthenticationRequest, initiateAuthenticationRequest); @@ -67,7 +69,7 @@ public void createDefaultEmailRequest() { public void createDefaultSsnRequest() throws FrejaEidClientInternalException { InitiateAuthenticationRequest expectedInitiateAuthenticationRequest = new InitiateAuthenticationRequest(UserInfoType.SSN, UserInfoUtil.convertSsnUserInfo(SSN_USER_INFO), - MinRegistrationLevel.BASIC, null, null, null, null); + MinRegistrationLevel.BASIC, null, null, null, null, null); InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.createDefaultWithSsn(SSN_USER_INFO); Assert.assertEquals(expectedInitiateAuthenticationRequest, initiateAuthenticationRequest); @@ -77,7 +79,7 @@ public void createDefaultSsnRequest() throws FrejaEidClientInternalException { public void createCustomRequest_userInfoTypeEmail() { InitiateAuthenticationRequest expectedInitiateAuthenticationRequest = new InitiateAuthenticationRequest(UserInfoType.EMAIL, EMAIL, MinRegistrationLevel.EXTENDED, - REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null); + REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null, null); InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.createCustom() .setEmail(EMAIL) .setMinRegistrationLevel(REGISTRATION_STATE) @@ -92,7 +94,7 @@ public void createCustomRequest_userInfoTypeEmail() { public void createCustomRequest_userInfoTypeEmail_defaultRegistrationState() { InitiateAuthenticationRequest expectedInitiateAuthenticationRequest = new InitiateAuthenticationRequest(UserInfoType.EMAIL, EMAIL, MinRegistrationLevel.BASIC, - REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null); + REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null, null); InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.createCustom() .setEmail(EMAIL) .setAttributesToReturn(AttributeToReturn.values()) @@ -107,7 +109,7 @@ public void createCustomRequest_userInfoTypeSsn() throws FrejaEidClientInternalE InitiateAuthenticationRequest expectedInitiateAuthenticationRequest = new InitiateAuthenticationRequest(UserInfoType.SSN, UserInfoUtil.convertSsnUserInfo(SSN_USER_INFO), MinRegistrationLevel.EXTENDED, REQUESTED_ATTRIBUTES, - RELYING_PARTY_ID, ORG_ID_ISSUER, null); + RELYING_PARTY_ID, ORG_ID_ISSUER, null, null); InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.createCustom() .setSsn(SSN_USER_INFO) .setAttributesToReturn(AttributeToReturn.values()) @@ -122,7 +124,7 @@ public void createCustomRequest_userInfoTypeSsn() throws FrejaEidClientInternalE public void createCustomRequest_userInfoTypePhoneNumber() { InitiateAuthenticationRequest expectedInitiateAuthenticationRequest = new InitiateAuthenticationRequest(UserInfoType.PHONE, PHONE_NUMBER, REGISTRATION_STATE, - REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null); + REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null, null); InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.createCustom() .setPhoneNumber(PHONE_NUMBER) .setAttributesToReturn(AttributeToReturn.values()) @@ -138,7 +140,7 @@ public void createCustomRequest_userInfoTypeInferred() { InitiateAuthenticationRequest expectedInitiateAuthenticationRequest = new InitiateAuthenticationRequest(UserInfoType.INFERRED, INFERRED_USER_INFO, REGISTRATION_STATE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, - UserConfirmationMethod.DEFAULT); + UserConfirmationMethod.DEFAULT, ORIGIN_DEVICE_DETAILS); InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.createCustom() .setInferred() .setAttributesToReturn(AttributeToReturn.values()) @@ -146,6 +148,7 @@ public void createCustomRequest_userInfoTypeInferred() { .setRelyingPartyId(RELYING_PARTY_ID) .setOrgIdIssuer(ORG_ID_ISSUER) .setUserConfirmationMethod(UserConfirmationMethod.DEFAULT) + .setOriginDeviceDetails(ORIGIN_DEVICE_DETAILS) .build(); Assert.assertEquals(expectedInitiateAuthenticationRequest, initiateAuthenticationRequest); } @@ -155,7 +158,7 @@ public void createCustomRequest_minRegistrationLevelAndRelyingPartyIdNull() { InitiateAuthenticationRequest expectedInitiateAuthenticationRequest = new InitiateAuthenticationRequest(UserInfoType.INFERRED, INFERRED_USER_INFO, MinRegistrationLevel.BASIC, REQUESTED_ATTRIBUTES, null, - ORG_ID_ISSUER, null); + ORG_ID_ISSUER, null, null); InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.createCustom() .setInferred() .setAttributesToReturn(AttributeToReturn.values()) @@ -170,7 +173,7 @@ public void createCustomRequest_minRegistrationLevelAndRelyingPartyIdNull() { public void createCustomRequest_userInfoOrganisationId() { InitiateAuthenticationRequest expectedInitiateAuthenticationRequest = new InitiateAuthenticationRequest(UserInfoType.ORG_ID, ORGANISATION_ID, MinRegistrationLevel.EXTENDED, - REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null); + REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null, null); InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.createCustom() .setOrganisationId(ORGANISATION_ID) .setAttributesToReturn(AttributeToReturn.values()) @@ -186,7 +189,7 @@ public void createCustomRequest_orgIdIssuerNull() { InitiateAuthenticationRequest expectedInitiateAuthenticationRequest = new InitiateAuthenticationRequest(UserInfoType.INFERRED, INFERRED_USER_INFO, MinRegistrationLevel.BASIC, REQUESTED_ATTRIBUTES, null, - null, null); + null, null, null); InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.createCustom() .setInferred() .setAttributesToReturn(AttributeToReturn.values()) @@ -202,7 +205,7 @@ public void createCustomRequest_userConfirmationMethodSet() { InitiateAuthenticationRequest expectedInitiateAuthenticationRequest = new InitiateAuthenticationRequest(UserInfoType.EMAIL, EMAIL, MinRegistrationLevel.EXTENDED, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, - UserConfirmationMethod.DEFAULT_AND_FACE); + UserConfirmationMethod.DEFAULT_AND_FACE, ORIGIN_DEVICE_DETAILS); InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.createCustom() .setEmail(EMAIL) .setMinRegistrationLevel(REGISTRATION_STATE) @@ -210,6 +213,22 @@ public void createCustomRequest_userConfirmationMethodSet() { .setRelyingPartyId(RELYING_PARTY_ID) .setOrgIdIssuer(ORG_ID_ISSUER) .setUserConfirmationMethod(UserConfirmationMethod.DEFAULT_AND_FACE) + .setOriginDeviceDetails(ORIGIN_DEVICE_DETAILS) + .build(); + Assert.assertEquals(expectedInitiateAuthenticationRequest, initiateAuthenticationRequest); + } + + @Test + public void createCustomRequest_originDeviceDetailsSet() { + InitiateAuthenticationRequest expectedInitiateAuthenticationRequest = + new InitiateAuthenticationRequest(UserInfoType.EMAIL, EMAIL, MinRegistrationLevel.EXTENDED, + REQUESTED_ATTRIBUTES, null, null, + null, ORIGIN_DEVICE_DETAILS); + InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.createCustom() + .setEmail(EMAIL) + .setMinRegistrationLevel(REGISTRATION_STATE) + .setAttributesToReturn(AttributeToReturn.values()) + .setOriginDeviceDetails(ORIGIN_DEVICE_DETAILS) .build(); Assert.assertEquals(expectedInitiateAuthenticationRequest, initiateAuthenticationRequest); } diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/beans/sign/init/InitiateSignRequestBuildersTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/beans/sign/init/InitiateSignRequestBuildersTest.java index 6f40cc1..8e46f8c 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/beans/sign/init/InitiateSignRequestBuildersTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/beans/sign/init/InitiateSignRequestBuildersTest.java @@ -1,6 +1,7 @@ package com.verisec.frejaeid.client.beans.sign.init; import com.verisec.frejaeid.client.beans.general.AttributeToReturnInfo; +import com.verisec.frejaeid.client.beans.general.OriginDeviceDetails; import com.verisec.frejaeid.client.beans.general.SsnUserInfo; import com.verisec.frejaeid.client.enums.*; import com.verisec.frejaeid.client.exceptions.FrejaEidClientInternalException; @@ -25,6 +26,7 @@ public class InitiateSignRequestBuildersTest { private static final String ORGANISATION_ID = "orgId"; private static final String ORG_ID_ISSUER = "orgIdIssuer"; private static final PushNotification PUSH_NOTIFICATION = PushNotification.create(TITLE, TEXT); + private static final OriginDeviceDetails ORIGIN_DEVICE_DETAILS = OriginDeviceDetails.create("frejaCookie"); private static final Set REQUESTED_ATTRIBUTES = new HashSet<>(); @BeforeClass @@ -61,7 +63,7 @@ public void createDefaultEmailRequest() { InitiateSignRequest expectedInitiateSignRequest = new InitiateSignRequest(UserInfoType.EMAIL, EMAIL, MinRegistrationLevel.PLUS, TITLE, null, null, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT), - SignatureType.SIMPLE, null, null, null, null); + SignatureType.SIMPLE, null, null, null, null, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createDefaultWithEmail(EMAIL, TITLE, TEXT); Assert.assertEquals(expectedInitiateSignRequest, initiateSignRequest); } @@ -71,7 +73,7 @@ public void createDefaultSsnRequest() throws FrejaEidClientInternalException { InitiateSignRequest expectedInitiateSignRequest = new InitiateSignRequest(UserInfoType.SSN, UserInfoUtil.convertSsnUserInfo(SSN_USER_INFO), MinRegistrationLevel.PLUS, TITLE, null, null, DataToSignType.SIMPLE_UTF8_TEXT, - DataToSign.create(TEXT), SignatureType.SIMPLE, null, null, null, null); + DataToSign.create(TEXT), SignatureType.SIMPLE, null, null, null, null, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createDefaultWithSsn(SSN_USER_INFO, TITLE, TEXT); Assert.assertEquals(expectedInitiateSignRequest, initiateSignRequest); } @@ -82,7 +84,7 @@ public void createCustomRequest_userInfoTypeEmail() { new InitiateSignRequest(UserInfoType.EMAIL, EMAIL, REGISTRATION_STATE, TITLE, PUSH_NOTIFICATION, EXPIRY, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT), SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, - UserConfirmationMethod.DEFAULT); + UserConfirmationMethod.DEFAULT, ORIGIN_DEVICE_DETAILS); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() .setEmail(EMAIL) .setTitle(TITLE) @@ -94,6 +96,7 @@ public void createCustomRequest_userInfoTypeEmail() { .setRelyingPartyId(RELYING_PARTY_ID) .setOrgIdIssuer(ORG_ID_ISSUER) .setUserConfirmationMethod(UserConfirmationMethod.DEFAULT) + .setOriginDeviceDetails(ORIGIN_DEVICE_DETAILS) .build(); Assert.assertEquals(expectedInitiateSignRequest, initiateSignRequest); } @@ -104,7 +107,7 @@ public void createCustomRequest_userInfoTypeEmail_defaultRegistrationState() { new InitiateSignRequest( UserInfoType.EMAIL, EMAIL, MinRegistrationLevel.PLUS, TITLE, null, EXPIRY, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT), - SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null); + SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() .setEmail(EMAIL) .setTitle(TITLE) @@ -124,7 +127,7 @@ public void createCustomRequest_userInfoTypeSsn() throws FrejaEidClientInternalE UserInfoType.SSN, UserInfoUtil.convertSsnUserInfo(SSN_USER_INFO), REGISTRATION_STATE, TITLE, PUSH_NOTIFICATION, EXPIRY, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT), - SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null); + SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() .setSsn(SSN_USER_INFO) .setTitle(TITLE) @@ -144,7 +147,7 @@ public void createCustomRequest_userInfoTypePhoneNumber_optionalParamsNull() { InitiateSignRequest expectedInitiateSignRequest = new InitiateSignRequest(UserInfoType.PHONE, PHONE_NUMBER, MinRegistrationLevel.PLUS, null, null, null, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT), - SignatureType.SIMPLE, null, null, null, null); + SignatureType.SIMPLE, null, null, null, null, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() .setPhoneNumber(PHONE_NUMBER) .setTitle(null) @@ -166,7 +169,7 @@ public void createCustomRequest_extendedSignatureType() throws FrejaEidClientInt UserInfoType.SSN, UserInfoUtil.convertSsnUserInfo(SSN_USER_INFO), REGISTRATION_STATE, TITLE, PUSH_NOTIFICATION, EXPIRY, DataToSignType.EXTENDED_UTF8_TEXT, DataToSign.create(TEXT, TEXT.getBytes()), - SignatureType.EXTENDED, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null); + SignatureType.EXTENDED, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() .setSsn(SSN_USER_INFO) .setTitle(TITLE) @@ -188,7 +191,7 @@ public void createCustomRequest_binaryDataNull() throws FrejaEidClientInternalEx UserInfoType.SSN, UserInfoUtil.convertSsnUserInfo(SSN_USER_INFO), REGISTRATION_STATE, TITLE, PUSH_NOTIFICATION, EXPIRY, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT), - SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null); + SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() .setSsn(SSN_USER_INFO) .setTitle(TITLE) @@ -210,7 +213,7 @@ public void createCustomRequest_binaryDataEmpty() throws FrejaEidClientInternalE UserInfoType.SSN, UserInfoUtil.convertSsnUserInfo(SSN_USER_INFO), REGISTRATION_STATE, TITLE, PUSH_NOTIFICATION, EXPIRY, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT, "".getBytes()), - SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null); + SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() .setSsn(SSN_USER_INFO) .setTitle(TITLE) @@ -232,7 +235,7 @@ public void createCustomRequest_minRegistrationLevelAndRelyingPartyIdNull() thro UserInfoType.SSN, UserInfoUtil.convertSsnUserInfo(SSN_USER_INFO), MinRegistrationLevel.PLUS, TITLE, PUSH_NOTIFICATION, EXPIRY, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT), - SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, null, ORG_ID_ISSUER, null); + SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, null, ORG_ID_ISSUER, null, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() .setSsn(SSN_USER_INFO) .setTitle(TITLE) @@ -254,7 +257,7 @@ public void createCustomRequest_userInfoTypeOrganisationId() { UserInfoType.ORG_ID, ORGANISATION_ID, REGISTRATION_STATE, TITLE, PUSH_NOTIFICATION, EXPIRY, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT), SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, - RELYING_PARTY_ID, ORG_ID_ISSUER, null); + RELYING_PARTY_ID, ORG_ID_ISSUER, null, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() .setOrganisationId(ORGANISATION_ID) .setTitle(TITLE) @@ -276,7 +279,7 @@ public void createCustomRequest_orgIdIssuerNull() throws FrejaEidClientInternalE UserInfoType.SSN, UserInfoUtil.convertSsnUserInfo(SSN_USER_INFO), MinRegistrationLevel.PLUS, TITLE, PUSH_NOTIFICATION, EXPIRY, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT), - SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, null, null); + SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, null, null, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() .setSsn(SSN_USER_INFO) .setTitle(TITLE) @@ -297,7 +300,8 @@ public void createCustomRequest_CMSImplicitSignature() throws FrejaEidClientInte UserInfoType.SSN, UserInfoUtil.convertSsnUserInfo(SSN_USER_INFO), MinRegistrationLevel.PLUS, TITLE, null, EXPIRY, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT), - SignatureType.XML_MINAMEDDELANDEN, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, null); + SignatureType.XML_MINAMEDDELANDEN, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, + null, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() .setSsn(SSN_USER_INFO) .setTitle(TITLE) @@ -317,7 +321,7 @@ public void createCustomRequest_userConfirmationMethodSet() { new InitiateSignRequest(UserInfoType.EMAIL, EMAIL, REGISTRATION_STATE, TITLE, PUSH_NOTIFICATION, EXPIRY, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT), SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, RELYING_PARTY_ID, ORG_ID_ISSUER, - UserConfirmationMethod.DEFAULT_AND_FACE); + UserConfirmationMethod.DEFAULT_AND_FACE, null); InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() .setEmail(EMAIL) .setTitle(TITLE) @@ -332,4 +336,24 @@ public void createCustomRequest_userConfirmationMethodSet() { .build(); Assert.assertEquals(expectedInitiateSignRequest, initiateSignRequest); } + + @Test + public void createCustomRequest_originDeviceDetailsSet() { + InitiateSignRequest expectedInitiateSignRequest = + new InitiateSignRequest(UserInfoType.EMAIL, EMAIL, REGISTRATION_STATE, TITLE, PUSH_NOTIFICATION, + EXPIRY, DataToSignType.SIMPLE_UTF8_TEXT, DataToSign.create(TEXT), + SignatureType.SIMPLE, REQUESTED_ATTRIBUTES, null, null, + null, ORIGIN_DEVICE_DETAILS); + InitiateSignRequest initiateSignRequest = InitiateSignRequest.createCustom() + .setEmail(EMAIL) + .setTitle(TITLE) + .setDataToSign(DataToSign.create(TEXT)) + .setMinRegistrationLevel(REGISTRATION_STATE) + .setAttributesToReturn(AttributeToReturn.values()) + .setExpiry(EXPIRY) + .setPushNotification(PUSH_NOTIFICATION) + .setOriginDeviceDetails(ORIGIN_DEVICE_DETAILS) + .build(); + Assert.assertEquals(expectedInitiateSignRequest, initiateSignRequest); + } } diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/AuthenticationClientGetResultTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/AuthenticationClientGetResultTest.java index f695513..a3ef57e 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/AuthenticationClientGetResultTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/AuthenticationClientGetResultTest.java @@ -24,13 +24,14 @@ import java.util.List; import java.util.Map; -import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.verify; @@ -70,6 +71,7 @@ public class AuthenticationClientGetResultTest { private static final CovidCertificates COVID_CERTIFICATES = new CovidCertificates(new Vaccines("covidCertificate"), null, null, true); private static final NetworkInfo NETWORK_INFO = new NetworkInfo("123.45.6.7"); + private static final String FREJA_COOKIE = "frejaCookie"; private static RequestedAttributes REQUESTED_ATTRIBUTES; private AuthenticationClientApi authenticationClient; @@ -110,7 +112,7 @@ public void getAuthenticationResult_relyingPartyIdNull_success() any(RelyingPartyRequest.class), Mockito.eq(AuthenticationResult.class), (String) Mockito.isNull())) .thenReturn(new AuthenticationResult(REFERENCE, TransactionStatus.STARTED, DETAILS, - REQUESTED_ATTRIBUTES)); + REQUESTED_ATTRIBUTES, FREJA_COOKIE)); AuthenticationResult response = authenticationClient.getResult(authenticationResultRequest); verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.AUTHENTICATION_GET_RESULT, RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE, @@ -119,6 +121,7 @@ public void getAuthenticationResult_relyingPartyIdNull_success() assertEquals(TransactionStatus.STARTED, response.getStatus()); assertEquals(DETAILS, response.getDetails()); assertEquals(REQUESTED_ATTRIBUTES, response.getRequestedAttributes()); + assertEquals(FREJA_COOKIE, response.getFrejaCookie()); } @Test @@ -129,7 +132,7 @@ public void getAuthenticationResultPersonal_success() throws FrejaEidClientInter any(RelyingPartyRequest.class), Mockito.eq(AuthenticationResult.class), anyString())) .thenReturn(new AuthenticationResult(REFERENCE, TransactionStatus.STARTED, DETAILS, - REQUESTED_ATTRIBUTES)); + REQUESTED_ATTRIBUTES, FREJA_COOKIE)); AuthenticationResult response = authenticationClient.getResult(authenticationResultRequest); verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.AUTHENTICATION_GET_RESULT, RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE, @@ -138,6 +141,7 @@ public void getAuthenticationResultPersonal_success() throws FrejaEidClientInter assertEquals(TransactionStatus.STARTED, response.getStatus()); assertEquals(DETAILS, response.getDetails()); assertEquals(REQUESTED_ATTRIBUTES, response.getRequestedAttributes()); + assertEquals(FREJA_COOKIE, response.getFrejaCookie()); } @Test @@ -153,7 +157,7 @@ public void getAuthenticationResultOrganisational_success() any(RelyingPartyRequest.class), Mockito.eq(AuthenticationResult.class), anyString())) .thenReturn(new AuthenticationResult(REFERENCE, TransactionStatus.APPROVED, DETAILS, - REQUESTED_ATTRIBUTES)); + REQUESTED_ATTRIBUTES, FREJA_COOKIE)); AuthenticationResult response = authenticationClient.getResult(authenticationResultRequest); verify(httpServiceMock) .send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.ORGANISATION_AUTHENTICATION_GET_ONE_RESULT, @@ -163,6 +167,7 @@ public void getAuthenticationResultOrganisational_success() assertEquals(TransactionStatus.APPROVED, response.getStatus()); assertEquals(DETAILS, response.getDetails()); assertEquals(REQUESTED_ATTRIBUTES, response.getRequestedAttributes()); + assertEquals(FREJA_COOKIE, response.getFrejaCookie()); } @Test @@ -188,7 +193,7 @@ public void getAuthenticationResultOrganisational_withAdditionalAttributes_succe any(RelyingPartyRequest.class), Mockito.eq(AuthenticationResult.class), anyString())) .thenReturn(new AuthenticationResult(REFERENCE, TransactionStatus.APPROVED, DETAILS, - requestedAttributes)); + requestedAttributes, FREJA_COOKIE)); AuthenticationResult response = authenticationClient.getResult(authenticationResultRequest); verify(httpServiceMock) .send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.ORGANISATION_AUTHENTICATION_GET_ONE_RESULT, @@ -198,6 +203,7 @@ public void getAuthenticationResultOrganisational_withAdditionalAttributes_succe assertEquals(TransactionStatus.APPROVED, response.getStatus()); assertEquals(DETAILS, response.getDetails()); assertEquals(requestedAttributes, response.getRequestedAttributes()); + assertEquals(FREJA_COOKIE, response.getFrejaCookie()); } @Test @@ -212,7 +218,7 @@ public void getAuthenticationResult_invalidReference_expectInvalidReferenceError .thenThrow(new FrejaEidException(FrejaEidErrorCode.INVALID_REFERENCE.getMessage(), FrejaEidErrorCode.INVALID_REFERENCE.getCode())); authenticationClient.getResult(getOneAuthenticationResultRequest); - Assert.fail("Test should throw exception!"); + fail("Test should throw exception!"); } catch (FrejaEidException rpEx) { verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.AUTHENTICATION_GET_RESULT, RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE, @@ -227,7 +233,7 @@ public void getAuthenticationResult_invalidReference_expectInvalidReferenceError public void pollForResult_relyingPartyIdNull_finalResponseRejected_success() throws FrejaEidClientInternalException, FrejaEidException, FrejaEidClientPollingException { AuthenticationResult expectedResponse = - new AuthenticationResult(DETAILS, TransactionStatus.REJECTED, DETAILS, null); + new AuthenticationResult(DETAILS, TransactionStatus.REJECTED, DETAILS, null, null); AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.create(REFERENCE); when(httpServiceMock.send(anyString(), any(RequestTemplate.class), any(RelyingPartyRequest.class), @@ -244,7 +250,7 @@ public void pollForResult_relyingPartyIdNull_finalResponseRejected_success() public void pollForResult_relyingPartyIdNotNull_finalResponseRejected_success() throws FrejaEidClientInternalException, FrejaEidException, FrejaEidClientPollingException { AuthenticationResult expectedResponse = - new AuthenticationResult(DETAILS, TransactionStatus.REJECTED, DETAILS, null); + new AuthenticationResult(DETAILS, TransactionStatus.REJECTED, DETAILS, null, null); AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.create(REFERENCE, RELYING_PARTY_ID); when(httpServiceMock.send(anyString(), any(RequestTemplate.class), @@ -264,7 +270,7 @@ public void pollForResult_requestTimeout_expectTimeoutError() throws FrejaEidClientInternalException, FrejaEidException { try { authenticationClient.pollForResult(AuthenticationResultRequest.create(REFERENCE), 2); - Assert.fail("Test should throw exception!"); + fail("Test should throw exception!"); } catch (FrejaEidClientPollingException ex) { assertEquals("A timeout of 2s was reached while sending request.", ex.getLocalizedMessage()); } @@ -308,12 +314,14 @@ private void getAuthenticationResults_success(AuthenticationResultsRequest getAu assertEquals(TransactionStatus.STARTED, first.getStatus()); assertEquals(DETAILS, first.getDetails()); assertEquals(REQUESTED_ATTRIBUTES, first.getRequestedAttributes()); + assertEquals(FREJA_COOKIE, first.getFrejaCookie()); AuthenticationResult second = response.get(1); assertEquals(REFERENCE, second.getAuthRef()); assertEquals(TransactionStatus.DELIVERED_TO_MOBILE, second.getStatus()); assertEquals("test", second.getDetails()); assertEquals("test", second.getRequestedAttributes().getCustomIdentifier()); + assertNull(second.getFrejaCookie()); } private AuthenticationResults prepareResponse() { @@ -326,12 +334,13 @@ private AuthenticationResults prepareResponse() { Arrays.asList(CHILDREN_DOCUMENT_WITH_PDF), NETWORK_INFO); AuthenticationResult firstResponse = - new AuthenticationResult(REFERENCE, TransactionStatus.STARTED, DETAILS, attributes1); + new AuthenticationResult(REFERENCE, TransactionStatus.STARTED, DETAILS, attributes1, FREJA_COOKIE); RequestedAttributes attributes2 = new RequestedAttributes(null, "test", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); AuthenticationResult secondResponse = - new AuthenticationResult(REFERENCE, TransactionStatus.DELIVERED_TO_MOBILE, "test", attributes2); + new AuthenticationResult(REFERENCE, TransactionStatus.DELIVERED_TO_MOBILE, "test", attributes2, + null); List responses = new ArrayList<>(); responses.add(firstResponse); responses.add(secondResponse); diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdClientGetResultTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdClientGetResultTest.java index 8a0c953..d40d195 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdClientGetResultTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdClientGetResultTest.java @@ -14,7 +14,8 @@ import com.verisec.frejaeid.client.http.HttpServiceApi; import com.verisec.frejaeid.client.util.MethodUrl; import com.verisec.frejaeid.client.util.RequestTemplate; -import org.junit.Assert; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -25,6 +26,7 @@ public class OrganisationIdClientGetResultTest { private static final String RELYING_PARTY_ID = "relyingPartyId"; private static final String REFERENCE = "123456789123456789"; private static final String DETAILS = "This is sign transaction"; + private static final String FREJA_COOKIE = "frejaCookie"; private OrganisationIdClientApi organisationIdClient; @Before @@ -38,36 +40,42 @@ public void initialiseClient() throws FrejaEidClientInternalException { public void getOrganisationIdResult_relyingPartyIdNull_expectSuccess() throws FrejaEidClientInternalException, FrejaEidException { OrganisationIdResultRequest organisationIdResultRequest = OrganisationIdResultRequest.create(REFERENCE); - OrganisationIdResult expectedResponse = new OrganisationIdResult(REFERENCE, TransactionStatus.STARTED, DETAILS); + OrganisationIdResult expectedResponse = new OrganisationIdResult(REFERENCE, TransactionStatus.STARTED, DETAILS, + FREJA_COOKIE); Mockito.when(httpServiceMock.send(Mockito.anyString(), Mockito.any(RequestTemplate.class), Mockito.any(RelyingPartyRequest.class), Mockito.eq(OrganisationIdResult.class), (String) Mockito.isNull())) .thenReturn(expectedResponse); OrganisationIdResult response = organisationIdClient.getResult(organisationIdResultRequest); - Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.ORGANISATION_ID_GET_RESULT, + Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + + MethodUrl.ORGANISATION_ID_GET_RESULT, RequestTemplate.ORGANISATION_ID_RESULT_TEMPLATE, organisationIdResultRequest, OrganisationIdResult.class, null); - Assert.assertEquals(REFERENCE, response.getOrgIdRef()); - Assert.assertEquals(TransactionStatus.STARTED, response.getStatus()); - Assert.assertEquals(DETAILS, response.getDetails()); + assertEquals(REFERENCE, response.getOrgIdRef()); + assertEquals(TransactionStatus.STARTED, response.getStatus()); + assertEquals(DETAILS, response.getDetails()); + assertEquals(FREJA_COOKIE, response.getFrejaCookie()); } @Test public void getOrganisationIdResult_expectSuccess() throws FrejaEidClientInternalException, FrejaEidException { OrganisationIdResultRequest organisationIdResultRequest = OrganisationIdResultRequest.create(REFERENCE, RELYING_PARTY_ID); - OrganisationIdResult expectedResponse = new OrganisationIdResult(REFERENCE, TransactionStatus.STARTED, DETAILS); + OrganisationIdResult expectedResponse = new OrganisationIdResult(REFERENCE, TransactionStatus.STARTED, DETAILS, + FREJA_COOKIE); Mockito.when(httpServiceMock.send(Mockito.anyString(), Mockito.any(RequestTemplate.class), Mockito.any(RelyingPartyRequest.class), Mockito.eq(OrganisationIdResult.class), Mockito.anyString())) .thenReturn(expectedResponse); OrganisationIdResult response = organisationIdClient.getResult(organisationIdResultRequest); - Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.ORGANISATION_ID_GET_RESULT, + Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + + MethodUrl.ORGANISATION_ID_GET_RESULT, RequestTemplate.ORGANISATION_ID_RESULT_TEMPLATE, organisationIdResultRequest, OrganisationIdResult.class, RELYING_PARTY_ID); - Assert.assertEquals(REFERENCE, response.getOrgIdRef()); - Assert.assertEquals(TransactionStatus.STARTED, response.getStatus()); - Assert.assertEquals(DETAILS, response.getDetails()); + assertEquals(REFERENCE, response.getOrgIdRef()); + assertEquals(TransactionStatus.STARTED, response.getStatus()); + assertEquals(DETAILS, response.getDetails()); + assertEquals(FREJA_COOKIE, response.getFrejaCookie()); } @Test @@ -84,14 +92,14 @@ public void getOrganisationIdResult_invalidReference_expectInvalidReferenceError Mockito.eq(OrganisationIdResult.class), Mockito.anyString())) .thenThrow(frejaEidException); organisationIdClient.getResult(organisationIdResultRequest); - Assert.fail("Test should throw exception!"); + fail("Test should throw exception!"); } catch (FrejaEidException rpEx) { Mockito.verify(httpServiceMock) .send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.ORGANISATION_ID_GET_RESULT, RequestTemplate.ORGANISATION_ID_RESULT_TEMPLATE, organisationIdResultRequest, OrganisationIdResult.class, RELYING_PARTY_ID); - Assert.assertEquals(1100, rpEx.getErrorCode()); - Assert.assertEquals("Invalid reference (for example, nonexistent or expired).", rpEx.getLocalizedMessage()); + assertEquals(1100, rpEx.getErrorCode()); + assertEquals("Invalid reference (for example, nonexistent or expired).", rpEx.getLocalizedMessage()); } } @@ -99,7 +107,7 @@ public void getOrganisationIdResult_invalidReference_expectInvalidReferenceError public void pollForResult_finalResponseRejected_success() throws FrejaEidClientInternalException, FrejaEidException, FrejaEidClientPollingException { OrganisationIdResult expectedResponse = - new OrganisationIdResult(REFERENCE, TransactionStatus.REJECTED, DETAILS); + new OrganisationIdResult(REFERENCE, TransactionStatus.REJECTED, DETAILS, null); Mockito.when(httpServiceMock.send(Mockito.anyString(), Mockito.any(RequestTemplate.class), Mockito.any(RelyingPartyRequest.class), Mockito.eq(OrganisationIdResult.class), (String) Mockito.isNull())) @@ -110,7 +118,7 @@ public void pollForResult_finalResponseRejected_success() .send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.ORGANISATION_ID_GET_RESULT, RequestTemplate.ORGANISATION_ID_RESULT_TEMPLATE, organisationIdResultRequest, OrganisationIdResult.class, null); - Assert.assertEquals(TransactionStatus.REJECTED, response.getStatus()); + assertEquals(TransactionStatus.REJECTED, response.getStatus()); } @Test @@ -118,9 +126,9 @@ public void getFinalOrganisationIdResponse_requestTimeout_expectTimeoutError() throws FrejaEidException, FrejaEidClientInternalException { try { organisationIdClient.pollForResult(OrganisationIdResultRequest.create(REFERENCE), 2); - Assert.fail("Test should throw exception!"); + fail("Test should throw exception!"); } catch (FrejaEidClientPollingException ex) { - Assert.assertEquals("A timeout of 2s was reached while sending request.", ex.getLocalizedMessage()); + assertEquals("A timeout of 2s was reached while sending request.", ex.getLocalizedMessage()); } } } diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/SignClientGetResultTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/SignClientGetResultTest.java index 41f6122..ec5aa91 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/SignClientGetResultTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/SignClientGetResultTest.java @@ -24,13 +24,14 @@ import java.util.List; import java.util.Map; -import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.verify; @@ -65,6 +66,7 @@ public class SignClientGetResultTest { protected static final CovidCertificates COVID_CERTIFICATES = new CovidCertificates(new Vaccines("covidCertificate"), null, null, true); private static final NetworkInfo NETWORK_INFO = new NetworkInfo("123.45.6.7"); + private static final String FREJA_COOKIE = "frejaCookie"; private static RequestedAttributes REQUESTED_ATTRIBUTES; private SignClientApi signClient; @@ -103,7 +105,7 @@ public void getSignResult_relyingPartyIdNull_expectSuccess() throws FrejaEidClientInternalException, FrejaEidException { SignResultRequest signResultsRequest = SignResultRequest.create(SIGN_REFERENCE); SignResult expectedResponse = new SignResult(SIGN_REFERENCE, TransactionStatus.STARTED, SIGN_DETAILS, - REQUESTED_ATTRIBUTES); + REQUESTED_ATTRIBUTES, FREJA_COOKIE); when(httpServiceMock.send(anyString(), any(RequestTemplate.class), any(RelyingPartyRequest.class), Mockito.eq(SignResult.class), (String) Mockito.isNull())).thenReturn(expectedResponse); @@ -115,13 +117,15 @@ public void getSignResult_relyingPartyIdNull_expectSuccess() assertEquals(TransactionStatus.STARTED, response.getStatus()); assertEquals(SIGN_DETAILS, response.getDetails()); assertEquals(REQUESTED_ATTRIBUTES, response.getRequestedAttributes()); + assertEquals(FREJA_COOKIE, response.getFrejaCookie()); } @Test public void getSignResultPersonal_expectSuccess() throws FrejaEidClientInternalException, FrejaEidException { SignResultRequest signResultRequest = SignResultRequest.create(SIGN_REFERENCE, RELYING_PARTY_ID); SignResult expectedResponse = - new SignResult(SIGN_REFERENCE, TransactionStatus.STARTED, SIGN_DETAILS, REQUESTED_ATTRIBUTES); + new SignResult(SIGN_REFERENCE, TransactionStatus.STARTED, SIGN_DETAILS, REQUESTED_ATTRIBUTES, + FREJA_COOKIE); when(httpServiceMock.send(anyString(), any(RequestTemplate.class), any(RelyingPartyRequest.class), Mockito.eq(SignResult.class), anyString())).thenReturn(expectedResponse); @@ -133,13 +137,15 @@ public void getSignResultPersonal_expectSuccess() throws FrejaEidClientInternalE assertEquals(TransactionStatus.STARTED, response.getStatus()); assertEquals(SIGN_DETAILS, response.getDetails()); assertEquals(REQUESTED_ATTRIBUTES, response.getRequestedAttributes()); + assertEquals(FREJA_COOKIE, response.getFrejaCookie()); } @Test public void getSignResultOrganisational_expectSuccess() throws FrejaEidClientInternalException, FrejaEidException { SignResultRequest signResultRequest = SignResultRequest.create(SIGN_REFERENCE, RELYING_PARTY_ID); SignResult expectedResponse = - new SignResult(SIGN_REFERENCE, TransactionStatus.APPROVED, SIGN_DETAILS, REQUESTED_ATTRIBUTES); + new SignResult(SIGN_REFERENCE, TransactionStatus.APPROVED, SIGN_DETAILS, REQUESTED_ATTRIBUTES, + FREJA_COOKIE); SignClientApi signClient = SignClient.create(TestUtil.getDefaultSslSettings(), FrejaEnvironment.TEST) .setHttpService(httpServiceMock) .setTransactionContext(TransactionContext.ORGANISATIONAL).build(); @@ -154,6 +160,7 @@ public void getSignResultOrganisational_expectSuccess() throws FrejaEidClientInt assertEquals(TransactionStatus.APPROVED, response.getStatus()); assertEquals(SIGN_DETAILS, response.getDetails()); assertEquals(REQUESTED_ATTRIBUTES, response.getRequestedAttributes()); + assertEquals(FREJA_COOKIE, response.getFrejaCookie()); } @Test @@ -172,7 +179,8 @@ public void getSignResultOrganisational_withAdditionalAttributes_expectSuccess() NETWORK_INFO); SignResultRequest signResultRequest = SignResultRequest.create(SIGN_REFERENCE, RELYING_PARTY_ID); SignResult expectedResponse = - new SignResult(SIGN_REFERENCE, TransactionStatus.APPROVED, SIGN_DETAILS, requestedAttributes); + new SignResult(SIGN_REFERENCE, TransactionStatus.APPROVED, SIGN_DETAILS, requestedAttributes, + FREJA_COOKIE); SignClientApi signClient = SignClient.create(TestUtil.getDefaultSslSettings(), FrejaEnvironment.TEST) .setHttpService(httpServiceMock) .setTransactionContext(TransactionContext.ORGANISATIONAL).build(); @@ -187,6 +195,7 @@ public void getSignResultOrganisational_withAdditionalAttributes_expectSuccess() assertEquals(TransactionStatus.APPROVED, response.getStatus()); assertEquals(SIGN_DETAILS, response.getDetails()); assertEquals(requestedAttributes, response.getRequestedAttributes()); + assertEquals(FREJA_COOKIE, response.getFrejaCookie()); } @Test @@ -200,7 +209,7 @@ public void getSignResult_invalidReference_expectInvalidReferenceError() any(RelyingPartyRequest.class), Mockito.eq(SignResult.class), anyString())).thenThrow(frejaEidException); signClient.getResult(signResultRequest); - Assert.fail("Test should throw exception!"); + fail("Test should throw exception!"); } catch (FrejaEidException rpEx) { verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.SIGN_GET_RESULT, RequestTemplate.SIGN_RESULT_TEMPLATE, signResultRequest, @@ -213,7 +222,8 @@ public void getSignResult_invalidReference_expectInvalidReferenceError() @Test public void pollForResult_finalResponseRejected_success() throws FrejaEidClientInternalException, FrejaEidException, FrejaEidClientPollingException { - SignResult expectedResponse = new SignResult(SIGN_REFERENCE, TransactionStatus.REJECTED, SIGN_DETAILS, null); + SignResult expectedResponse = new SignResult(SIGN_REFERENCE, TransactionStatus.REJECTED, SIGN_DETAILS, null, + null); when(httpServiceMock.send(anyString(), any(RequestTemplate.class), any(RelyingPartyRequest.class), Mockito.eq(SignResult.class), (String) Mockito.isNull())).thenReturn(expectedResponse); @@ -230,7 +240,7 @@ public void pollForResult_requestTimeout_expectTimeoutError() throws FrejaEidClientInternalException, FrejaEidException { try { signClient.pollForResult(SignResultRequest.create(SIGN_REFERENCE), 2); - Assert.fail("Test should throw exception!"); + fail("Test should throw exception!"); } catch (FrejaEidClientPollingException ex) { assertEquals("A timeout of 2s was reached while sending request.", ex.getLocalizedMessage()); } @@ -270,7 +280,7 @@ public void getSignResults_expectError() throws FrejaEidClientInternalException, SignResultsRequest signResultsRequest = SignResultsRequest.create(RELYING_PARTY_ID); try { signClient.getResults(signResultsRequest); - Assert.fail("Test should throw exception!"); + fail("Test should throw exception!"); } catch (FrejaEidException rpEx) { verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.SIGN_GET_RESULTS, RequestTemplate.SIGN_RESULTS_TEMPLATE, signResultsRequest, @@ -293,18 +303,21 @@ private void getSignResults_success(SignResultsRequest signResultsRequest) assertEquals(TransactionStatus.STARTED, firstResponse.getStatus()); assertEquals(SIGN_DETAILS, firstResponse.getDetails()); assertEquals(REQUESTED_ATTRIBUTES, firstResponse.getRequestedAttributes()); + assertEquals(FREJA_COOKIE, firstResponse.getFrejaCookie()); SignResult secondResponse = response.get(1); assertEquals(SIGN_REFERENCE, secondResponse.getSignRef()); assertEquals(TransactionStatus.DELIVERED_TO_MOBILE, secondResponse.getStatus()); assertEquals("test", secondResponse.getDetails()); - Assert.assertNull(secondResponse.getRequestedAttributes()); + assertNull(secondResponse.getRequestedAttributes()); + assertNull(secondResponse.getFrejaCookie()); } private SignResults prepareResponse() { SignResult response1 = - new SignResult(SIGN_REFERENCE, TransactionStatus.STARTED, SIGN_DETAILS, REQUESTED_ATTRIBUTES); - SignResult response2 = new SignResult(SIGN_REFERENCE, TransactionStatus.DELIVERED_TO_MOBILE, "test", null); + new SignResult(SIGN_REFERENCE, TransactionStatus.STARTED, SIGN_DETAILS, REQUESTED_ATTRIBUTES, + FREJA_COOKIE); + SignResult response2 = new SignResult(SIGN_REFERENCE, TransactionStatus.DELIVERED_TO_MOBILE, "test", null, null); List responses = new ArrayList<>(); responses.add(response1); responses.add(response2); diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/AuthenticationClientHttpTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/AuthenticationClientHttpTest.java index 9a95670..6c109c0 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/AuthenticationClientHttpTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/AuthenticationClientHttpTest.java @@ -37,9 +37,10 @@ public class AuthenticationClientHttpTest extends CommonHttpTest { public static void init() throws FrejaEidClientInternalException { jsonService = new JsonService(); initiateAuthenticationResponse = new InitiateAuthenticationResponse(REFERENCE); - authenticationResult = new AuthenticationResult(REFERENCE, TransactionStatus.STARTED, null, null); + authenticationResult = new AuthenticationResult(REFERENCE, TransactionStatus.STARTED, null, null, null); authenticationResultWithRequestedAttributes = - new AuthenticationResult(REFERENCE, TransactionStatus.APPROVED, DETAILS, REQUESTED_ATTRIBUTES); + new AuthenticationResult(REFERENCE, TransactionStatus.APPROVED, DETAILS, REQUESTED_ATTRIBUTES, + FREJA_COOKIE); authenticationResults = new AuthenticationResults(Arrays.asList(authenticationResult)); authenticationClient = AuthenticationClient.create(TestUtil.getDefaultSslSettings(), FrejaEnvironment.TEST) .setTestModeServerCustomUrl("http://localhost:" + MOCK_SERVICE_PORT) diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/CommonHttpTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/CommonHttpTest.java index b2938d8..8f0c48c 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/CommonHttpTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/CommonHttpTest.java @@ -63,6 +63,7 @@ public abstract class CommonHttpTest { new CovidCertificates(new Vaccines("covidCertificate"), null, null, true); private static final String DOCUMENT_PHOTO = "Base64EncodedDocPhoto"; private static final NetworkInfo NETWORK_INFO = new NetworkInfo("123.45.6.7"); + protected static final String FREJA_COOKIE = "frejaCookie"; protected static final RequestedAttributes REQUESTED_ATTRIBUTES = new RequestedAttributes(BASIC_USER_INFO, CUSTOM_IDENTIFIER, SSN_USER_INFO, null, DATE_OF_BIRTH, RELYING_PARTY_USER_ID, EMAIL_ADDRESS, ORGANISATION_ID, ADDRESSES, diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/OrganisationIdClientHttpTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/OrganisationIdClientHttpTest.java index 7ae38f9..72ab0d4 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/OrganisationIdClientHttpTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/OrganisationIdClientHttpTest.java @@ -44,7 +44,7 @@ public class OrganisationIdClientHttpTest extends CommonHttpTest { public static void init() throws FrejaEidClientInternalException { jsonService = new JsonService(); initiateAddOrganisationIdResponse = new InitiateAddOrganisationIdResponse(REFERENCE); - organisationIdResult = new OrganisationIdResult(REFERENCE, TransactionStatus.STARTED, null); + organisationIdResult = new OrganisationIdResult(REFERENCE, TransactionStatus.STARTED, null, null); OrganisationIdUserInfo organisationIdUserInfo = new OrganisationIdUserInfo(OrganisationId.create(ORGANISATION_ID_TITLE, IDENTIFIER_NAME, IDENTIFIER), SSN_USER_INFO, RegistrationState.EXTENDED); diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/SignClientHttpTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/SignClientHttpTest.java index 81dc9bf..a0de6d1 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/SignClientHttpTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/SignClientHttpTest.java @@ -53,9 +53,9 @@ public static void init() throws FrejaEidClientInternalException { dataToSignText = "Data to sign"; binaryData = "binaryData".getBytes(StandardCharsets.UTF_8); initiateSignResponse = new InitiateSignResponse(REFERENCE); - signResult = new SignResult(REFERENCE, TransactionStatus.STARTED, null, null); + signResult = new SignResult(REFERENCE, TransactionStatus.STARTED, null, null, null); signResultWithRequestedAttributes = new SignResult(REFERENCE, TransactionStatus.APPROVED, DETAILS, - REQUESTED_ATTRIBUTES); + REQUESTED_ATTRIBUTES, FREJA_COOKIE); signResults = new SignResults(Arrays.asList(signResult)); signClient = SignClient.create(TestUtil.getDefaultSslSettings(), FrejaEnvironment.TEST)