-
Notifications
You must be signed in to change notification settings - Fork 12
PolicyAgent
The constructor function, whose argument should be an object of config options (listed below).
var config = {
serverUrl: 'http://openam.example.com:8080/openam',
appUrl: 'http://app.example.com:8080',
notificationRoute: '/',
notificationsEnabled: true,
username: 'my-agent',
password: 'changeit',
realm: '/',
logLevel: 'info'
};
var agent = new PolicyAgent(config);
-
serverUrl: The deployment URI of the OpenAM server, e.g.
http://openam.example.com:8080/openam
, -
appUrl: The root URL of the application, e.g.
http://app.example.com:8080
. -
notificationsEnabled: If enabled, the agent will cache sessions and register a change listener for them in OpenAM. Cached sessions will not be revalidated against OpenAM. The notifications middleware has be added to the express application for notifications to work (adds an
/agent/notifications
endpoint which can receive notifications from OpenAM). -
notificationRoute: The route to which the
notifications
middleware is attached.app.use('/foo/bar/baz', agent.notifications); app.listen(8080);
In the above case the
notificationRoute
should be/foo/bar/baz
. Notifications will be sent tohttp://app.example.com:8080/foo/bar/baz/agent/notifications
. -
username: The agent's username in OpenAM
-
password: The agent's password in OpenAM
-
realm: Name of the realm in OpenAM in which the agent profile exists. Default:
/
-
errorPage: Callback function; If present, the function's return value will be sent as an error page, otherwise the default error template will be used.
config = { ... errorPage: function (status, message, details) { return '<html><body><h1>' + status + ' - ' + message + '</h1></body></html>' } ... }
-
logger:
winston Logger
A winstonjs logger instance. If falsy, a new Console logger is created. -
logLevel: logging level see winston's documentation Default:
error
. Only used when logger is falsy.
Short random ID that lets you differentiate agents in logs, etc.
The config object passed to the constructor.
A Promise returned by getServerInfo()
. Once resolved, the response is mixed into the serverInfo
object.
Originally an empty Promise (haha). Whenever a certain client request needs an agent session, the agent will get
authenticated and agentSession
will become a Promise returned by authenticateAgent()
. Once resolved, the response
is mixed into the agentSession
object.
An instance of OpenAMClient
.
An instance of NotificationHandler
that also serves as an EventEmitter
. Events are emitted when notifications are
received.
Express middleware that has a single route: /agent/notifications
.
-
session: a session service notification is received. Callbacks will be called with a
session
argument.
Authenticates the policy agent using the credentials in the config object. Returns Promise
.
Validates a given sessionId against OpenAM and adds a session listener if valid. Returns Promise
.
Fetches the user profile for a give UID.
Gets policy decisions from OpenAM for the req.originalUrl
resource and the application name specified in the agent
config (req
must be an instance of IncomingRequest
). Returns Promise
.
Constructs a RequestSet
document containing a AddSessionListener
node for sessionId
, and sends it to the
SessionService. Returns Promise
.