Skip to content

Commit

Permalink
Added support for activation status and handling UnknownUidException
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan committed Apr 3, 2019
1 parent ae3019c commit 8cc8d79
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 4 deletions.
8 changes: 8 additions & 0 deletions connector-rest-wordpress/samples/connector-rest-wordpress.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@
</target>
</inbound>
</attribute>
<activation>
<administrativeStatus>
<outbound/>
</administrativeStatus>
</activation>
<credentials>
<password xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="c:ResourcePasswordDefinitionType">
<outbound/>
Expand Down Expand Up @@ -362,6 +367,9 @@
<cap:enabled>true</cap:enabled>
<cap:returnDefaultAttributesOption>false</cap:returnDefaultAttributesOption>
</cap:read>
<cap:activation>
<cap:status/>
</cap:activation>
</configured>
</capabilities>
<synchronization>
Expand Down
62 changes: 62 additions & 0 deletions connector-rest-wordpress/samples/subscriber-role.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<role xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3" xmlns:org="http://midpoint.evolveum.com/xml/ns/public/common/org-3" xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3" xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3" xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3" oid="422d70bc-90b5-4a72-98fc-71f552202e9c" version="6">
<name>Subscriber</name>
<metadata>
<requestTimestamp>2019-03-29T17:20:56.643Z</requestTimestamp>
<requestorRef oid="00000000-0000-0000-0000-000000000002" relation="org:default" type="c:UserType">
<!-- administrator -->
</requestorRef>
<createTimestamp>2019-03-29T17:20:56.702Z</createTimestamp>
<creatorRef oid="00000000-0000-0000-0000-000000000002" relation="org:default" type="c:UserType">
<!-- administrator -->
</creatorRef>
<createChannel>http://midpoint.evolveum.com/xml/ns/public/gui/channels-3#user</createChannel>
</metadata>
<operationExecution id="1">
<timestamp>2019-03-29T17:20:56.764Z</timestamp>
<operation>
<objectDelta>
<t:changeType>add</t:changeType>
<t:objectType>c:RoleType</t:objectType>
</objectDelta>
<executionResult>
<operation>com.evolveum.midpoint.model.impl.lens.ChangeExecutor.executeDelta</operation>
<status>success</status>
<token>1000000000000003970</token>
</executionResult>
<objectName>Subscriber</objectName>
</operation>
<status>success</status>
<initiatorRef oid="00000000-0000-0000-0000-000000000002" relation="org:default" type="c:UserType">
<!-- administrator -->
</initiatorRef>
<channel>http://midpoint.evolveum.com/xml/ns/public/gui/channels-3#user</channel>
</operationExecution>
<activation>
<administrativeStatus>enabled</administrativeStatus>
<effectiveStatus>enabled</effectiveStatus>
<enableTimestamp>2019-03-29T17:20:56.652Z</enableTimestamp>
</activation>
<iteration>0</iteration>
<iterationToken/>
<displayName>Wordpress Subscriber</displayName>
<inducement id="2">
<construction>
<resourceRef oid="dd683dd5-b7b0-414c-a1d9-7039340ad70b" relation="org:default" type="c:ResourceType">
<!-- wordpress -->
</resourceRef>
<attribute id="3">
<c:ref>ri:roles</c:ref>
<outbound>
<strength>strong</strength>
<source>
<c:path>$containingObject/name</c:path>
</source>
<expression>
<value>subscriber</value>
</expression>
</outbound>
</attribute>
</construction>
</inducement>
</role>

Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public Schema schema() {
password.setRequired(false);
password.setMultiValued(false);
attributes.add(password.build());
attributes.add(OperationalAttributeInfos.ENABLE);
schemaBuilder.defineObjectClass(ObjectClass.ACCOUNT.getDisplayNameKey(),attributes);
LOG.info(">>> schema finished");
return schemaBuilder.build();
Expand Down Expand Up @@ -459,14 +460,32 @@ public Uid create(ObjectClass objectClass, Set<Attribute> attributes, OperationO
if (last_name != null) {
jsonObject.put(ATTR_LAST_NAME, last_name);
}
Boolean enable = getAttr(attributes, OperationalAttributes.ENABLE_NAME, Boolean.class);
if (enable != null) {
if (! enable) {
JSONArray rolesJsonArray = new JSONArray();
jsonObject.put(ATTR_ROLES, (Object) rolesJsonArray);
}
else {
String[] rolecheck = getMultiValAttr(attributes, ATTR_ROLES, null);
if (rolecheck == null || rolecheck[0] == null) {
JSONArray rolesJsonArray = new JSONArray();
rolesJsonArray.put(0, (Object) "subscriber");
jsonObject.put(ATTR_ROLES, (Object) rolesJsonArray);
}
}
}
String[] roles = getMultiValAttr(attributes, ATTR_ROLES, null);
if ( roles != null ) {
JSONArray rolesJsonArray = new JSONArray();
for ( int i = 0; i < roles.length; i++) {
String role = roles[i];
JSONObject roleJsonObject = new JSONObject(role);
//JSONObject roleJsonObject = new JSONObject();
//roleJsonObject.put(role);
rolesJsonArray.put(i, (Object) role);
//JSONObject roleJsonObject = new JSONObject(role);
//roleJsonObject.put(role);
rolesJsonArray.put(i, (Object) roleJsonObject);
//rolesJsonArray.put(i, (Object) roleJsonObject);
}
jsonObject.put(ATTR_ROLES, (Object) rolesJsonArray);
}
Expand Down Expand Up @@ -555,14 +574,29 @@ public Uid update(ObjectClass objectClass, Uid uid, Set<Attribute> attributes, O
if (last_name != null) {
jsonObject.put(ATTR_LAST_NAME, last_name);
}
Boolean enable = getAttr(attributes, OperationalAttributes.ENABLE_NAME, Boolean.class);
if (enable != null) {
if (! enable) {
JSONArray rolesJsonArray = new JSONArray();
jsonObject.put(ATTR_ROLES, (Object) rolesJsonArray);
}
else {
String[] rolecheck = getMultiValAttr(attributes, ATTR_ROLES, null);
if (rolecheck == null || rolecheck[0] == null) {
JSONArray rolesJsonArray = new JSONArray();
rolesJsonArray.put(0, (Object) "subscriber");
jsonObject.put(ATTR_ROLES, (Object) rolesJsonArray);
}
}
}
String[] roles = getMultiValAttr(attributes, ATTR_ROLES, null);
if ( roles != null ) {
JSONArray rolesJsonArray = new JSONArray();
for ( int i = 0; i < roles.length; i++) {
String role = roles[i];
JSONObject roleJsonObject = new JSONObject(role);
//JSONObject roleJsonObject = new JSONObject();
//roleJsonObject.put(role);
rolesJsonArray.put(i, (Object) roleJsonObject);
rolesJsonArray.put(i, (Object) role);
}
jsonObject.put(ATTR_ROLES, (Object) rolesJsonArray);
}
Expand Down Expand Up @@ -643,6 +677,14 @@ protected JSONObject callRequest(HttpEntityEnclosingRequestBase request, JSONObj
throw new AlreadyExistsException(jo.getString(ATTR_MAIL));
}
}
if (statusCode == 404) {
JSONObject errorResult = new JSONObject(responseText);
//JSONObject errorData = errorResult.getJSONObject("data");
if (errorResult.getString("code").equals("rest_user_invalid_id")) {
closeResponse(response);
throw new UnknownUidException(errorResult.toString());
}
}
processResponseErrors(response);
JSONObject result = new JSONObject (responseText);
LOG.info("response body: ");
Expand Down

0 comments on commit 8cc8d79

Please sign in to comment.