Skip to content

Commit

Permalink
Sample for adding attribute construction in resource inducement
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Feb 12, 2015
1 parent d15d248 commit 885b0de
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Expand Up @@ -165,13 +165,16 @@ public static void main(String[] args) {
// System.out.println(roles);

String seaSuperuserRole = createRoleFromSystemResource(modelPort, "role-sea-superuser.xml");
System.out.println("Created role Sea Superuser, OID: "+seaSuperuserRole);
System.out.println("Created role Sea Superuser, OID: " + seaSuperuserRole);

assignRoles(modelPort, userLeChuckOid, seaSuperuserRole);
System.out.println("Assigned role Sea Superuser to LeChuck");

modifyRoleModifyInducement(modelPort, seaSuperuserRole);
System.out.println("Modified role Sea Superuser - modified resource inducement");

modifyRoleReplaceInducement(modelPort, seaSuperuserRole, 2, ROLE_CAPTAIN_OID);
System.out.println("Modified role Sea Superuser");
System.out.println("Modified role Sea Superuser - changed role inducement");

reconcileUser(modelPort, userLeChuckOid);
System.out.println("LeChuck reconciled.");
Expand Down Expand Up @@ -465,6 +468,37 @@ private static void modifyRoleAssignment(ModelPortType modelPort, String userOid
}
}

private static void modifyRoleModifyInducement(ModelPortType modelPort, String roleOid) throws IOException, SAXException, FaultMessage {
ItemDeltaType inducementDelta = new ItemDeltaType();
inducementDelta.setModificationType(ModificationTypeType.ADD);
inducementDelta.setPath(ModelClientUtil.createItemPathType("inducement[3]/construction/attribute"));
inducementDelta.getValue().add(ModelClientUtil.parseElement("<value>\n" +
" <ref xmlns:ri=\"http://midpoint.evolveum.com/xml/ns/public/resource/instance-3\">ri:pager</ref>\n" +
" <outbound>\n" +
" <expression>\n" +
" <value>00-000-001</value>\n" +
" <value>00-000-003</value>\n" +
" </expression>\n" +
" </outbound>\n" +
" </value>"));

ObjectDeltaType deltaType = new ObjectDeltaType();
deltaType.setObjectType(ModelClientUtil.getTypeQName(RoleType.class));
deltaType.setChangeType(ChangeTypeType.MODIFY);
deltaType.setOid(roleOid);
deltaType.getItemDelta().add(inducementDelta);

ObjectDeltaListType deltaListType = new ObjectDeltaListType();
deltaListType.getDelta().add(deltaType);
ObjectDeltaOperationListType objectDeltaOperationList = modelPort.executeChanges(deltaListType, null);
for (ObjectDeltaOperationType objectDeltaOperation : objectDeltaOperationList.getDeltaOperation()) {
if (!OperationResultStatusType.SUCCESS.equals(objectDeltaOperation.getExecutionResult().getStatus())) {
System.out.println("*** Operation result = " + objectDeltaOperation.getExecutionResult().getStatus() + ": " + objectDeltaOperation.getExecutionResult().getMessage());
}
}
}


// removes inducement with a given ID and replaces it with a new one
private static void modifyRoleReplaceInducement(ModelPortType modelPort, String roleOid, int oldId, String newInducementOid) throws FaultMessage, IOException, SAXException {

Expand Down
Expand Up @@ -27,4 +27,9 @@
<inducement id="2">
<targetRef oid="12345678-d34d-b33f-f00d-987987987988" type="RoleType"/> <!-- Pirate -->
</inducement>
<inducement id="3">
<construction>
<resourceRef oid="ef2bc95b-76e0-48e2-86d6-3d4f02d3e1a2" /> <!-- OpenDJ Localhost -->
</construction>
</inducement>
</role>

0 comments on commit 885b0de

Please sign in to comment.