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

[SCIM-32] added parameter to switch between colon and dot for extension attributes names #103

Merged
merged 2 commits into from
Jan 8, 2025
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 @@ -347,14 +347,17 @@ public Uid create(

// custom attributes
if (StringUtil.isNotBlank(configuration.getCustomAttributesJSON())) {
user.fillSCIMCustomAttributes(createAttributes, configuration.getCustomAttributesJSON());
user.fillSCIMCustomAttributes(
createAttributes,
configuration.getCustomAttributesJSON(),
configuration.getUseColonOnExtensionAttributes());
}
// enterprise user
createAttributes.stream().
filter(ca -> ca.getName().contains(SCIMv2EnterpriseUser.SCHEMA_URI)).
findFirst().ifPresent(ca -> {
user.getSchemas().add(SCIMv2EnterpriseUser.SCHEMA_URI);
user.fillEnterpriseUser(createAttributes);
user.fillEnterpriseUser(createAttributes, configuration.getUseColonOnExtensionAttributes());
});

client.createUser(user);
Expand Down Expand Up @@ -436,13 +439,16 @@ public Uid update(

// custom attributes
if (StringUtil.isNotBlank(configuration.getCustomAttributesJSON())) {
user.fillSCIMCustomAttributes(replaceAttributes, configuration.getCustomAttributesJSON());
user.fillSCIMCustomAttributes(
replaceAttributes,
configuration.getCustomAttributesJSON(),
configuration.getUseColonOnExtensionAttributes());
}
// enterprise user
replaceAttributes.stream().filter(ca -> ca.getName().contains(SCIMv2EnterpriseUser.SCHEMA_URI)).findFirst()
.ifPresent(ca -> {
user.getSchemas().add(SCIMv2EnterpriseUser.SCHEMA_URI);
user.fillEnterpriseUser(replaceAttributes);
user.fillEnterpriseUser(replaceAttributes, configuration.getUseColonOnExtensionAttributes());
});

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class SCIMConnectorConfiguration extends AbstractConfiguration implements
private String updateGroupMethod = "PUT";

private boolean explicitGroupAddOnCreate = false;

private boolean replaceMembersOnUpdate = false;

private String accept = MediaType.APPLICATION_JSON;
Expand Down Expand Up @@ -93,9 +93,11 @@ public class SCIMConnectorConfiguration extends AbstractConfiguration implements
private String proxyServerPassword;

private boolean followHttpRedirects = false;

private boolean requestAttributesOnSearch = true;

private boolean useColonOnExtensionAttributes = true;

@ConfigurationProperty(order = 1,
displayMessageKey = "baseAddress.display",
helpMessageKey = "baseAddress.help",
Expand Down Expand Up @@ -390,6 +392,17 @@ public void setRequestAttributesOnSearch(final boolean requestAttributesOnSearch
this.requestAttributesOnSearch = requestAttributesOnSearch;
}

@ConfigurationProperty(displayMessageKey = "useColonOnExtensionAttributes.display",
helpMessageKey = "useColonOnExtensionAttributes.help",
order = 28)
public boolean getUseColonOnExtensionAttributes() {
return useColonOnExtensionAttributes;
}

public void setUseColonOnExtensionAttributes(final boolean useColonOnExtensionAttributes) {
this.useColonOnExtensionAttributes = useColonOnExtensionAttributes;
}

@Override
public void validate() {
if (StringUtil.isBlank(baseAddress)) {
Expand Down Expand Up @@ -438,9 +451,9 @@ public void validate() {
} catch (Exception e) {
failValidation("Unsupported SCIM provider: " + scimProvider);
}
if (StringUtil.isNotBlank(proxyServerHost) && (
StringUtil.isBlank(proxyServerType)
|| proxyServerPort == null)) {
if (StringUtil.isNotBlank(proxyServerHost)
&& (StringUtil.isBlank(proxyServerType) || proxyServerPort == null)) {

failValidation("Proxy server type and port cannot be null or empty if host is specified.");
}
if (StringUtil.isNotBlank(proxyServerType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,10 @@ public Set<Attribute> toAttributes(final Class<?> type, final SCIMConnectorConfi
// manage enterprise user
if (SCIMEnterpriseUser.class.isAssignableFrom(field.getType()) && getEnterpriseUser() != null) {
field.setAccessible(true);
addAttribute(getEnterpriseUser().toAttributes(SCIMv2EnterpriseUser.SCHEMA_URI), attrs,
addAttribute(getEnterpriseUser().toAttributes(
SCIMv2EnterpriseUser.SCHEMA_URI,
conf.getUseColonOnExtensionAttributes()),
attrs,
field.getType());
} else if (!field.isAnnotationPresent(JsonIgnore.class) && !SCIMUtils.isEmptyObject(field.get(this))) {
Object objInstance = field.get(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public interface SCIMEnterpriseUser<T extends Serializable> extends Serializable

void setManager(T manager);

Set<Attribute> toAttributes(String id) throws IllegalArgumentException, IllegalAccessException;
Set<Attribute> toAttributes(String schemaUri, boolean useColon)
throws IllegalArgumentException, IllegalAccessException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public interface SCIMUser<MT extends SCIMBaseMeta, EUT extends SCIMEnterpriseUse
String getDisplayName();

void setDisplayName(String displayName);
void fillSCIMCustomAttributes(Set<Attribute> createAttributes, String customAttributesJSON);

void fillSCIMCustomAttributes(Set<Attribute> createAttributes, String customAttributesJSON, boolean useColon);

Map<String, List<Object>> getReturnedCustomAttributes();

Map<? extends SCIMBaseAttribute<?>, List<Object>> getSCIMCustomAttributes();

EUT getEnterpriseUser();

void fillEnterpriseUser(Set<Attribute> attributes);
void fillEnterpriseUser(Set<Attribute> attributes, boolean useColon);

void setEnterpriseUser(EUT enterpriseUser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ protected <T extends SCIMBaseAttribute<T>> void readCustomAttributes(
(attr instanceof SCIMv2Attribute
? SCIMv2Attribute.class.cast(attr).getExtensionSchema()
: SCIMv11Attribute.class.cast(attr).getSchema())
+ "." + attr.getName(),
+ (config.getUseColonOnExtensionAttributes() ? ":" : ".") + attr.getName(),
values);
}
}
Expand Down Expand Up @@ -592,7 +592,7 @@ public List<UT> getAllUsers(final Set<String> attributesToGet) {
Map<String, String> params = new HashMap<>();
if (!attributesToGet.isEmpty() && config.getRequestAttributesOnSearch()) {
params.put("attributes", SCIMUtils.cleanAttributesToGet(attributesToGet, config.getCustomAttributesJSON(),
SCIMv2Attribute.class));
config.getUseColonOnExtensionAttributes(), SCIMv2Attribute.class));
}
WebClient webClient = getWebclient("Users", params);
return doGetAllUsers(webClient).getResources();
Expand All @@ -609,7 +609,7 @@ public List<UT> getAllUsers(final String filterQuery, final Set<String> attribut
params.put("filter", filterQuery);
if (!attributesToGet.isEmpty() && config.getRequestAttributesOnSearch()) {
params.put("attributes", SCIMUtils.cleanAttributesToGet(attributesToGet, config.getCustomAttributesJSON(),
SCIMv2Attribute.class));
config.getUseColonOnExtensionAttributes(), SCIMv2Attribute.class));
}
WebClient webClient = getWebclient("Users", params);
return doGetAllUsers(webClient).getResources();
Expand All @@ -631,8 +631,8 @@ public PagedResults<UT> getAllUsers(
params.put("startIndex", String.valueOf(startIndex));
Optional.ofNullable(count).ifPresent(c -> params.put("count", String.valueOf(c)));
if (!attributesToGet.isEmpty() && config.getRequestAttributesOnSearch()) {
params.put("attributes", SCIMUtils.cleanAttributesToGet(
attributesToGet, config.getCustomAttributesJSON(), SCIMv2Attribute.class));
params.put("attributes", SCIMUtils.cleanAttributesToGet(attributesToGet, config.getCustomAttributesJSON(),
config.getUseColonOnExtensionAttributes(), SCIMv2Attribute.class));
}
WebClient webClient = getWebclient("Users", params);
return doGetAllUsers(webClient);
Expand All @@ -658,6 +658,7 @@ public PagedResults<UT> getAllUsers(final String filterQuery, final Integer star
params.put("attributes",
SCIMUtils.cleanAttributesToGet(attributesToGet,
config.getCustomAttributesJSON(),
config.getUseColonOnExtensionAttributes(),
SCIMv2Attribute.class));
}
WebClient webClient = getWebclient("Users", params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,27 +288,27 @@ public static <T extends SCIMBaseAttribute<T>> Schema buildSchema(
// enterprise user
if (SCIMv2Attribute.class.equals(attrType)) {
userBuilder.addAttributeInfo(
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ".employeeNumber")
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ":employeeNumber")
.setMultiValued(false).build());
userBuilder.addAttributeInfo(
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ".costCenter").setMultiValued(false)
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ":costCenter").setMultiValued(false)
.build());
userBuilder.addAttributeInfo(
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ".organization").setMultiValued(false)
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ":organization").setMultiValued(false)
.build());
userBuilder.addAttributeInfo(
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ".division").setMultiValued(false)
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ":division").setMultiValued(false)
.build());
userBuilder.addAttributeInfo(
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ".department").setMultiValued(false)
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ":department").setMultiValued(false)
.build());
userBuilder.addAttributeInfo(AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ".manager.value")
userBuilder.addAttributeInfo(AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ":manager.value")
.setMultiValued(false).build());
userBuilder.addAttributeInfo(
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ".manager.ref").setMultiValued(false)
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ":manager.ref").setMultiValued(false)
.build());
userBuilder.addAttributeInfo(
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ".manager.displayName")
AttributeInfoBuilder.define(SCIMv2EnterpriseUser.SCHEMA_URI + ":manager.displayName")
.setMultiValued(false).build());
if (manageComplexEntitlements) {
userBuilder.addAttributeInfo(
Expand All @@ -317,13 +317,13 @@ public static <T extends SCIMBaseAttribute<T>> Schema buildSchema(
}
} else {
userBuilder.addAttributeInfo(
AttributeInfoBuilder.define(SCIMv11EnterpriseUser.SCHEMA_URI + ".employeeNumber")
AttributeInfoBuilder.define(SCIMv11EnterpriseUser.SCHEMA_URI + ":employeeNumber")
.setMultiValued(false).build());
userBuilder.addAttributeInfo(
AttributeInfoBuilder.define(SCIMv11EnterpriseUser.SCHEMA_URI + ".manager.managerId")
AttributeInfoBuilder.define(SCIMv11EnterpriseUser.SCHEMA_URI + ":manager.managerId")
.setMultiValued(false).build());
userBuilder.addAttributeInfo(
AttributeInfoBuilder.define(SCIMv11EnterpriseUser.SCHEMA_URI + ".manager.displayName")
AttributeInfoBuilder.define(SCIMv11EnterpriseUser.SCHEMA_URI + ":manager.displayName")
.setMultiValued(false).build());
}

Expand Down
Loading
Loading