From 0a56b12a27a377f56a886e9f4428e599a04b2625 Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Sun, 12 Aug 2018 01:09:13 +0200 Subject: [PATCH] Add first grouper<->midpoint demo files First attempt at grouper<->midpoint interconnection demonstration. There's "OpenLDAP edu" resource used to import users into midPoint and "Grouper SQL" resource used to import group membership information from Grouper. Work in progress. Very limited functionality as for now. --- .../objects/resources/ldap-edu.xml | 233 ++++++++++++++++++ .../objects/resources/scriptedsql-grouper.xml | 132 ++++++++++ grouper-midpoint-demo/schema/user-schema.xsd | 22 ++ .../scriptedsql/grouper/SchemaScript.groovy | 91 +++++++ .../scriptedsql/grouper/SearchScript.groovy | 79 ++++++ .../scriptedsql/grouper/TestScript.groovy | 38 +++ 6 files changed, 595 insertions(+) create mode 100644 grouper-midpoint-demo/objects/resources/ldap-edu.xml create mode 100644 grouper-midpoint-demo/objects/resources/scriptedsql-grouper.xml create mode 100644 grouper-midpoint-demo/schema/user-schema.xsd create mode 100644 grouper-midpoint-demo/scriptedsql/grouper/SchemaScript.groovy create mode 100644 grouper-midpoint-demo/scriptedsql/grouper/SearchScript.groovy create mode 100644 grouper-midpoint-demo/scriptedsql/grouper/TestScript.groovy diff --git a/grouper-midpoint-demo/objects/resources/ldap-edu.xml b/grouper-midpoint-demo/objects/resources/ldap-edu.xml new file mode 100644 index 0000000..b8f1e0f --- /dev/null +++ b/grouper-midpoint-demo/objects/resources/ldap-edu.xml @@ -0,0 +1,233 @@ + + + + + + + + + OpenLDAP edu + + + + + c:connectorType + com.evolveum.polygon.connector.ldap.LdapConnector + + + + + + + 389 + grouper + dc=internet2,dc=edu + cn=root,dc=internet2,dc=edu + + password + + always + spr + SSHA + + memberOf + createTimestamp + + + false + false + false + + + + + + ri:inetOrgPerson + ri:eduPerson + ri:groupOfUniqueNames + ri:groupOfNames + ri:organizationalUnit + + + + + + account + Normal Account + true + ri:inetOrgPerson + ri:eduPerson + + ri:dn + Distinguished Name + + 0 + + mr:stringIgnoreCase + + + ri:entryUUID + Entry UUID + + + true + false + true + + + mr:stringIgnoreCase + + + ri:cn + Common Name + + 0 + + + + fullName + + + + + ri:sn + Surname + + 0 + + + + familyName + + + + + ri:givenName + Given Name + + + givenName + + + + + ri:uid + Login Name + mr:stringIgnoreCase + + + name + + + + + ri:mail + Mail + mr:stringIgnoreCase + + + emailAddress + + + + + ri:employeeNumber + + + employeeNumber + + + + + ri:businessCategory + + + extension/ldap_businessCategory + + + + + ri:eduPersonAffiliation + + + extension/ldap_eduPersonAffiliation + + + + + + + http://prism.evolveum.com/xml/ns/public/matching-rule-3#stringIgnoreCase + attributes/ri:dn + cn=root,dc=internet2,dc=edu + + + + + + + + + + true + + + + name + + + declare namespace ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"; + $account/attributes/ri:uid + + + + + + + linked + true + + + deleted + true + + http://midpoint.evolveum.com/xml/ns/public/model/action-3#unlink + + + + + unlinked + true + + http://midpoint.evolveum.com/xml/ns/public/model/action-3#link + + + + unmatched + true + + http://midpoint.evolveum.com/xml/ns/public/model/action-3#addFocus + + + + + + + + diff --git a/grouper-midpoint-demo/objects/resources/scriptedsql-grouper.xml b/grouper-midpoint-demo/objects/resources/scriptedsql-grouper.xml new file mode 100644 index 0000000..9a2e8e6 --- /dev/null +++ b/grouper-midpoint-demo/objects/resources/scriptedsql-grouper.xml @@ -0,0 +1,132 @@ + + + + + Grouper SQL + + + + + connectorType + net.tirasa.connid.bundles.db.scriptedsql.ScriptedSQLConnector + + + + + + + + grouper + 3306 + + root + + + + grouper + + GROOVY + + /opt/midpoint/var/res/SearchScript.groovy + /opt/midpoint/var/res/TestScript.groovy + /opt/midpoint/var/res/SchemaScript.groovy + + true + + + + + + org.mariadb.jdbc.Driver + jdbc:mysql://%h:%p/%d?useUnicode=true&characterEncoding=utf8&connectionCollation=utf8_bin + true + true + false + false + + + + + + + + + + + account + Normal Account + true + ri:AccountObjectClass + + ri:subject_id + Subject ID + + + ri:subject_identifier0 + Subject Identifier + + + ri:name + Name + + + ri:group + Subject Groups + + + extension/grouper_group + + + + + + + + + true + + + + employeeNumber + + + declare namespace ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"; + $account/attributes/ri:subject_identifier0 + + + + + + + linked + true + + + deleted + true + + http://midpoint.evolveum.com/xml/ns/public/model/action-3#unlink + + + + + unlinked + true + + http://midpoint.evolveum.com/xml/ns/public/model/action-3#link + + + + unmatched + true + + + + + + + diff --git a/grouper-midpoint-demo/schema/user-schema.xsd b/grouper-midpoint-demo/schema/user-schema.xsd new file mode 100644 index 0000000..4b745f1 --- /dev/null +++ b/grouper-midpoint-demo/schema/user-schema.xsd @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + diff --git a/grouper-midpoint-demo/scriptedsql/grouper/SchemaScript.groovy b/grouper-midpoint-demo/scriptedsql/grouper/SchemaScript.groovy new file mode 100644 index 0000000..857e6c1 --- /dev/null +++ b/grouper-midpoint-demo/scriptedsql/grouper/SchemaScript.groovy @@ -0,0 +1,91 @@ +/* + * ==================== + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 ForgeRock. All rights reserved. + * + * The contents of this file are subject to the terms of the Common Development + * and Distribution License("CDDL") (the "License"). You may not use this file + * except in compliance with the License. + * + * You can obtain a copy of the License at + * http://opensource.org/licenses/cddl1.php + * See the License for the specific language governing permissions and limitations + * under the License. + * + * When distributing the Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://opensource.org/licenses/cddl1.php. + * If applicable, add the following below this CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * ==================== + * Portions Copyrighted 2013 ConnId. + */ +import org.identityconnectors.framework.common.objects.AttributeInfo; +import org.identityconnectors.framework.common.objects.AttributeInfo.Flags; +import org.identityconnectors.framework.common.objects.AttributeInfoBuilder; +import org.identityconnectors.framework.common.objects.ObjectClassInfo; +import org.identityconnectors.framework.common.objects.ObjectClassInfoBuilder; + +// Parameters: +// The connector sends the following: +// action: a string describing the action ("SCHEMA" here) +// log: a handler to the Log facility +// builder: SchemaBuilder instance for the connector +// +// The connector will make the final call to builder.build() +// so the scipt just need to declare the different object types. + +// This sample shows how to create 3 basic ObjectTypes: __ACCOUNT__, __GROUP__ and organization. +// Each of them contains one required attribute and normal String attributes + + +log.info("Entering "+action+" Script"); + +// Declare the __ACCOUNT__ attributes +// Make the uid required +uidAIB = new AttributeInfoBuilder("uid",String.class); +uidAIB.setRequired(true); + +accAttrsInfo = new HashSet(); +accAttrsInfo.add(uidAIB.build()); +accAttrsInfo.add(AttributeInfoBuilder.build("subject_id", String.class)); +accAttrsInfo.add(AttributeInfoBuilder.build("subject_identifier0", String.class)); +accAttrsInfo.add(AttributeInfoBuilder.build("sort_string0", String.class)); +accAttrsInfo.add(AttributeInfoBuilder.build("search_string0", String.class)); +accAttrsInfo.add(AttributeInfoBuilder.build("name", String.class)); +accAttrsInfo.add(AttributeInfoBuilder.build("description", String.class)); +accAttrsInfo.add(AttributeInfoBuilder.build("group", String.class, [Flags.MULTIVALUED] as Set)); +// Create the __ACCOUNT__ Object class +final ObjectClassInfo ociAccount = new ObjectClassInfoBuilder().setType("__ACCOUNT__").addAllAttributeInfo(accAttrsInfo).build(); +builder.defineObjectClass(ociAccount); + +/* +// Declare the __GROUP__ attributes +// Make the gid required +gidAIB = new AttributeInfoBuilder("gid",String.class); +gidAIB.setRequired(true); + +grpAttrsInfo = new HashSet(); +grpAttrsInfo.add(gidAIB.build()); +grpAttrsInfo.add(AttributeInfoBuilder.build("name", String.class)); +grpAttrsInfo.add(AttributeInfoBuilder.build("description", String.class)); +// Create the __GROUP__ Object class +final ObjectClassInfo ociGroup = new ObjectClassInfoBuilder().setType("__GROUP__").addAllAttributeInfo(grpAttrsInfo).build(); +builder.defineObjectClass(ociGroup); + + +// Declare the organization attributes +// Make the name required +nAIB = new AttributeInfoBuilder("name",String.class); +nAIB.setRequired(true); + +orgAttrsInfo = new HashSet(); +orgAttrsInfo.add(nAIB.build()); +orgAttrsInfo.add(AttributeInfoBuilder.build("description", String.class)); +// Create the organization Object class +final ObjectClassInfo ociOrg = new ObjectClassInfoBuilder().setType("organization").addAllAttributeInfo(orgAttrsInfo).build(); +builder.defineObjectClass(ociOrg); +*/ + +log.info("Schema script done"); diff --git a/grouper-midpoint-demo/scriptedsql/grouper/SearchScript.groovy b/grouper-midpoint-demo/scriptedsql/grouper/SearchScript.groovy new file mode 100644 index 0000000..5da1e92 --- /dev/null +++ b/grouper-midpoint-demo/scriptedsql/grouper/SearchScript.groovy @@ -0,0 +1,79 @@ +/* + * ==================== + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 ForgeRock. All rights reserved. + * + * The contents of this file are subject to the terms of the Common Development + * and Distribution License("CDDL") (the "License"). You may not use this file + * except in compliance with the License. + * + * You can obtain a copy of the License at + * http://opensource.org/licenses/cddl1.php + * See the License for the specific language governing permissions and limitations + * under the License. + * + * When distributing the Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://opensource.org/licenses/cddl1.php. + * If applicable, add the following below this CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * ==================== + * Portions Copyrighted 2013 ConnId. + */ +import groovy.sql.Sql; +import groovy.sql.DataSet; + +// Parameters: +// The connector sends the following: +// connection: handler to the SQL connection +// objectClass: a String describing the Object class (__ACCOUNT__ / __GROUP__ / other) +// action: a string describing the action ("SEARCH" here) +// log: a handler to the Log facility +// options: a handler to the OperationOptions Map +// query: a handler to the Query Map +// +// The Query map describes the filter used. +// +// query = [ operation: "CONTAINS", left: attribute, right: "value", not: true/false ] +// query = [ operation: "ENDSWITH", left: attribute, right: "value", not: true/false ] +// query = [ operation: "STARTSWITH", left: attribute, right: "value", not: true/false ] +// query = [ operation: "EQUALS", left: attribute, right: "value", not: true/false ] +// query = [ operation: "GREATERTHAN", left: attribute, right: "value", not: true/false ] +// query = [ operation: "GREATERTHANOREQUAL", left: attribute, right: "value", not: true/false ] +// query = [ operation: "LESSTHAN", left: attribute, right: "value", not: true/false ] +// query = [ operation: "LESSTHANOREQUAL", left: attribute, right: "value", not: true/false ] +// query = null : then we assume we fetch everything +// +// AND and OR filter just embed a left/right couple of queries. +// query = [ operation: "AND", left: query1, right: query2 ] +// query = [ operation: "OR", left: query1, right: query2 ] +// +// Returns: A list of Maps. Each map describing one row. +// !!!! Each Map must contain a '__UID__' and '__NAME__' attribute. +// This is required to build a ConnectorObject. + +log.info("Entering "+action+" Script"); + +def sql = new Sql(connection); +def result = [] +def where = ""; + +switch ( objectClass ) { + case "__ACCOUNT__": + sql.eachRow("select m.*, group_concat(distinct g.name) as groups from grouper_members m left join grouper_memberships_all_v gm on m.id=gm.member_id left join grouper_groups g on gm.owner_id=g.id group by m.id", {result.add([__UID__:it.id, __NAME__:it.subject_id, uid:it.id, subject_id:it.subject_id, subject_identifier0:it.subject_identifier0, sort_string0:it.sort_string0, search_string0:it.search_string0, name:it.name, description:it.description, group:it.groups?.tokenize(',')])} ); + break + +/* case "__GROUP__": + sql.eachRow("SELECT * FROM Groups" + where, {result.add([__UID__:it.name, __NAME__:it.name, gid:it.gid, ,description:it.description])} ); + break + + case "organization": + sql.eachRow("SELECT * FROM Organizations" + where, {result.add([__UID__:it.name, __NAME__:it.name, description:it.description])} ); + break */ + + default: + result; +} + +return result; diff --git a/grouper-midpoint-demo/scriptedsql/grouper/TestScript.groovy b/grouper-midpoint-demo/scriptedsql/grouper/TestScript.groovy new file mode 100644 index 0000000..a232c15 --- /dev/null +++ b/grouper-midpoint-demo/scriptedsql/grouper/TestScript.groovy @@ -0,0 +1,38 @@ +/* + * ==================== + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 ForgeRock. All rights reserved. + * + * The contents of this file are subject to the terms of the Common Development + * and Distribution License("CDDL") (the "License"). You may not use this file + * except in compliance with the License. + * + * You can obtain a copy of the License at + * http://opensource.org/licenses/cddl1.php + * See the License for the specific language governing permissions and limitations + * under the License. + * + * When distributing the Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://opensource.org/licenses/cddl1.php. + * If applicable, add the following below this CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * ==================== + * Portions Copyrighted 2013 ConnId. + */ +import groovy.sql.Sql; +import groovy.sql.DataSet; + +// Parameters: +// The connector sends the following: +// connection: handler to the SQL connection +// action: a string describing the action ("TEST" here) +// log: a handler to the Log facility + +log.info("Entering "+action+" Script"); +def sql = new Sql(connection); + +sql.eachRow("select * from grouper_members limit 10", { println it.subject_id } ); + +