public class AuthorizationPlugin extends Plugin implements com.ibm.rules.res.xu.engine.internal.AuthorizationProvider
The declaration of the AuthorizationPlugin can be done in the same way than other XU plug-ins. Unlike other
XU plug-ins, only one instance of an AuthorizationPlugin can be declared.
Example of using the configuration API of the RuleSession:
cfg = IlrJ2SESessionFactory.createDefaultConfig(); xuCfg = cfg.getXUConfig(); xuCfg.setLogLevel(Level.ALL); xuCfg.setLogWriter(new PrintWriter(System.out)); plugins = new ArrayList<IlrPluginConfig>(1); plugin = xuCfg.createPluginConfig(AuthPlugin.class.getName()); plugins.add(plugin); xuCfg.setPluginConfigs(plugins); factory = new IlrJ2SESessionFactory(cfg);
The "userdata" parameter of a session, which can be passed from
the IlrSession to the AuthorizationPlugin, can be
used to pass to the XU, the credential, or other data that
identifies the user who is willing to execute the ruleset.
The Rule Execution Server ruleset archive properties, which are
passed to the isRulesetExecutionAllowed method, can be
used to specify the list of authorized users for each ruleset.
class User {
private final String name;
public User(String name) {
this.name = name;
}
}
public class AuthPlugin extends AuthorizationPlugin {
/**
* Authorize only the users specified by the 'allowedUser'
* RES ruleset archive properties.
*/
@Override
public boolean isRulesetExecutionAllowed(String taskName,
IlrPath canonicalPath,
Map<String, String> rulesetProps,
Object userData) {
String allowedUser;
allowedUser = rulesetProps.get("allowedUser");
if (userData == null || !(userData instanceof User))
return false;
if (allowedUser != null && !allowedUser.trim().isEmpty())
return allowedUser.equals(((User) userData).name);
return true;
}
}
class Application {
[..]
sess = factory.createStatefulSession(path, new User("odmuser"), null, false, false);
sess.execute(); // will fail if the user is not authorized
[..]
Plugin| Constructor and Description |
|---|
AuthorizationPlugin() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isRulesetExecutionAllowed(java.lang.String taskName,
IlrPath canonicalPath,
java.util.Map<java.lang.String,java.lang.String> rulesetProps,
java.lang.Object userData)
Whether the execution of a given ruleset is allowed.
|
getRulesetUsageInformationMonitor, notifyRulesetArchiveChanged, release, startdestroy, executeRuleset, executeRuleset, getInteractionExtension, getWorkManager, getXUConfig, getXUInfo, isLoggable, log, setConnectionFactory, setLogHandler, setProperties, setResourceAdapter, setRulesetUsageInformationMonitor, setXUConfig, start, subscribe, unsubscribepublic boolean isRulesetExecutionAllowed(java.lang.String taskName,
IlrPath canonicalPath,
java.util.Map<java.lang.String,java.lang.String> rulesetProps,
java.lang.Object userData)
By default this method always returns true. Override this method to authorize or refuse the
execution of rulesets.
The implementation of this method must be thread-safe.
isRulesetExecutionAllowed in interface com.ibm.rules.res.xu.engine.internal.AuthorizationProvidertaskName - The name of the task of the ruleset to be executed. null if the execution request
does not specify a task.canonicalPath - The canonical ruleset path of the ruleset.rulesetProps - The RES ruleset archive properties of the ruleset.userData - The userData that is passed by the caller of the ruleset execution. Can be null.true if ruleset execution is allowed.© Copyright IBM Corp. 1987, 2017