2020-11-18 19:01:40 +01:00
|
|
|
{
|
|
|
|
"ownerApp" : "Orchestrator",
|
|
|
|
"name" : "user-group_created",
|
|
|
|
"createBy" : "Marco Lettere",
|
|
|
|
"description": "Handle workflow related to Portal event user-group_created",
|
|
|
|
"version" : 1,
|
|
|
|
"ownerEmail" : "m.lettere@gmail.com",
|
|
|
|
"inputParameters" : ["user", "group"],
|
|
|
|
"tasks" : [
|
|
|
|
{
|
2023-10-12 15:32:32 +02:00
|
|
|
"name": "INLINE_TASK",
|
2020-11-18 19:01:40 +01:00
|
|
|
"taskReferenceName": "init",
|
2023-10-12 15:32:32 +02:00
|
|
|
"type": "INLINE",
|
2020-11-18 19:01:40 +01:00
|
|
|
"inputParameters": {
|
2020-12-04 10:03:19 +01:00
|
|
|
"keycloak": "{{ keycloak }}/{{ keycloak_realm }}",
|
|
|
|
"keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}",
|
2022-03-01 12:33:31 +01:00
|
|
|
"user" : "${workflow.input.user}",
|
2020-11-18 19:01:40 +01:00
|
|
|
"group" : "${workflow.input.group}",
|
2023-10-12 15:32:32 +02:00
|
|
|
"evaluatorType" : "javascript",
|
2023-10-12 16:08:29 +02:00
|
|
|
"expression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; if(e($.user) || e($.group)) throw('User and Group must not be empty'); function f(){ var path = $.group.startsWith('%2F') ? $.group.split('%2F').slice(1) : [$.group]; return { 'tree' : Java.to(path, 'java.lang.String[]'), 'name' : path.slice(path.length-1)[0], 'search' : encodeURIComponent(path.slice(path.length-1)[0])}} f()"
|
2020-11-18 19:01:40 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name" : "pyrest",
|
|
|
|
"taskReferenceName" : "authorize",
|
|
|
|
"type" : "SIMPLE",
|
|
|
|
"inputParameters" : {
|
|
|
|
"url" : "${init.input.keycloak}/protocol/openid-connect/token",
|
|
|
|
"method" : "POST",
|
|
|
|
"headers" : {
|
|
|
|
"Accept" : "application/json"
|
|
|
|
},
|
|
|
|
"body" : {
|
|
|
|
"client_id" : "orchestrator",
|
|
|
|
"client_secret" : "{{ keycloak_auth }}",
|
|
|
|
"grant_type" : "client_credentials"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name" : "pyrest",
|
|
|
|
"taskReferenceName" : "lookup_user",
|
|
|
|
"type" : "SIMPLE",
|
|
|
|
"inputParameters" : {
|
|
|
|
"url" : "${init.input.keycloak_admin}/users?username=${workflow.input.user}",
|
|
|
|
"method" : "GET",
|
|
|
|
"headers" : {
|
|
|
|
"Authorization" : "Bearer ${authorize.output.body.access_token}",
|
|
|
|
"Accept" : "application/json"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-02-17 18:08:52 +01:00
|
|
|
{
|
2023-10-12 15:32:32 +02:00
|
|
|
"name": "INLINE_TASK",
|
2022-03-01 12:33:31 +01:00
|
|
|
"taskReferenceName": "select_user",
|
|
|
|
"inputParameters": {
|
|
|
|
"foundusers": "${lookup_user.output.body}",
|
|
|
|
"username": "${workflow.input.user}",
|
2023-10-12 15:32:32 +02:00
|
|
|
"evaluatorType" : "javascript",
|
|
|
|
"expression": "function f(){for(var i=0; i < $.foundusers.length;i++){if($.foundusers[i]['username'] == $.username) return $.foundusers[i]}} f()"
|
2022-03-01 12:33:31 +01:00
|
|
|
},
|
2023-10-12 15:32:32 +02:00
|
|
|
"type": "INLINE"
|
2020-11-18 19:01:40 +01:00
|
|
|
},
|
|
|
|
{
|
2023-10-12 15:32:32 +02:00
|
|
|
"name": "check_user_existance",
|
|
|
|
"taskReferenceName": "check_user_existance",
|
|
|
|
"inputParameters": {
|
2023-10-12 16:17:14 +02:00
|
|
|
"user": "${select_user.output.result}"
|
2023-10-12 15:32:32 +02:00
|
|
|
},
|
|
|
|
"type": "SWITCH",
|
|
|
|
"evaluatorType" : "javascript",
|
|
|
|
"expression": "($.user == null ? 'true' : 'false')",
|
|
|
|
"decisionCases": {
|
|
|
|
"true": [
|
|
|
|
{
|
|
|
|
"name" : "terminate",
|
|
|
|
"taskReferenceName" : "terminate_when_no_user",
|
|
|
|
"type" : "TERMINATE",
|
|
|
|
"inputParameters" : {
|
|
|
|
"terminationStatus" : "COMPLETED"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-03-11 12:52:07 +01:00
|
|
|
},
|
|
|
|
{
|
2022-03-01 12:33:31 +01:00
|
|
|
"name" : "pyrest",
|
|
|
|
"taskReferenceName" : "look_up_groups",
|
|
|
|
"type" : "SIMPLE",
|
|
|
|
"inputParameters" : {
|
2022-03-01 15:34:54 +01:00
|
|
|
"url" : "${init.input.keycloak_admin}/groups?search=${init.output.result.search}",
|
2022-03-01 12:33:31 +01:00
|
|
|
"headers" : {
|
|
|
|
"Authorization" : "Bearer ${authorize.output.body.access_token}",
|
|
|
|
"Accept" : "application/json"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2023-10-12 15:32:32 +02:00
|
|
|
"name": "INLINE_TASK",
|
2022-03-01 12:33:31 +01:00
|
|
|
"taskReferenceName": "extract_group",
|
2023-10-12 15:32:32 +02:00
|
|
|
"type": "INLINE",
|
2022-03-01 12:33:31 +01:00
|
|
|
"inputParameters": {
|
|
|
|
"tree" : "${init.output.result.tree}",
|
|
|
|
"groups" : "${look_up_groups.output.body}",
|
2023-10-12 16:21:59 +02:00
|
|
|
"expression": "function selectByPath(groups, path, level) { for (var i=0; i < groups.length; i++) {if (groups[i].name === path[level]) {if (level === path.length - 1) return groups[i];return selectByPath(groups[i].subGroups, path, level+1)}} return null; } function f() { return { 'group' : selectByPath($.groups, $.tree, 0)}} f()",
|
|
|
|
"evaluatorType" : "javascript"
|
2020-11-18 19:01:40 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2022-03-01 12:33:31 +01:00
|
|
|
"name" : "check_group_existance",
|
|
|
|
"taskReferenceName" : "check_group_existance",
|
2023-10-12 15:32:32 +02:00
|
|
|
"type" : "SWITCH",
|
|
|
|
"evaluatorType" : "javascript",
|
2020-11-18 19:01:40 +01:00
|
|
|
"inputParameters" :{
|
2022-03-01 12:43:30 +01:00
|
|
|
"group" : "${extract_group.output.result.group}"
|
2020-11-18 19:01:40 +01:00
|
|
|
},
|
2023-10-12 15:32:32 +02:00
|
|
|
"expression": "(($.group != null) ? 'assign' : 'skip')",
|
2020-11-18 19:01:40 +01:00
|
|
|
"decisionCases" : {
|
2022-03-01 12:33:31 +01:00
|
|
|
"assign" : [
|
2020-11-18 19:01:40 +01:00
|
|
|
{
|
|
|
|
"name" : "pyrest",
|
|
|
|
"taskReferenceName" : "assign_user_to_group",
|
|
|
|
"type" : "SIMPLE",
|
|
|
|
"inputParameters" : {
|
2023-10-12 16:12:04 +02:00
|
|
|
"url" : "${init.input.keycloak_admin}/users/${select_user.output.result.id}/groups/${extract_group.output.result.group.id}",
|
2020-11-18 19:01:40 +01:00
|
|
|
"method" : "PUT",
|
|
|
|
"headers" : {
|
|
|
|
"Authorization" : "Bearer ${authorize.output.body.access_token}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|