Skip to content

Commit

Permalink
Added support for Entities and clarified Account objectClass naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan committed Sep 27, 2019
1 parent 60834dd commit fb1019d
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 25 deletions.
2 changes: 1 addition & 1 deletion connector-federation-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<groupId>edu.unc.polygon</groupId>
<artifactId>connector-federation-manager</artifactId>
<version>.2-SNAPSHOT</version>
<version>.3-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Federation Manager Connector</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@
<xsd:import namespace="http://prism.evolveum.com/xml/ns/public/annotation-3"/>
<xsd:import namespace="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"/>
<xsd:import namespace="http://midpoint.evolveum.com/xml/ns/public/resource/annotation-3"/>
<xsd:complexType name="MESSAGE_OBJECT_CLASS___ACCOUNT__">
<xsd:complexType name="AccountObjectClass">
<xsd:annotation>
<xsd:appinfo>
<ra:resourceObject/>
<ra:identifier>icfs:uid</ra:identifier>
<ra:secondaryIdentifier>icfs:name</ra:secondaryIdentifier>
<ra:displayNameAttribute>icfs:name</ra:displayNameAttribute>
<ra:namingAttribute>icfs:name</ra:namingAttribute>
<ra:nativeObjectClass>MESSAGE_OBJECT_CLASS___ACCOUNT__</ra:nativeObjectClass>
<ra:nativeObjectClass>AccountObjectClass</ra:nativeObjectClass>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
Expand Down Expand Up @@ -254,7 +254,7 @@
<kind>account</kind>
<intent>default</intent>
<default>true</default>
<objectClass>MESSAGE_OBJECT_CLASS___ACCOUNT__</objectClass>
<objectClass>AccountObjectClass</objectClass>
<attribute id="1">
<c:ref>icfs:uid</c:ref>
<inbound id="9">
Expand Down Expand Up @@ -349,7 +349,7 @@
<synchronization>
<objectSynchronization>
<name>Account sync policy</name>
<objectClass>MESSAGE_OBJECT_CLASS___ACCOUNT__</objectClass>
<objectClass>AccountObjectClass</objectClass>
<kind>account</kind>
<intent>default</intent>
<focusType>c:UserType</focusType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public class FederationManagerConnector extends AbstractRestConnector<Federation
public static final String ATTR_INFORMAL_NAME = "informalname";
public static final String ATTR_WEBSITE = "website";
public static final String CONTENT_TYPE = "application/json";
private static final String ENTITY_ATTR_ID = "id"; //__UID__
private static final String ENTITY_ATTR_ENTITY_NAME = "entity_name"; // __NAME__
private static final String ENTITY_ATTR_TYPE = "type";
private static final String ENTITY_ATTR_ORGANIZATION_ID = "organization_id";
private static final String ENTITY_ATTR_ORGANIZATION_NAME = "organization_name";
private static final String ENTITY_ATTR_STATUS = "status";
private static final String ENTITY_OBJECT_CLASS = "EntityObjectClass";


