From bec87076f4582a312a91a95196598291b58c47e8 Mon Sep 17 00:00:00 2001 From: Ethan Kromhout Date: Fri, 12 Jun 2020 14:52:55 -0400 Subject: [PATCH] Bring username back as json with attributes, only valid for single valued --- connector-scim2/pom.xml | 2 +- .../connector/scim2/Scim2Connector.java | 88 +++++++++++++++---- 2 files changed, 71 insertions(+), 19 deletions(-) diff --git a/connector-scim2/pom.xml b/connector-scim2/pom.xml index b924a7e..5e4a252 100644 --- a/connector-scim2/pom.xml +++ b/connector-scim2/pom.xml @@ -27,7 +27,7 @@ edu.unc.polygon connector-scim2 - .2-SNAPSHOT + .98-SNAPSHOT jar Scim2 Connector diff --git a/connector-scim2/src/main/java/edu/unc/polygon/connector/scim2/Scim2Connector.java b/connector-scim2/src/main/java/edu/unc/polygon/connector/scim2/Scim2Connector.java index 3f2312d..25cf490 100644 --- a/connector-scim2/src/main/java/edu/unc/polygon/connector/scim2/Scim2Connector.java +++ b/connector-scim2/src/main/java/edu/unc/polygon/connector/scim2/Scim2Connector.java @@ -66,13 +66,14 @@ * */ @ConnectorClass(displayNameKey = "connector.federation.manager.display", configurationClass = Scim2Configuration.class) -public class Scim2Connector extends AbstractRestConnector implements TestOp, SchemaOp, Connector, SearchOp, SyncOp { +public class Scim2Connector extends AbstractRestConnector implements TestOp, SchemaOp, PoolableConnector, SearchOp, SyncOp { private static final Log LOG = Log.getLog(Scim2Connector.class); private static final String ATTR_ID = "id"; //__UID__ private static final String ATTR_USER_NAME = "userName"; // __NAME__ private static final String ATTR_ACTIVE = "active"; public static final String ATTR_EXTERNAL_ID = "externalId"; + //public static final String ATTR_ONYEN = "onyen"; //public static final String ATTR_MAIL = "email"; //public static final String ATTR_NAME = "id"; //hope to change this to username later __NAME__ //public static final String ATTR_FAX_NUMBER = "faxnumber"; @@ -125,12 +126,12 @@ public void test() { } -/* + @Override public void checkAlive() { test(); } -*/ + private void authHeader(HttpRequest request) { //request.setHeader(configuration.getTokenName(), configuration.getTokenValue()); @@ -174,9 +175,18 @@ public Schema schema() { userName.setUpdateable(true); userName.setReadable(true); userName.setRequired(false); - userName.setMultiValued(false); + userName.setMultiValued(true); accountAttributes.add(userName.build()); + //AttributeInfoBuilder onyen = new AttributeInfoBuilder(); + /*onyen.setName(ATTR_ONYEN); + onyen.setCreateable(true); + onyen.setUpdateable(true); + onyen.setReadable(true); + onyen.setRequired(false); + onyen.setMultiValued(true); + accountAttributes.add(onyen.build()); */ AttributeInfoBuilder active = new AttributeInfoBuilder(); + active.setType(boolean.class); active.setName(ATTR_ACTIVE); active.setCreateable(true); active.setUpdateable(true); @@ -209,6 +219,7 @@ public void sync(ObjectClass oc, SyncToken fromToken, SyncResultsHandler handler if (fromToken == null) { fromToken = getLatestSyncToken(oc); } + SyncToken afterToken = getLatestSyncToken(oc); LOG.info("starting sync"); LOG.info("ObjectClass.ACCOUNT_NAME is " + ObjectClass.ACCOUNT_NAME); LOG.info("sync ObjectClass is " + oc.getObjectClassValue() + "--"); @@ -251,10 +262,10 @@ public void sync(ObjectClass oc, SyncToken fromToken, SyncResultsHandler handler parameters = parameters + "&excludedAttributes=" + configuration.getScim2ExcludedAttributes(); } if (!StringUtil.isEmpty(configuration.getScim2Filter())) { - parameters = parameters + "&filter=" + configuration.getScim2Filter() + "and (meta.created gt %22" + fromToken + "%22 or onyen.expirationDate gt %22" + fromToken + "%22)"; + parameters = parameters + "&filter=" + configuration.getScim2Filter() + "+and+(meta.created+gt+%22" + (String)fromToken.getValue() + "%22+or+onyen.expirationDate+gt+%22" + (String)fromToken.getValue() + "%22)"; } else { - parameters = parameters + "&filter=" + "meta.created gt %22" + fromToken + "%22 or onyen.expirationDate gt %22" + fromToken + "%22"; + parameters = parameters + "&filter=" + "meta.created+gt+%22" + (String)fromToken.getValue() + "%22+or+onyen.expirationDate+gt+%22" + (String)fromToken.getValue()+ "%22"; } if (!StringUtil.isEmpty(configuration.getScim2SortBy())) { parameters = parameters + "&sortBy=" + configuration.getScim2SortBy(); @@ -294,11 +305,11 @@ public void sync(ObjectClass oc, SyncToken fromToken, SyncResultsHandler handler for ( int i = 0; i < peopleArray.length(); i++ ) { JSONObject personJson = peopleArray.getJSONObject(i); LOG.info(">>> processing ID " + i); - //handleUserId( handler, personJson ); + ////handleUserId( handler, personJson ); SyncDeltaBuilder builder = new SyncDeltaBuilder(); builder.setDeltaType(SyncDeltaType.CREATE_OR_UPDATE); builder.setObjectClass(ObjectClass.ACCOUNT); - builder.setToken(fromToken); + builder.setToken(afterToken); LOG.info("Building sync connector object for " + String.valueOf(personJson.getString(ATTR_ID))); ConnectorObjectBuilder objectBuild = new ConnectorObjectBuilder(); objectBuild.setUid(new Uid(String.valueOf(personJson.getString(ATTR_ID)))); @@ -307,19 +318,36 @@ public void sync(ObjectClass oc, SyncToken fromToken, SyncResultsHandler handler LOG.info(">>> checking for attribute " + potentialAttribute ); if ( personJson.has(potentialAttribute) && personJson.get(potentialAttribute) != null && !JSONObject.NULL.equals(personJson.get(potentialAttribute)) ) { LOG.info(">>> found attribute " + potentialAttribute ); + if ( potentialAttribute.equals(ATTR_EXTERNAL_ID) ) { + //builder.setName(attributes.getString(potentialAttribute)); + objectBuild.setName(personJson.getString(ATTR_EXTERNAL_ID)); + addAttr(objectBuild, potentialAttribute, personJson.getString(potentialAttribute)); + } if ( potentialAttribute.equals(ATTR_USER_NAME) ) { //builder.setName(attributes.getString(potentialAttribute)); - objectBuild.setName(personJson.getString(ATTR_USER_NAME)); + //objectBuild.setName(personJson.getString(ATTR_USER_NAME)); + LOG.info(">>> Processing userName " + potentialAttribute ); + JSONObject onyenInfo = new JSONObject(); + onyenInfo = (JSONObject)personJson.get("urn:ietf:params:scim:schema:unc:core:2.0:Onyen"); + onyenInfo.put(ATTR_USER_NAME,personJson.getString(ATTR_USER_NAME)); + addAttr(objectBuild, ATTR_USER_NAME, onyenInfo.toString()); + String logSafeString = onyenInfo.toString().replace('{','$').replace('}','#'); + LOG.info(">>> Just added onyen information " + logSafeString ); + if ((String)onyenInfo.get("type") == "PRIMARY") { + objectBuild.setUid(personJson.getString(ATTR_ID)); + addAttr(objectBuild, ATTR_ID, personJson.getString(ATTR_ID)); + } } - if ( potentialAttribute.equals(ATTR_ID) ) { + /*if ( potentialAttribute.equals(ATTR_ID) ) { objectBuild.setUid(personJson.getString(ATTR_ID)); - } + addAttr(objectBuild, potentialAttribute, personJson.getString(potentialAttribute)); + }*/ if ( potentialAttribute.equals(ATTR_ACTIVE) ) { addAttr(objectBuild, potentialAttribute, personJson.getBoolean(potentialAttribute)); } - else { + /*else { addAttr(objectBuild, potentialAttribute, personJson.getString(potentialAttribute)); - } + }*/ } } ConnectorObject connectorObject = objectBuild.build(); @@ -328,6 +356,7 @@ public void sync(ObjectClass oc, SyncToken fromToken, SyncResultsHandler handler } } else { + morePages = false; LOG.info("No data object found in response"); } @@ -515,6 +544,7 @@ else if (filter != null && filter.byExternalId != null) { } } else { + morePages = false; LOG.info("No data object found in response"); } @@ -607,19 +637,41 @@ private void handleUserId ( ResultsHandler handler, JSONObject uidSearchResponse LOG.info(">>> checking for attribute " + potentialAttribute ); if ( uidSearchResponseJson.has(potentialAttribute) && uidSearchResponseJson.get(potentialAttribute) != null && !JSONObject.NULL.equals(uidSearchResponseJson.get(potentialAttribute)) ) { LOG.info(">>> found attribute " + potentialAttribute ); - if ( potentialAttribute.equals(ATTR_USER_NAME) ) { + /*if ( potentialAttribute.equals(ATTR_USER_NAME) ) { //builder.setName(attributes.getString(potentialAttribute)); builder.setName(uidSearchResponseJson.getString(ATTR_USER_NAME)); + }*/ + if ( potentialAttribute.equals(ATTR_EXTERNAL_ID) ) { + //builder.setName(attributes.getString(potentialAttribute)); + builder.setName(uidSearchResponseJson.getString(ATTR_EXTERNAL_ID)); + addAttr(builder, potentialAttribute, uidSearchResponseJson.getString(potentialAttribute)); } - if ( potentialAttribute.equals(ATTR_ID) ) { - builder.setUid(uidSearchResponseJson.getString(ATTR_ID)); + if ( potentialAttribute.equals(ATTR_USER_NAME) ) { + //builder.setName(attributes.getString(potentialAttribute)); + //objectBuild.setName(personJson.getString(ATTR_USER_NAME)); + LOG.info(">>> Inside processing userName " + potentialAttribute ); + JSONObject onyenInfo = new JSONObject(); + onyenInfo = (JSONObject)uidSearchResponseJson.get("urn:ietf:params:scim:schema:unc:core:2.0:Onyen"); + onyenInfo.put(ATTR_USER_NAME,uidSearchResponseJson.getString(ATTR_USER_NAME)); + addAttr(builder, ATTR_USER_NAME, onyenInfo.toString()); + String logSafeString = onyenInfo.toString().replace('{','$').replace('}','#'); + LOG.info(">>> Just added onyen information " + logSafeString ); + if ((String)onyenInfo.get("type") == "PRIMARY") { + builder.setUid(uidSearchResponseJson.getString(ATTR_ID)); + addAttr(builder, ATTR_ID, uidSearchResponseJson.getString(ATTR_ID)); + } } + + /*if ( potentialAttribute.equals(ATTR_ID) ) { + builder.setUid(uidSearchResponseJson.getString(ATTR_ID)); + addAttr(builder, potentialAttribute, uidSearchResponseJson.getString(potentialAttribute)); + }*/ if ( potentialAttribute.equals(ATTR_ACTIVE) ) { addAttr(builder, potentialAttribute, uidSearchResponseJson.getBoolean(potentialAttribute)); } - else { + /*else { addAttr(builder, potentialAttribute, uidSearchResponseJson.getString(potentialAttribute)); - } + }*/ } } ConnectorObject connectorObject = builder.build();