Skip to content

Commit

Permalink
[OKTA-15] #resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Apr 26, 2024
1 parent 19bab98 commit c196a6f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
fit/nbactions.xml
fit/nb-configuration.xml
**/nbactions.xml
**/nb-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -913,54 +913,48 @@ private void updateUserAttributes(final User user, final Set<Attribute> replaceA
ObjectClassInfo objectClassInfo = schema.getSchema().findObjectClassInfo(ObjectClass.ACCOUNT_NAME);
replaceAttributes.stream().
filter(attribute -> !NOT_FOR_PROFILE.contains(attribute.getName())).
forEach(attribute -> objectClassInfo.getAttributeInfo().stream().
filter(attr -> attr.getName().equals(attribute.getName())).findFirst().
ifPresent(attributeInfo -> {
forEach(attr -> objectClassInfo.getAttributeInfo().stream().
filter(attrInfo -> attrInfo.getName().equals(attr.getName())).findFirst().
ifPresent(attrInfo -> {

if (!CollectionUtil.isEmpty(attribute.getValue())) {
if (OktaAttribute.BASIC_PROFILE_ATTRIBUTES.contains(attribute.getName())) {
switch (attributeInfo.getName()) {
case OktaAttribute.FIRSTNAME:
user.getProfile().setFirstName(AttributeUtil.getStringValue(attribute));
break;
if (OktaAttribute.BASIC_PROFILE_ATTRIBUTES.contains(attr.getName())) {
String value = CollectionUtil.isEmpty(attr.getValue())
? null
: AttributeUtil.getStringValue(attr);

case OktaAttribute.LASTNAME:
user.getProfile().setLastName(AttributeUtil.getStringValue(attribute));
break;
switch (attrInfo.getName()) {
case OktaAttribute.FIRSTNAME:
user.getProfile().setFirstName(value);
break;

case OktaAttribute.LASTNAME:
user.getProfile().setLastName(value);
break;

case OktaAttribute.EMAIL:
user.getProfile().setEmail(AttributeUtil.getStringValue(attribute));
break;
case OktaAttribute.EMAIL:
user.getProfile().setEmail(value);
break;

case OktaAttribute.LOGIN:
user.getProfile().setLogin(AttributeUtil.getStringValue(attribute));
break;
case OktaAttribute.LOGIN:
user.getProfile().setLogin(value);
break;

case OktaAttribute.MOBILEPHONE:
user.getProfile().setMobilePhone(AttributeUtil.getStringValue(attribute));
break;
case OktaAttribute.MOBILEPHONE:
user.getProfile().setMobilePhone(value);
break;

case OktaAttribute.SECOND_EMAIL:
user.getProfile().setSecondEmail(AttributeUtil.getStringValue(attribute));
break;
case OktaAttribute.SECOND_EMAIL:
user.getProfile().setSecondEmail(value);
break;

default:
}
} else {
if (Boolean.class.isInstance(attributeInfo.getType())) {
user.getProfile().getAdditionalProperties().
put(attribute.getName(), AttributeUtil.getBooleanValue(attribute));
} else if (Integer.class.isInstance(attributeInfo.getType())) {
user.getProfile().getAdditionalProperties().
put(attribute.getName(), AttributeUtil.getIntegerValue(attribute));
} else if (String.class.isInstance(attributeInfo.getType())) {
user.getProfile().getAdditionalProperties().
put(attribute.getName(), AttributeUtil.getStringValue(attribute));
} else {
user.getProfile().getAdditionalProperties().
put(attribute.getName(), AttributeUtil.getSingleValue(attribute));
}
default:
}
} else {
user.getProfile().getAdditionalProperties().put(
attr.getName(),
CollectionUtil.isEmpty(attr.getValue())
? null
: AttributeUtil.getSingleValue(attr));
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ public void crudUser() {
assertEquals(Collections.singletonList("{}"), entitlements.getValue());
LOG.info("Created User with id {0} on Okta", handler.getObjects().get(0).getUid());

// UPDATE USER
// UPDATE USER - change attribute
Attribute newMobilePhone = AttributeBuilder.build(OktaAttribute.MOBILEPHONE, "987654321");
userAttrs.remove(mobilePhone);
userAttrs.remove(password);
userAttrs.add(newMobilePhone);
Uid updated = FACADE.update(ObjectClass.ACCOUNT, created, userAttrs, operationOption);
assertNotNull(updated);
assertEquals(created, updated);

// GET USER
handler = new ToListResultsHandler();
Expand All @@ -304,6 +304,21 @@ public void crudUser() {
AttributeUtil.getAsStringValue(
handler.getObjects().get(0).getAttributeByName(OktaAttribute.MOBILEPHONE)));

// UPDATE USER - remove attribute
Attribute noMobilePhone = AttributeBuilder.build(OktaAttribute.MOBILEPHONE);
userAttrs.remove(newMobilePhone);
userAttrs.add(noMobilePhone);
updated = FACADE.update(ObjectClass.ACCOUNT, created, userAttrs, operationOption);
assertEquals(created, updated);

// GET USER
handler = new ToListResultsHandler();
FACADE.search(ObjectClass.ACCOUNT, filter, handler, operationOption);
assertNotNull(handler.getObjects());
assertFalse(handler.getObjects().isEmpty());
assertEquals(handler.getObjects().get(0).getUid().getUidValue(), created.getUidValue());
assertNull(handler.getObjects().get(0).getAttributeByName(OktaAttribute.MOBILEPHONE).getValue());

// DELETE USER
FACADE.delete(ObjectClass.ACCOUNT, updated, operationOption);

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<cargo.log>${log.directory}/cargo.log</cargo.log>
<cargo.output>${log.directory}/cargo-output.log</cargo.output>

<tomcat.version>9.0.87</tomcat.version>
<tomcat.version>9.0.88</tomcat.version>

<java.version>1.8</java.version>
<rootpom.basedir>${basedir}</rootpom.basedir>
Expand Down

0 comments on commit c196a6f

Please sign in to comment.