Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add to AS session the data passed in Finish #3978

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/admin/developer/agama/dsl-full.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ Finish it.nonsense

- Any statements found after `Finish` is not reached and thus, not executed
- If no `Finish` statement is found in a flow's execution, this will degenerate in flow crash
- When a flow is finished and was used as subflow (part of the execution of a bigger parent flow), the parent does not terminate. Execution continues at the following instruction that triggered the subflow. More on `Trigger` later
- When a flow is finished and was used as [subflow](#subflows) (part of the execution of a bigger parent flow), the parent does not terminate. Execution continues at the following instruction that triggered the subflow. More on `Trigger` later
- Using `data` in the `Finish` directive is an effective way to communicate information to callers (parent flows). If a flow has no parents, `data` is stored in the authentication server's session of the given user under the key `agamaData`. Contents are serialized to a JSON string previously
- A flow cannot be aborted by itself. This can only be achieved through a parent flow. Learn more about aborted flows [here](./flows-lifecycle.md#cancellation)
- Check the best practices on finishing flows [here](./flows-lifecycle.md#finishing-flows)

Expand Down
4 changes: 4 additions & 0 deletions docs/admin/developer/agama/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ To fix a serialization problem, try some of the following:

This is a limitation of the scripting engine. Here, classes have to be imported even if they belong to the same package, or the fully qualified name used.

### A class is still available after removing the corresponding file

This is because the JVM does not support unloading: even if a given source file is removed, its corresponding class will still be accessible - it remains in the classpath. The classpath will be clean again after a service restart.

### How to append data to a flow's log directly?

Call method `log` of class `io.jans.agama.engine.script.LogUtils`. This method receives a variable number of arguments as DSL's `Log` does. Thus you can do `LogUtils.log("@w Today is Friday %th", 13)`, as in the logging [examples](./dsl-full.md#logging).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Janssen Project software is available under the Apache 2.0 License (2004). See http://www.apache.org/licenses/ for full text.
# Copyright (c) 2020, Janssen Project
#

from com.fasterxml.jackson.databind import ObjectMapper

from io.jans.agama import NativeJansFlowBridge
from io.jans.agama.engine.misc import FlowUtils
from io.jans.as.server.security import Identity
Expand All @@ -13,6 +16,7 @@
from io.jans.util import StringHelper

from jakarta.faces.application import FacesMessage
from java.util import Arrays

import java
import sys
Expand All @@ -22,7 +26,9 @@ def __init__(self, currentTimeMillis):
self.currentTimeMillis = currentTimeMillis

def init(self, customScript, configurationAttributes):
print "Agama. Initialization"
print "Agama. Initialization"
self.resultParam = "agamaData"

prop = "cust_param_name"
self.cust_param_name = self.configProperty(configurationAttributes, prop)

Expand Down Expand Up @@ -78,6 +84,9 @@ def authenticate(self, configurationAttributes, requestParameters, step):
if not authenticated:
print "Agama. Unable to authenticate %s" % userId
return False

jsonData = CdiUtil.bean(ObjectMapper).writeValueAsString(data)
CdiUtil.bean(Identity).setWorkingParameter(self.resultParam, jsonData)
except:
print "Agama. Exception: ", sys.exc_info()[1]
return False
Expand Down Expand Up @@ -132,7 +141,7 @@ def prepareForStep(self, configurationAttributes, requestParameters, step):
return True

def getExtraParametersForStep(self, configurationAttributes, step):
return None
return Arrays.asList(self.resultParam)

def getCountAuthenticationSteps(self, configurationAttributes):
return 1
Expand Down