From c196a6fc0868314f093a038e54c78d5526bbf071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Fri, 26 Apr 2024 09:15:53 +0200 Subject: [PATCH] [OKTA-15] #resolve --- .gitignore | 4 +- .../connid/bundles/okta/OktaConnector.java | 74 +++++++++---------- .../bundles/okta/OktaConnectorTests.java | 19 ++++- pom.xml | 2 +- 4 files changed, 54 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index cf4254c..a6e107f 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/connector/src/main/java/net/tirasa/connid/bundles/okta/OktaConnector.java b/connector/src/main/java/net/tirasa/connid/bundles/okta/OktaConnector.java index 4900c49..37a6160 100644 --- a/connector/src/main/java/net/tirasa/connid/bundles/okta/OktaConnector.java +++ b/connector/src/main/java/net/tirasa/connid/bundles/okta/OktaConnector.java @@ -913,54 +913,48 @@ private void updateUserAttributes(final User user, final Set 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)); } })); } diff --git a/fit/src/test/java/net/tirasa/connid/bundles/okta/OktaConnectorTests.java b/fit/src/test/java/net/tirasa/connid/bundles/okta/OktaConnectorTests.java index 21be0f3..f484732 100644 --- a/fit/src/test/java/net/tirasa/connid/bundles/okta/OktaConnectorTests.java +++ b/fit/src/test/java/net/tirasa/connid/bundles/okta/OktaConnectorTests.java @@ -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(); @@ -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); diff --git a/pom.xml b/pom.xml index 113f851..7ec7f32 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,7 @@ ${log.directory}/cargo.log ${log.directory}/cargo-output.log - 9.0.87 + 9.0.88 1.8 ${basedir}