Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-2367: Add support for advanced identity profiles to Share V1 #439

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ public class Policy {
@JsonProperty(Property.IDENTITY_PROFILE_REQUIREMENTS)
private final Object identityProfile;

@JsonProperty(Property.ADVANCED_IDENTITY_PROFILE_REQUIREMENTS)
private final Object advancedIdentityProfile;

private Policy(Builder builder) {
wantedAttributes = builder.wantedAttributes.values();
wantedAuthTypes = builder.wantedAuthTypes;
wantedRememberMe = builder.wantedRememberMe;
wantedRememberMeOptional = builder.wantedRememberMeOptional;
identityProfile = builder.identityProfile;
advancedIdentityProfile = builder.advancedIdentityProfile;
}

public Collection<WantedAttribute> getWantedAttributes() {
Expand All @@ -60,6 +64,10 @@ public Object getIdentityProfile() {
return identityProfile;
}

public Object getAdvancedIdentityProfile() {
return advancedIdentityProfile;
}

public static Builder builder() {
return new Builder();
}
Expand All @@ -75,6 +83,7 @@ public static class Builder {
private boolean wantedRememberMe;
private boolean wantedRememberMeOptional;
private Object identityProfile;
private Object advancedIdentityProfile;

private Builder() {
wantedAttributes = new HashMap<>();
Expand Down Expand Up @@ -266,6 +275,11 @@ public Builder withIdentityProfile(Object identityProfile) {
this.identityProfile = identityProfile;
return this;
}

public Builder withAdvancedIdentityProfile(Object advancedIdentityProfile) {
this.advancedIdentityProfile = advancedIdentityProfile;
return this;
}

public Policy build() {
return new Policy(this);
Expand All @@ -280,6 +294,7 @@ private static final class Property {
private static final String WANTED_REMEMBER_ME = "wanted_remember_me";
private static final String WANTED_REMEMBER_ME_OPTIONAL = "wanted_remember_me_optional";
private static final String IDENTITY_PROFILE_REQUIREMENTS = "identity_profile_requirements";
private static final String ADVANCED_IDENTITY_PROFILE_REQUIREMENTS = "advanced_identity_profile_requirements";

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Set of data required to request a sharing transaction
*/
public class DynamicPolicy {

@JsonProperty(Property.WANTED)
Expand All @@ -33,67 +30,46 @@ public class DynamicPolicy {
@JsonProperty(Property.IDENTITY_PROFILE_REQUIREMENTS)
private final Object identityProfile;

DynamicPolicy(Collection<WantedAttribute> wantedAttributes,
Set<Integer> wantedAuthTypes,
boolean wantedRememberMe,
boolean wantedRememberMeOptional,
Object identityProfile) {
this.wantedAttributes = wantedAttributes;
this.wantedAuthTypes = wantedAuthTypes;
this.wantedRememberMe = wantedRememberMe;
this.wantedRememberMeOptional = wantedRememberMeOptional;
this.identityProfile = identityProfile;
@JsonProperty(Property.ADVANCED_IDENTITY_PROFILE_REQUIREMENTS)
private final Object advancedIdentityProfile;

private DynamicPolicy(Builder builder) {
wantedAttributes = builder.wantedAttributes.values();
wantedAuthTypes = builder.wantedAuthTypes;
wantedRememberMe = builder.wantedRememberMe;
wantedRememberMeOptional = builder.wantedRememberMeOptional;
identityProfile = builder.identityProfile;
advancedIdentityProfile = builder.advancedIdentityProfile;
}

public static DynamicPolicy.Builder builder() {
return new DynamicPolicy.Builder();
}

/**
* Set of required {@link WantedAttribute}
*
* @return attributes
*/
public Collection<WantedAttribute> getWantedAttributes() {
return wantedAttributes;
}

/**
* Type of authentications
*
* @return authentication types
*/
public Set<Integer> getWantedAuthTypes() {
return wantedAuthTypes;
}

/**
* Allows to remember the {@link DynamicPolicy}
*
* @return RememberMe
*/
public boolean isWantedRememberMe() {
return wantedRememberMe;
}

/**
* Defines the {@link #isWantedRememberMe()} optional for the sharing
*
* @return RememberMeOptional
*/
public boolean isWantedRememberMeOptional() {
return wantedRememberMeOptional;
}

/**
* Defines a required identity profile within the scope of a trust framework and scheme.
*
* @return IdentityProfile
*/
public Object getIdentityProfile() {
return identityProfile;
}

public Object getAdvancedIdentityProfile() {
return advancedIdentityProfile;
}

public static class Builder {

private static final int SELFIE_AUTH_TYPE = 1;
Expand All @@ -104,6 +80,7 @@ public static class Builder {
private boolean wantedRememberMe;
private boolean wantedRememberMeOptional;
private Object identityProfile;
private Object advancedIdentityProfile;

private Builder() { }

Expand All @@ -114,7 +91,7 @@ public Builder withWantedAttribute(WantedAttribute wantedAttribute) {
key += "-" + wantedAttribute.getConstraints().hashCode();
}

this.wantedAttributes.put(key, wantedAttribute);
wantedAttributes.put(key, wantedAttribute);
return this;
}

Expand Down Expand Up @@ -245,11 +222,11 @@ public Builder withEmail(boolean optional) {
}

public Builder withSelfieAuthentication(boolean enabled) {
return this.withWantedAuthType(SELFIE_AUTH_TYPE, enabled);
return withWantedAuthType(SELFIE_AUTH_TYPE, enabled);
}

public Builder withPinAuthentication(boolean enabled) {
return this.withWantedAuthType(PIN_AUTH_TYPE, enabled);
return withWantedAuthType(PIN_AUTH_TYPE, enabled);
}

public Builder withWantedAuthType(int wantedAuthType) {
Expand All @@ -259,7 +236,7 @@ public Builder withWantedAuthType(int wantedAuthType) {

public Builder withWantedAuthType(int wantedAuthType, boolean enabled) {
if (enabled) {
return this.withWantedAuthType(wantedAuthType);
return withWantedAuthType(wantedAuthType);
} else {
this.wantedAuthTypes.remove(wantedAuthType);
return this;
Expand All @@ -280,15 +257,14 @@ public Builder withIdentityProfile(Object identityProfile) {
this.identityProfile = identityProfile;
return this;
}

public Builder withAdvancedIdentityProfile(Object advancedIdentityProfile) {
this.advancedIdentityProfile = advancedIdentityProfile;
return this;
}

public DynamicPolicy build() {
return new DynamicPolicy(
wantedAttributes.values(),
wantedAuthTypes,
wantedRememberMe,
wantedRememberMeOptional,
identityProfile
);
return new DynamicPolicy(this);
}

}
Expand All @@ -300,6 +276,7 @@ private static final class Property {
private static final String WANTED_REMEMBER_ME = "wanted_remember_me";
private static final String WANTED_REMEMBER_ME_OPTIONAL = "wanted_remember_me_optional";
private static final String IDENTITY_PROFILE_REQUIREMENTS = "identity_profile_requirements";
private static final String ADVANCED_IDENTITY_PROFILE_REQUIREMENTS = "advanced_identity_profile_requirements";

private Property() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

public final class IdentityProfile {

@JsonProperty("trust_framework")
@JsonProperty(Share.Policy.Profile.TRUST_FRAMEWORK)
private final String framework;

@JsonProperty("scheme")
@JsonProperty(Share.Policy.Profile.SCHEME)
private final IdentityProfileScheme scheme;

public IdentityProfile(String framework, IdentityProfileScheme scheme) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

public final class IdentityProfileScheme {

@JsonProperty("type")
@JsonProperty(Share.Policy.Profile.TYPE)
private final String type;

@JsonProperty("objective")
@JsonProperty(Share.Policy.Profile.OBJECTIVE)
private final String objective;

public IdentityProfileScheme(String type, String objective) {
Expand Down
35 changes: 35 additions & 0 deletions yoti-sdk-api/src/test/java/com/yoti/api/client/common/Share.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.yoti.api.client.common;

public final class Share {

public static final class Policy {

public static final class Profile {

private Profile() { }

public static final String TYPE = "type";
public static final String OBJECTIVE = "objective";
public static final String TRUST_FRAMEWORK = "trust_framework";

// identity profile only
public static final String SCHEME = "scheme";
public static final String IDENTITY_PROFILE_REQUIREMENTS = "identity_profile_requirements";

// advanced identity profile only
public static final String LABEL = "label";
public static final String FILTER = "filter";
public static final String CONFIG = "config";
public static final String SCHEMES = "schemes";
public static final String PROFILES = "profiles";
public static final String DOCUMENTS = "documents";
public static final String INCLUSION = "inclusion";
public static final String COUNTRY_CODES = "country_codes";
public static final String DOCUMENT_TYPES = "document_types";
public static final String ADVANCED_IDENTITY_PROFILE_REQUIREMENTS = "advanced_identity_profile_requirements";

}

}

}
Loading