Skip to content

Commit

Permalink
It is now possible to execute UPDATE / DELETE actions using 'userPrin…
Browse files Browse the repository at this point in the history
…cipalName' attribute as User ID - only for Users
  • Loading branch information
Matteo Alessandroni committed Mar 20, 2018
1 parent b8d9301 commit c82057c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,11 @@ public Uid update(ObjectClass objectClass, Uid uid, Set<Attribute> replaceAttrib
}

User user = new User();
user.setObjectId(uid.getUidValue());
if (uid.getUidValue().contains("@")) {
user.setUserPrincipalName(uid.getUidValue());
} else {
user.setObjectId(uid.getUidValue());
}

if (!uid.getUidValue().equals(userID)) {
LOG.info("Update - uid value different from user ID");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.tirasa.connid.bundles.azure.dto.User;
import net.tirasa.connid.bundles.azure.utils.AzureAttributes;
import net.tirasa.connid.bundles.azure.utils.AzureUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.jaxrs.client.WebClient;
import org.identityconnectors.common.StringUtil;
import org.identityconnectors.common.logging.Log;
Expand Down Expand Up @@ -598,12 +599,15 @@ private AzureObject doCreate(final AzureObject obj) {
}

private AzureObject doUpdate(final AzureObject obj) {
WebClient webClient = azureService.getWebclient(
(obj instanceof Group ? "groups" : "users") + "/" + obj.getObjectId(), null);
WebClient webClient;
AzureObject updated = obj;

if (updated instanceof User) {
User updatedUser = User.class.cast(updated);
webClient = azureService.getWebclient("users/"
+ (StringUtils.isBlank(updatedUser.getObjectId())
? updatedUser.getUserPrincipalName()
: updatedUser.getObjectId()), null);

// handle PasswordProfile object - password update
if ((updatedUser.getPassword() != null
Expand All @@ -615,6 +619,9 @@ private AzureObject doUpdate(final AzureObject obj) {
}

updated = updatedUser;
} else {
webClient = azureService.getWebclient("groups/"
+ obj.getObjectId(), null);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ public void crud() {

Thread.sleep(2000);

// UPDATE USER
// UPDATE USER (using 'objectId' attribute)
username = UUID.randomUUID().toString();
boolean newStatusValue = false;

userAttrs.clear();
userAttrs.add(AttributeBuilder.build(AzureAttributes.USER_DISPLAY_NAME, username));
userAttrs.add(AttributeBuilder.build(AzureAttributes.USER_ID, testUserUid)); // important
userAttrs.add(AttributeBuilder.build(AzureAttributes.USER_ID, testUserUid));
// '__ENABLE__' attribute update
userAttrs.add(AttributeBuilder.build(AzureAttributes.USER_ACCOUNT_ENABLED, newStatusValue));

Expand All @@ -363,15 +363,35 @@ public void crud() {
assertEquals(created.getUidValue(), updated.getUidValue());
assertNotEquals(user.getDisplayName(), username);

// GET NEW USER TO CHECK 'accountEnabled' UPDATE
// GET NEW USER (to check 'accountEnabled' update)
assertNotEquals(user.getAccountEnabled(), newStatusValue);
User updatedUser = client.getAuthenticated().getUser(testUserUid);
assertEquals(updatedUser.getAccountEnabled(), newStatusValue);

LOG.info("Updated User with old name {0} and new name {1}",
user.getDisplayName(), username);

// UPDATE USER (using 'userPrincipalName' attribute)
String anotherUsername = UUID.randomUUID().toString();

userAttrs.clear();
userAttrs.add(AttributeBuilder.build(AzureAttributes.USER_DISPLAY_NAME, anotherUsername));
userAttrs.add(AttributeBuilder.build(AzureAttributes.USER_PRINCIPAL_NAME, user.getUserPrincipalName()));

updated = connector.update(
ObjectClass.ACCOUNT, new Uid(testUserUid), userAttrs, new OperationOptionsBuilder().build());
assertNotNull(updated);
assertEquals(created.getUidValue(), updated.getUidValue());
assertNotEquals(updatedUser.getDisplayName(), anotherUsername);

// GET NEW USER (to check update using 'userPrincipalName' attribute)
User anotherUpdatedUser = client.getAuthenticated().getUser(testUserUid);
assertEquals(anotherUpdatedUser.getUserPrincipalName(), user.getUserPrincipalName());

testUserUid = updated.getUidValue();

LOG.info("Updated User with old name {0} and new name {1}",
user.getDisplayName(), username);
user.getDisplayName(), anotherUsername);

// GET ALL USERS
List<User> users = client.getAuthenticated().getAllUsers();
Expand Down

0 comments on commit c82057c

Please sign in to comment.