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

feat: include jansDeviceData in SCIM Fido2Resource schema #4115

Merged
merged 1 commit into from
Mar 9, 2023
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
@@ -0,0 +1,96 @@
package io.jans.scim.model.scim2.fido;

import io.jans.scim.model.scim2.annotations.Attribute;
import io.jans.scim.model.scim2.AttributeDefinition;

public class DeviceData {

@Attribute(description = "", mutability = AttributeDefinition.Mutability.IMMUTABLE)
private String uuid;

@Attribute(description = "", mutability = AttributeDefinition.Mutability.IMMUTABLE)
private String pushToken;

@Attribute(description = "", mutability = AttributeDefinition.Mutability.IMMUTABLE)
private String type;

@Attribute(description = "", mutability = AttributeDefinition.Mutability.IMMUTABLE)
private String platform;

@Attribute(description = "", mutability = AttributeDefinition.Mutability.IMMUTABLE)
private String name;

@Attribute(description = "", mutability = AttributeDefinition.Mutability.IMMUTABLE)
private String osName;

@Attribute(description = "", mutability = AttributeDefinition.Mutability.IMMUTABLE)
private String osVersion;

@Attribute(description = "", mutability = AttributeDefinition.Mutability.IMMUTABLE)
private String customData;

public String getUuid() {
return uuid;
}

public String getPushToken() {
return pushToken;
}

public String getType() {
return type;
}

public String getPlatform() {
return platform;
}

public String getName() {
return name;
}

public String getOsName() {
return osName;
}

public String getOsVersion() {
return osVersion;
}

public String getCustomData() {
return customData;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

public void setPushToken(String pushToken) {
this.pushToken = pushToken;
}

public void setType(String type) {
this.type = type;
}

public void setPlatform(String platform) {
this.platform = platform;
}

public void setName(String name) {
this.name = name;
}

public void setOsName(String osName) {
this.osName = osName;
}

public void setOsVersion(String osVersion) {
this.osVersion = osVersion;
}

public void setCustomData(String customData) {
this.customData = customData;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public class Fido2DeviceResource extends BaseScimResource {
@StoreReference(ref = "jansStatus")
private String status;

@Attribute(description = "Device data for Super Gluu enrollment",
mutability = AttributeDefinition.Mutability.IMMUTABLE,
type = AttributeDefinition.Type.COMPLEX)
@StoreReference(ref = "jansDeviceData")
private DeviceData deviceData;

@Attribute
@StoreReference(ref = "displayName")
private String displayName;
Expand Down Expand Up @@ -87,4 +93,12 @@ public void setDisplayName(String displayName) {
this.displayName = displayName;
}

public DeviceData getDeviceData() {
return deviceData;
}

public void setDeviceData(DeviceData deviceData) {
this.deviceData = deviceData;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
import static io.jans.scim.model.scim2.Constants.QUERY_PARAM_START_INDEX;
import static io.jans.scim.model.scim2.Constants.UTF8_CHARSET_FRAGMENT;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.time.Instant;

import jakarta.annotation.PostConstruct;
Expand All @@ -39,8 +44,10 @@
import org.apache.commons.lang.StringUtils;

import io.jans.scim.model.exception.SCIMException;
import io.jans.scim.model.fido2.Fido2DeviceData;
import io.jans.scim.model.GluuFido2Device;
import io.jans.scim.model.scim2.*;
import io.jans.scim.model.scim2.fido.DeviceData;
import io.jans.scim.model.scim2.fido.Fido2DeviceResource;
import io.jans.scim.model.scim2.patch.PatchRequest;
import io.jans.scim.model.scim2.util.DateUtil;
Expand Down Expand Up @@ -74,6 +81,8 @@ public class Fido2DeviceWebService extends BaseScimWebService implements IFido2D
private PersistenceEntryManager entryManager;

private String fido2ResourceType;

private ObjectMapper mapper;

private Response doSearchDevices(String userId, String filter, Integer startIndex,
Integer count, String sortBy, String sortOrder, String attrsList, String excludedAttrsList,
Expand Down Expand Up @@ -314,9 +323,30 @@ private void transferAttributesToFido2Resource(GluuFido2Device fidoDevice, Fido2
res.setStatus(fidoDevice.getRegistrationStatus());
res.setDisplayName(fidoDevice.getDisplayName());

Fido2DeviceData f2dd = fidoDevice.getDeviceData();
if (f2dd != null) {
DeviceData dd = new DeviceData();
dd.setUuid(f2dd.getUuid());
dd.setPushToken(f2dd.getPushToken());
dd.setType(f2dd.getType());
dd.setPlatform(f2dd.getPlatform());
dd.setName(f2dd.getName());
dd.setOsName(f2dd.getOsName());
dd.setOsVersion(f2dd.getOsVersion());

try {
if (f2dd.getCustomData() != null) {
dd.setCustomData(mapper.writeValueAsString(f2dd.getCustomData()));
}
} catch (JsonProcessingException e) {
log.error(e.getMessage(), e);
}
res.setDeviceData(dd);
}

}

private void transferAttributesToDevice(Fido2DeviceResource res, GluuFido2Device device){
private void transferAttributesToDevice(Fido2DeviceResource res, GluuFido2Device device) {

device.setId(res.getId());

Expand All @@ -326,6 +356,21 @@ private void transferAttributesToDevice(Fido2DeviceResource res, GluuFido2Device

Instant instant = Instant.parse(res.getMeta().getLastModified());
device.getRegistrationData().setUpdatedDate(new Date(instant.toEpochMilli()));

DeviceData deviceData = res.getDeviceData();
if (deviceData != null) {
Map<String, String> customData = null;

try {
if (deviceData.getCustomData() != null) {
customData = mapper.readValue(deviceData.getCustomData(), new TypeReference<Map<String, String>>(){});
}
} catch (JsonProcessingException e) {
log.error(e.getMessage(), e);
}
device.setDeviceData(new Fido2DeviceData(deviceData.getUuid(), deviceData.getPushToken(), deviceData.getType(),
deviceData.getPlatform(), deviceData.getName(), deviceData.getOsName(), deviceData.getOsVersion(), customData));
}

}

Expand Down Expand Up @@ -387,9 +432,10 @@ public Response patchF2Device(
}

@PostConstruct
public void setup(){
public void setup() {
init(Fido2DeviceWebService.class);
fido2ResourceType = ScimResourceUtil.getType(Fido2DeviceResource.class);
mapper = new ObjectMapper();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

package io.jans.scim.model;

import java.io.Serializable;
import java.util.Date;

import io.jans.scim.model.fido2.Fido2DeviceData;
import io.jans.scim.model.fido2.Fido2Data;
import io.jans.scim.model.fido2.Fido2Entry;
import io.jans.orm.annotation.AttributeName;
import io.jans.orm.annotation.DataEntry;
import io.jans.orm.annotation.JsonObject;
import io.jans.orm.annotation.ObjectClass;

import java.io.Serializable;
import java.util.Date;

@SuppressWarnings("serial")
@DataEntry
@ObjectClass(value = "jansFido2RegistrationEntry")
Expand All @@ -31,6 +32,10 @@ public class GluuFido2Device extends Fido2Entry implements Serializable {
@AttributeName(name = "displayName")
private String displayName;

@JsonObject
@AttributeName(name = "jansDeviceData")
private Fido2DeviceData deviceData;

public GluuFido2Device() {
}

Expand Down Expand Up @@ -64,4 +69,12 @@ public void setDisplayName(String displayName) {
this.displayName = displayName;
}

public Fido2DeviceData getDeviceData() {
return deviceData;
}

public void setDeviceData(Fido2DeviceData deviceData) {
this.deviceData = deviceData;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text.
*
* Copyright (c) 2020, Janssen Project
*/

package io.jans.scim.model.fido2;

import java.io.Serializable;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* FIDO2 device data
*
* @author Yuriy Movchan Date: 02/16/2016
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class Fido2DeviceData implements Serializable {

private static final long serialVersionUID = -8173244116167488365L;

@JsonProperty(value = "uuid")
private final String uuid;

@JsonProperty(value = "push_token")
private final String pushToken;

@JsonProperty(value = "type")
private final String type;

@JsonProperty(value = "platform")
private final String platform;

@JsonProperty(value = "name")
private final String name;

@JsonProperty(value = "os_name")
private final String osName;

@JsonProperty(value = "os_version")
private final String osVersion;

@JsonProperty(value = "custom_data")
private final Map<String, String> customData;

public Fido2DeviceData(@JsonProperty(value = "uuid") String uuid, @JsonProperty(value = "token") String pushToken,
@JsonProperty(value = "type") String type, @JsonProperty(value = "platform") String platform,
@JsonProperty(value = "name") String name, @JsonProperty(value = "os_name") String osName,
@JsonProperty(value = "os_version") String osVersion, @JsonProperty(value = "custom_data") Map<String, String> customData) {
this.uuid = uuid;
this.pushToken = pushToken;
this.type = type;
this.platform = platform;
this.name = name;
this.osName = osName;
this.osVersion = osVersion;
this.customData = customData;
}

public String getUuid() {
return uuid;
}

public String getPushToken() {
return pushToken;
}

public String getType() {
return type;
}

public String getPlatform() {
return platform;
}

public String getName() {
return name;
}

public String getOsName() {
return osName;
}

public String getOsVersion() {
return osVersion;
}

public final Map<String, String> getCustomData() {
return customData;
}

@Override
public String toString() {
return "DeviceData [uuid=" + uuid + ", pushToken=" + pushToken + ", type=" + type + ", platform=" + platform + ", name=" + name + ", osName="
+ osName + ", osVersion=" + osVersion + ", customData=" + customData + "]";
}

}