private FederationManagerConfiguration configuration;
Expand Down Expand Up @@ -227,8 +234,59 @@ public Schema schema() {
website.setMultiValued(false);
accountAttributes.add(website.build());
accountAttributes.add(OperationalAttributeInfos.ENABLE);
schemaBuilder.defineObjectClass(ObjectClass.ACCOUNT.getDisplayNameKey(),accountAttributes);
schemaBuilder.defineObjectClass(ObjectClass.ACCOUNT_NAME,accountAttributes);
//Finish Account Objectclass, add others before return if needed
Set<AttributeInfo> entityAttributes = new HashSet<AttributeInfo>();
AttributeInfoBuilder entity_id = new AttributeInfoBuilder();
entity_id.setName(ENTITY_ATTR_ID);
entity_id.setCreateable(true);
entity_id.setUpdateable(true);
entity_id.setReadable(true);
entity_id.setRequired(false);
entity_id.setMultiValued(false);
entityAttributes.add(entity_id.build());
AttributeInfoBuilder entity_name = new AttributeInfoBuilder();
entity_name.setName(ENTITY_ATTR_ENTITY_NAME);
entity_name.setCreateable(true);
entity_name.setUpdateable(true);
entity_name.setReadable(true);
entity_name.setRequired(false);
entity_name.setMultiValued(false);
entityAttributes.add(entity_name.build());
AttributeInfoBuilder entity_type = new AttributeInfoBuilder();
entity_type.setName(ENTITY_ATTR_TYPE);
entity_type.setCreateable(true);
entity_type.setUpdateable(true);
entity_type.setReadable(true);
entity_type.setRequired(false);
entity_type.setMultiValued(false);
entityAttributes.add(entity_type.build());
AttributeInfoBuilder entity_organization_id = new AttributeInfoBuilder();
entity_organization_id.setName(ENTITY_ATTR_ORGANIZATION_ID);
entity_organization_id.setCreateable(true);
entity_organization_id.setUpdateable(true);
entity_organization_id.setReadable(true);
entity_organization_id.setRequired(false);
entity_organization_id.setMultiValued(false);
entityAttributes.add(entity_organization_id.build());
AttributeInfoBuilder entity_organization_name = new AttributeInfoBuilder();
entity_organization_name.setName(ENTITY_ATTR_ORGANIZATION_NAME);
entity_organization_name.setCreateable(true);
entity_organization_name.setUpdateable(true);
entity_organization_name.setReadable(true);
entity_organization_name.setRequired(false);
entity_organization_name.setMultiValued(false);
entityAttributes.add(entity_organization_name.build());
AttributeInfoBuilder entity_status = new AttributeInfoBuilder();
entity_status.setName(ENTITY_ATTR_STATUS);
entity_status.setCreateable(true);
entity_status.setUpdateable(true);
entity_status.setReadable(true);
entity_status.setRequired(false);
entity_status.setMultiValued(false);
entityAttributes.add(entity_status.build());
accountAttributes.add(OperationalAttributeInfos.ENABLE);
schemaBuilder.defineObjectClass(ENTITY_OBJECT_CLASS,entityAttributes);
LOG.info(">>> schema finished");
return schemaBuilder.build();

Expand All @@ -244,8 +302,10 @@ public FilterTranslator<FederationManagerFilter> createFilterTranslator(ObjectCl
@Override
public void executeQuery(ObjectClass oc, FederationManagerFilter filter, ResultsHandler handler, OperationOptions oo) {
LOG.info("starting executeQuery");
LOG.info("ObjectClass.ACCOUNT_NAME is " + ObjectClass.ACCOUNT_NAME);
LOG.info("executeQuery ObjectClass is " + oc.getObjectClassValue() + "--");
if ( oc.is(ObjectClass.ACCOUNT_NAME)) {
LOG.info("executeQuery ObjectClass.ACCOUNT_NAME");
LOG.info("executeQuery ObjectClass.ACCOUNT_NAME");
/* Filtered searches aren't supported by this API yet, so we'll skip over these for now
if (filter != null && filter.byUid != null) {
//not sure if this use case exists yet
Expand All @@ -262,8 +322,6 @@ else if (filter != null && filter.byEmailAddress != null) {
//wide open search
}
*/
}
else {
try {
CloseableHttpClient client = HttpClients.createDefault();
HttpRequestBase restGet;
Expand Down Expand Up @@ -294,9 +352,57 @@ else if (filter != null && filter.byEmailAddress != null) {

} catch (IOException IOE) {
throw new ConnectorIOException(IOE.getMessage(), IOE);
}
}
if ( oc.is(ENTITY_OBJECT_CLASS)) {
LOG.info("executeQuery ObjectClass.EntityObjectClass");
/* Filtered searches aren't supported by this API yet, so we'll skip over these for now
if (filter != null && filter.byUid != null) {
//not sure if this use case exists yet
}
else if (filter != null && filter.byName != null) {
//not sure if this use case exists yet
}
else if (filter != null && filter.byEmailAddress != null) {
//not sure if this use case exists yet
}
else {
//wide open search
}
*/
try {
CloseableHttpClient client = HttpClients.createDefault();
HttpRequestBase restGet;
restGet = new HttpGet(configuration.getServiceAddress() + "/siteadmin/api/entities");
authHeader(restGet);
//CloseableHttpResponse getResponse = client.execute(restGet);
//processResponseErrors(getResponse);
JSONObject searchResponseJson = new JSONObject();
searchResponseJson = callRequest(restGet);
FileWriter file9 = new FileWriter("/tmp/file9.txt");
file9.write(searchResponseJson.toString());
System.out.println("Successfully Copied JSON Object to File...");
System.out.println("\nJSON Object: " + searchResponseJson);
file9.flush();
file9.close();
JSONArray entityArray = new JSONArray();
if ( searchResponseJson.has("data") && searchResponseJson.get("data") != null ) {
entityArray = searchResponseJson.getJSONArray("data");
for ( int i = 0; i < entityArray.length(); i++ ) {
JSONObject entityJson = entityArray.getJSONObject(i);
LOG.info(">>> processing ID " + i);
handleEntity( handler, entityJson );
}
}
else {
LOG.info("No data object found in response");
}

} catch (IOException IOE) {
throw new ConnectorIOException(IOE.getMessage(), IOE);
}
}

}
Expand Down Expand Up @@ -377,22 +483,6 @@ private void handleUserId ( ResultsHandler handler, JSONObject uidSearchResponse
}
//builder.setUid(new Uid(String.valueOf(id)));
String [] potentialAttributes = { ATTR_NAME, ATTR_MAIL, ATTR_FIRST_NAME, ATTR_LAST_NAME, ATTR_MIDDLE_NAME, ATTR_ORGANIZATION_ID, ATTR_FAX_NUMBER, ATTR_MOBILE_NUMBER, ATTR_PHONE_NUMBER, ATTR_INFORMAL_NAME, ATTR_WEBSITE};
/*
private static final String ATTR_ID = "id"; //__UID__
private static final String ATTR_ORGANIZATION_ID = "organization_id";
public static final String ATTR_NAME = "email"; //hope to change this to username later __NAME__
public static final String ATTR_MAIL = "email";
public static final String ATTR_FAX_NUMBER = "faxnumber";
public static final String ATTR_MOBILE_NUMBER = "mobilenumber";
public static final String ATTR_PHONE_NUMBER = "phonenumber";
//public static final String ATTR_ROLES = "roles";
public static final String ATTR_FIRST_NAME = "firstname";
public static final String ATTR_LAST_NAME = "lastname";
public static final String ATTR_MIDDLE_NAME = "middlename";
public static final String ATTR_INFORMAL_NAME = "informalname";
public static final String ATTR_WEBSITE = "website";
public static final String CONTENT_TYPE = "application/json";
*/
for ( String potentialAttribute: potentialAttributes ) {
LOG.info(">>> checking for attribute " + potentialAttribute );
if ( attributes.has(potentialAttribute) && attributes.get(potentialAttribute) != null && !JSONObject.NULL.equals(attributes.get(potentialAttribute)) ) {
Expand All @@ -413,5 +503,35 @@ else if ( potentialAttribute.equals(ATTR_ORGANIZATION_ID) ) {
handler.handle(connectorObject);
}

private void handleEntity ( ResultsHandler handler, JSONObject uidSearchResponseJson ) {
LOG.info("inside handleEntity " + String.valueOf(uidSearchResponseJson.getInt(ENTITY_ATTR_ID)));
ConnectorObjectBuilder builder = new ConnectorObjectBuilder();
builder.setUid(new Uid(String.valueOf(uidSearchResponseJson.getInt(ENTITY_ATTR_ID))));
JSONObject attributes = new JSONObject();
if ( uidSearchResponseJson.has("attributes") && uidSearchResponseJson.get("attributes") != null ) {
attributes = (JSONObject) uidSearchResponseJson.get("attributes");
}
//builder.setUid(new Uid(String.valueOf(id)));
String [] potentialAttributes = { ENTITY_ATTR_ENTITY_NAME,ENTITY_ATTR_TYPE,ENTITY_ATTR_ORGANIZATION_ID,ENTITY_ATTR_ORGANIZATION_NAME,ENTITY_ATTR_STATUS};
for ( String potentialAttribute: potentialAttributes ) {
LOG.info(">>> checking for attribute " + potentialAttribute );
if ( attributes.has(potentialAttribute) && attributes.get(potentialAttribute) != null && !JSONObject.NULL.equals(attributes.get(potentialAttribute)) ) {
LOG.info(">>> found attribute " + potentialAttribute );
if ( potentialAttribute.equals(ENTITY_ATTR_ENTITY_NAME) ) {
builder.setName(attributes.getString(potentialAttribute));
//builder.setName(String.valueOf(uidSearchResponseJson.getInt(ATTR_ID))); //Temp work around to use "id" as __NAME__ until we get username
}
else if ( potentialAttribute.equals(ENTITY_ATTR_ORGANIZATION_ID) ) {
addAttr(builder, potentialAttribute, attributes.getInt(potentialAttribute));
}
else {
addAttr(builder, potentialAttribute, attributes.getString(potentialAttribute));
}
}
}
ConnectorObject connectorObject = builder.build();
handler.handle(connectorObject);
}


}

0 comments on commit fb1019d

Please sign in to comment.