From aa4369bc1e971cbb8051e5160bccbca22d538cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Wed, 22 May 2024 14:35:06 +0200 Subject: [PATCH] [GOOGLEAPPS-17] #resolve --- .../googleapps/GoogleAppsConnector.java | 53 +++++++++++++++---- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/tirasa/connid/bundles/googleapps/GoogleAppsConnector.java b/src/main/java/net/tirasa/connid/bundles/googleapps/GoogleAppsConnector.java index 90cc835..2cedd10 100644 --- a/src/main/java/net/tirasa/connid/bundles/googleapps/GoogleAppsConnector.java +++ b/src/main/java/net/tirasa/connid/bundles/googleapps/GoogleAppsConnector.java @@ -263,6 +263,41 @@ public Void handleResult(final Directory.Users.MakeAdmin request, final Void val } } + Attribute groups = accessor.find(PredefinedAttributes.GROUPS_NAME); + if (null != groups && null != groups.getValue()) { + final Directory.Members service = configuration.getDirectory().members(); + if (!groups.getValue().isEmpty()) { + final List addGroups = new ArrayList<>(); + + for (Object member : groups.getValue()) { + if (member instanceof String) { + String email = accessor.getName().getNameValue(); + addGroups.add(MembersHandler.create(service, (String) member, email, null)); + } else if (null != member) { + // throw error/revert? + throw new InvalidAttributeValueException("Attribute '__GROUPS__' must be a String list"); + } + } + + // Add new Member object + for (Directory.Members.Insert insert : addGroups) { + execute(insert, new RequestResultHandler() { + + @Override + public Object handleResult(final Directory.Members.Insert request, final Member value) { + return null; + } + + @Override + public Object handleDuplicate(final IOException e) { + // Do nothing + return null; + } + }); + } + } + } + return uid; } else if (ObjectClass.GROUP.equals(objectClass)) { // @formatter:off @@ -325,8 +360,7 @@ public String handleResult(final Directory.Members.Insert request, final Member new RequestResultHandler() { @Override - public Uid handleResult(final Directory.Members.Insert request, - final Member value) { + public Uid handleResult(final Directory.Members.Insert request, final Member value) { LOG.ok("New Member is created:{0}/{1}", request.getGroupKey(), value.getEmail()); return MembersHandler.generateUid(request.getGroupKey(), value); } @@ -625,7 +659,6 @@ public Boolean handleNotFound(final IOException e) { throw ConnectorException.wrap(e); } } - } else if (ObjectClass.GROUP.equals(objectClass)) { if (null == key) { // Search request @@ -688,10 +721,8 @@ public String handleResult(final Directory.Groups.List request, final Groups val LOG.warn(e, "Failed to initialize Groups#List"); throw ConnectorException.wrap(e); } - } else { // Read request - try { Directory.Groups.Get request = configuration.getDirectory().groups().get((String) key.getValue().get(0)); @@ -702,8 +733,8 @@ public String handleResult(final Directory.Groups.List request, final Groups val @Override public Boolean handleResult(final Directory.Groups.Get request, final Group value) { - return handler.handle(fromGroup(value, attributesToGet, - configuration.getDirectory().members())); + return handler.handle(fromGroup( + value, attributesToGet, configuration.getDirectory().members())); } @Override @@ -1004,7 +1035,7 @@ public Boolean handleNotFound(final IOException e) { } - protected Attribute getKeyFromFilter(final ObjectClass objectClass, final Filter filter) { + protected static Attribute getKeyFromFilter(final ObjectClass objectClass, final Filter filter) { Attribute key = null; if (filter instanceof EqualsFilter) { // Account, Group, OrgUnit object classes @@ -1058,7 +1089,7 @@ protected Attribute getKeyFromFilter(final ObjectClass objectClass, final Filter return key; } - protected Set getAttributesToGet(final ObjectClass objectClass, final OperationOptions options) { + protected static Set getAttributesToGet(final ObjectClass objectClass, final OperationOptions options) { Set attributesToGet = null; if (null != options.getAttributesToGet()) { attributesToGet = CollectionUtil.newCaseInsensitiveSet(); @@ -1095,7 +1126,7 @@ protected Set getAttributesToGet(final ObjectClass objectClass, final Op return attributesToGet; } - protected String googleName(final ObjectClass objectClass, final String attributeName) { + protected static String googleName(final ObjectClass objectClass, final String attributeName) { if (AttributeUtil.namesEqual(Name.NAME, attributeName)) { if (ObjectClass.ACCOUNT.equals(objectClass)) { return GoogleAppsUtil.PRIMARY_EMAIL_ATTR; @@ -1122,7 +1153,7 @@ protected String googleName(final ObjectClass objectClass, final String attribut return attributeName; //__GROUPS__ //__PASSWORD__ } - protected Set getAttributesToGet(final OperationOptions options) { + protected static Set getAttributesToGet(final OperationOptions options) { Set attributesToGet = null; if (null != options.getAttributesToGet()) { attributesToGet = CollectionUtil.newCaseInsensitiveSet();