diff --git a/connector-scim2/pom.xml b/connector-scim2/pom.xml index 5e4a252..74a570f 100644 --- a/connector-scim2/pom.xml +++ b/connector-scim2/pom.xml @@ -27,7 +27,7 @@ edu.unc.polygon connector-scim2 - .98-SNAPSHOT + .9992-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 25cf490..5c23236 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 @@ -229,7 +229,7 @@ public void sync(ObjectClass oc, SyncToken fromToken, SyncResultsHandler handler String Scim2Filter = ""; String Scim2SortBy = ""; String Scim2SortOrder = ""; - String Scim2StartIndex = "0"; + String Scim2StartIndex = "1"; String Scim2Count = "2000"; /* if (configuration.getScim2Attributes() != null && !StringUtil.isEmpty(configuration.getScim2Attributes())) { Scim2Attributes = "attributes=" + configuration.getScim2Attributes(); @@ -313,41 +313,42 @@ public void sync(ObjectClass oc, SyncToken fromToken, SyncResultsHandler handler 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)))); - String [] potentialAttributes = { ATTR_ID, ATTR_EXTERNAL_ID, ATTR_USER_NAME, ATTR_ACTIVE}; + String [] potentialAttributes = { ATTR_EXTERNAL_ID, ATTR_USER_NAME, ATTR_ACTIVE}; for ( String potentialAttribute: potentialAttributes ) { 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) ) { + else if ( potentialAttribute.equals(ATTR_USER_NAME) ) { //builder.setName(attributes.getString(potentialAttribute)); //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)); + onyenInfo.put(ATTR_ID,personJson.getString(ATTR_ID)); + objectBuild.setName(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") { + /*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) ) { - objectBuild.setUid(personJson.getString(ATTR_ID)); - addAttr(objectBuild, potentialAttribute, personJson.getString(potentialAttribute)); - }*/ - if ( potentialAttribute.equals(ATTR_ACTIVE) ) { + else if ( potentialAttribute.equals(ATTR_ID) ) { + //objectBuild.setUid(personJson.getString(ATTR_ID)); + //addAttr(objectBuild, potentialAttribute, personJson.getString(potentialAttribute)); + } + else if ( potentialAttribute.equals(ATTR_ACTIVE) ) { addAttr(objectBuild, potentialAttribute, personJson.getBoolean(potentialAttribute)); } - /*else { + else { addAttr(objectBuild, potentialAttribute, personJson.getString(potentialAttribute)); - }*/ + } } } ConnectorObject connectorObject = objectBuild.build(); @@ -376,7 +377,7 @@ public void executeQuery(ObjectClass oc, Scim2Filter filter, ResultsHandler hand String Scim2Filter = ""; String Scim2SortBy = ""; String Scim2SortOrder = ""; - String Scim2StartIndex = "0"; + String Scim2StartIndex = "1"; String Scim2Count = "2000"; if (configuration.getScim2Attributes() != null && !StringUtil.isEmpty(configuration.getScim2Attributes())) { Scim2Attributes = "attributes=" + configuration.getScim2Attributes(); @@ -573,19 +574,13 @@ protected JSONObject callRequest(HttpRequestBase request) throws IOException { file.flush(); file.close(); int statusCode = response.getStatusLine().getStatusCode(); - /* No status responses to handle yet if (statusCode == 500) { JSONObject errorResult = new JSONObject(responseText); //JSONObject errorData = errorResult.getJSONObject("data"); - if (errorResult.getString("code").equals("existing_user_login")) { closeResponse(response); - throw new AlreadyExistsException(jo.getString(ATTR_NAME)); - } - if (errorResult.getString("code").equals("existing_user_email")) { - closeResponse(response); - throw new AlreadyExistsException(jo.getString(ATTR_MAIL)); - } + throw new ConnectionFailedException; } + /* No status responses to handle yet if (statusCode == 404) { JSONObject errorResult = new JSONObject(responseText); //JSONObject errorData = errorResult.getJSONObject("data"); @@ -632,7 +627,7 @@ private void handleUserId ( ResultsHandler handler, JSONObject uidSearchResponse // attributes = (JSONObject) uidSearchResponseJson.get("attributes"); //} //builder.setUid(new Uid(String.valueOf(id))); - String [] potentialAttributes = { ATTR_ID, ATTR_EXTERNAL_ID, ATTR_USER_NAME, ATTR_ACTIVE}; + String [] potentialAttributes = { ATTR_EXTERNAL_ID, ATTR_USER_NAME, ATTR_ACTIVE}; for ( String potentialAttribute: potentialAttributes ) { LOG.info(">>> checking for attribute " + potentialAttribute ); if ( uidSearchResponseJson.has(potentialAttribute) && uidSearchResponseJson.get(potentialAttribute) != null && !JSONObject.NULL.equals(uidSearchResponseJson.get(potentialAttribute)) ) { @@ -643,35 +638,35 @@ private void handleUserId ( ResultsHandler handler, JSONObject uidSearchResponse }*/ 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_USER_NAME) ) { + else 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)); + onyenInfo.put(ATTR_ID,uidSearchResponseJson.getString(ATTR_ID)); + builder.setName(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") { + /*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) ) { + else if ( potentialAttribute.equals(ATTR_ID) ) { + //builder.setUid(uidSearchResponseJson.getString(ATTR_ID)); + //addAttr(builder, potentialAttribute, uidSearchResponseJson.getString(potentialAttribute)); + } + else if ( potentialAttribute.equals(ATTR_ACTIVE) ) { addAttr(builder, potentialAttribute, uidSearchResponseJson.getBoolean(potentialAttribute)); } - /*else { + else { addAttr(builder, potentialAttribute, uidSearchResponseJson.getString(potentialAttribute)); - }*/ + } } } ConnectorObject connectorObject = builder.build();