Node class
The Node
class can access and modify the persisted state shared between the nodes within a tree,
and can request input by using callbacks. The class also defines the possible exit paths from the node.
In Java terms, an authentication node is a class that implements the Node
interface,
org.forgerock.openam.auth.node.api.Node
.
The SetSessionProperties
class shows the steps to implement the Node interface:
package org.forgerock.openam.auth.nodes;
import java.util.Map;
import javax.inject.Inject;
import org.forgerock.openam.annotations.sm.Attribute;
import org.forgerock.openam.auth.node.api.Action;
import org.forgerock.openam.auth.node.api.Node;
import org.forgerock.openam.auth.node.api.SingleOutcomeNode;
import org.forgerock.openam.auth.node.api.TreeContext;
import org.forgerock.openam.auth.nodes.validators.SessionPropertyValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.assistedinject.Assisted;
/*
* A node that defines a configurable set of properties to add to
* the user’s session if/when it is created.
*/
@Node.Metadata(outcomeProvider = SingleOutcomeNode.OutcomeProvider.class,
configClass = SetSessionPropertiesNode.Config.class,
tags = {"utilities"}) 1
public class SetSessionPropertiesNode extends SingleOutcomeNode { 2
/
* Configuration for the node.
/
public interface Config { 3
/
* A map of property name to value.
* @return a map of properties.
/
@Attribute(order = 100, validators = SessionPropertyValidator.class)
Map<String, String> properties();
}
private final Config config; 4
private final Logger logger = LoggerFactory.getLogger("SetSessionPropertiesNode.class");
/
* Constructs a new SetSessionPropertiesNode instance.
* @param config Node configuration.
*/
@Inject 5
public SetSessionPropertiesNode(@Assisted Config config) {
this.config = config;
}
@Override
public Action process(TreeContext context) { 6
logger.debug("SetSessionPropertiesNode started");
Action.ActionBuilder actionBuilder = goToNext();
config.properties().entrySet().forEach(property → {
actionBuilder.putSessionProperty(property.getKey(), property.getValue());
logger.debug("set session property {}", property);
});
return actionBuilder.build();
}
}
Step | Description | Further information |
---|---|---|
1 Apply the |
The annotation specifies the outcome provider, configuration class, and optionally, the configuration validation class and tags. Use an existing outcome provider such as |
|
2 Implement the |
Extend one of the following abstract classes to implement the
Alternatively, write your own implementation of the |
Javadoc:
|
3 Implement the |
The |
|
4 Define private constants and methods |
Optional |
|
5 Inject dependencies |
Inject objects using Guice as this makes it easier to unit test your node. This example specifies |
|
6 Override the |
The It takes a The method returns an The choice of outcome in a simple decision node would be |