Skip to content

Commit

Permalink
Added support for OriginDeviceDetails and Freja Cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkostojmenovic-frejaeid committed Oct 23, 2024
1 parent 5790fc7 commit ba424e2
Show file tree
Hide file tree
Showing 20 changed files with 377 additions and 130 deletions.
2 changes: 1 addition & 1 deletion FrejaEidClient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.verisec.frejaeid</groupId>
<artifactId>FrejaEidClient</artifactId>
<version>2.25.1-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>FrejaEidClient</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
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 {

@JsonCreator
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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down Expand Up @@ -73,21 +75,26 @@ private InitiateAuthenticationRequest(
@JsonProperty(value = "minRegistrationLevel") MinRegistrationLevel minRegistrationLevel,
@JsonProperty(value = "attributesToReturn") Set<AttributeToReturnInfo> 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<AttributeToReturnInfo> attributesToReturn, String relyingPartyId,
String orgIdIssuer, UserConfirmationMethod userConfirmationMethod) {
String orgIdIssuer, UserConfirmationMethod userConfirmationMethod,
OriginDeviceDetails originDeviceDetails) {
this.userInfoType = userInfoType;
this.userInfo = userInfo;
this.minRegistrationLevel = minRegistrationLevel;
this.attributesToReturn = attributesToReturn;
this.relyingPartyId = relyingPartyId;
this.orgIdIssuer = orgIdIssuer;
this.userConfirmationMethod = userConfirmationMethod;
this.originDeviceDetails = originDeviceDetails;

}

@JsonIgnore
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
+ '}';
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,47 +15,42 @@ 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) {
return new SetOptionalParamsBuilder(UserInfoType.EMAIL, 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) {
return new SetOptionalParamsBuilder(UserInfoType.PHONE, phoneNumber);
}

/**
* Sets {@linkplain UserInfoType#INFERRED} as {@linkplain UserInfoType}
* for initiating transaction.
* Sets {@linkplain UserInfoType#INFERRED} as {@linkplain UserInfoType} for initiating transaction.
*
* @return request builder
*/
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -165,9 +161,22 @@ public SetOptionalParamsBuilder setUserConfirmationMethod(UserConfirmationMethod
return this;
}

/**
* <b>OriginDeviceDetails contains information about the end user device from which the transaction was
* initiated.</b>
*
* @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);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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
+ '}';
}

}
Loading

0 comments on commit ba424e2

Please sign in to comment.