From ff422d5d7bec43cf9d95ae896edb8f1bd27051e5 Mon Sep 17 00:00:00 2001 From: boleque Date: Tue, 19 Mar 2024 14:28:17 +0200 Subject: [PATCH] Added location attribute. Attribute is not mandatory, but widely used in dynamic groups. Also removed extra ADMIN_DIRECTORY_GROUP directory scope --- .../googleapps/GoogleAppsConfiguration.java | 1 - .../connector/googleapps/GoogleAppsConnector.java | 8 +++++++- .../polygon/connector/googleapps/UserHandler.java | 13 ++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/evolveum/polygon/connector/googleapps/GoogleAppsConfiguration.java b/src/main/java/com/evolveum/polygon/connector/googleapps/GoogleAppsConfiguration.java index 4bc81fe..c0ee11d 100644 --- a/src/main/java/com/evolveum/polygon/connector/googleapps/GoogleAppsConfiguration.java +++ b/src/main/java/com/evolveum/polygon/connector/googleapps/GoogleAppsConfiguration.java @@ -269,7 +269,6 @@ public void getGoogleCredential() { try (InputStream inputStream = new ByteArrayInputStream(keyJson.getBytes(StandardCharsets.UTF_8))) { credentials = ServiceAccountCredentials.fromStream(inputStream, () -> HTTP_TRANSPORT) .createScoped(DirectoryScopes.ADMIN_DIRECTORY_USER, - DirectoryScopes.ADMIN_DIRECTORY_GROUP, DirectoryScopes.ADMIN_DIRECTORY_GROUP, LicensingScopes.APPS_LICENSING) .createDelegated(getServiceAccountUser()); diff --git a/src/main/java/com/evolveum/polygon/connector/googleapps/GoogleAppsConnector.java b/src/main/java/com/evolveum/polygon/connector/googleapps/GoogleAppsConnector.java index 2be7787..983d264 100644 --- a/src/main/java/com/evolveum/polygon/connector/googleapps/GoogleAppsConnector.java +++ b/src/main/java/com/evolveum/polygon/connector/googleapps/GoogleAppsConnector.java @@ -135,6 +135,8 @@ public class GoogleAppsConnector implements Connector, CreateOp, DeleteOp, Schem public static final String TYPE_ATTR = "type"; public static final String PRODUCT_ID_SKU_ID_USER_ID = "productId,skuId,userId"; public static final String PHOTO_ATTR = "__PHOTO__"; + public static final String LOCATIONS_ATTR = "locations"; + /** * Place holder for the {@link Configuration} passed into the init() method * {@link GoogleAppsConnector#init(org.identityconnectors.framework.spi.Configuration)} @@ -1742,13 +1744,17 @@ private ConnectorObject getUserFromResource(User user, ConnectorObjectBuilder bu .getOrganizations()))); } if (null == attributesToGet || attributesToGet.contains(PHONES_ATTR)) { -// builder.addAttribute(AttributeBuilder.build(PHONES_ATTR, (Collection) user.getPhones())); builder.addAttribute(AttributeBuilder.build(PHONES_ATTR, (Collection) GoogleAppsUtil.structAttrToString((Collection) user.getPhones()))); } if (null == attributesToGet || attributesToGet.contains(ALIASES_ATTR)) { builder.addAttribute(AttributeBuilder.build(ALIASES_ATTR, (Collection) GoogleAppsUtil.structAttrToString((Collection) user.getAliases()))); } + if (null == attributesToGet || attributesToGet.contains(LOCATIONS_ATTR)) { + builder.addAttribute(AttributeBuilder.build(LOCATIONS_ATTR, (Collection) GoogleAppsUtil.structAttrToString((Collection) user + .getLocations()))); + } + if (null == attributesToGet || attributesToGet.contains(NON_EDITABLE_ALIASES_ATTR)) { builder.addAttribute(AttributeBuilder.build(NON_EDITABLE_ALIASES_ATTR, user .getNonEditableAliases())); diff --git a/src/main/java/com/evolveum/polygon/connector/googleapps/UserHandler.java b/src/main/java/com/evolveum/polygon/connector/googleapps/UserHandler.java index 16214b9..4c29e4f 100644 --- a/src/main/java/com/evolveum/polygon/connector/googleapps/UserHandler.java +++ b/src/main/java/com/evolveum/polygon/connector/googleapps/UserHandler.java @@ -93,6 +93,7 @@ public class UserHandler implements FilterVisitor NAME_DICTIONARY; private static final Set S; @@ -475,6 +476,8 @@ public static ObjectClassInfo getUserClassInfo() { .setMultiValued(true).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(ALIASES_ATTR) .setMultiValued(true).build()); + builder.addAttributeInfo(AttributeInfoBuilder.define(LOCATIONS_ATTR) + .setMultiValued(true).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(NON_EDITABLE_ALIASES_ATTR) .setUpdateable(false).setCreateable(false).setMultiValued(true).build()); @@ -559,6 +562,7 @@ public static Directory.Users.Insert createUser(Directory.Users users, user.setAddresses(GoogleAppsUtil.getStructAttr((Attribute) attributes.find(ADDRESSES_ATTR))); user.setOrganizations(GoogleAppsUtil.getStructAttr((Attribute) attributes.find(ORGANIZATIONS_ATTR))); user.setPhones(GoogleAppsUtil.getStructAttr((Attribute) attributes.find(PHONES_ATTR))); + user.setLocations(GoogleAppsUtil.getStructAttr((Attribute) attributes.find(LOCATIONS_ATTR))); user.setSuspended(attributes.findBoolean(SUSPENDED_ATTR)); user.setChangePasswordAtNextLogin(attributes @@ -709,10 +713,17 @@ public static Directory.Users.Patch updateUser(Directory.Users users, Uid uid, if (null == content) { content = new User(); } - // content.setPhones(phones.getValue()); content.setPhones(GoogleAppsUtil.getStructAttr(phones)); } + Attribute locations = attributes.find(LOCATIONS_ATTR); + if (null != locations) { + if (null == content) { + content = new User(); + } + content.setLocations(GoogleAppsUtil.getStructAttr(locations)); + } + Attribute orgUnitPath = attributes.find(ORG_UNIT_PATH_ATTR); if (null != orgUnitPath) { String stringValue = GoogleAppsUtil.getStringValueWithDefault(orgUnitPath, null);