The initialization of the script sets the authentication method and credentials you want to use for accessing JasperReports Server. You can then use the login and logout functions to manage multiple user sessions.
This chapter contains the following sections:
• | Authentication Properties |
• | Authentication Functions |
• | Login With Plain Text Credentials |
• | Login With SSO Token |
• | Logging Out |
• | Login With Hooks |
• | UI for Login/Logout |
• | UI for Login/Logout With SSO Token |
• | Sharing Credentials Among Calls |
• | Using Visualize.js Without Authentication |
Authentication Properties
The properties argument to the visualize function has all the fields for specifying various authentication methods.
Authentication Functions
The Authentication module has functions for logging in and logging out.
There are several ways to set the user credentials, based on your environment.
Login With Plain Text Credentials
Use the methods of the Authentication module to set the credentials and perform login and logout operations.
Alternatively, you can specify the username, password, organization (if required), and optional parameters in the auth property of the visualize object itself.
Login With SSO Token
If you have single-sign-on (SSO) implemented and have configured JasperReports Server to use it, you can specify the SSO token in the Authentication module or Visualize.js. This example shows a token from a Central Authentication Service (CAS) server.
Or:
Some SSO implementations require encoding, additional parameters, or both. For example, if your server is configured for pre-authentication, you could use the following example to authenticate from Visualize.js. Note that the encoded fields depend on the specifics of your pre-authentication configuration:
If you have configured token-based pre-authentication with WebLogic Server, there is one additional setting needed for authentication to work properly with Visualize.js. Edit the file applicationContext-externalAuth-preAuth-mt.xml in the JasperReports Server web app, and remove the comments (<!-- -->) on the following line:
Logging Out
To log out and destroy the current user session, call the logout function and optionally specify any action to take when done.
Login With Hooks
If you have external authentication providers, you can invoke their login and logout URLs. Again, there are two similar forms, one with the Authentication module, and one with the auth properties.
The functions you define for login and logout must return a deferred object and accept two arguments:
• | properties – An object that contains all the required authentication properties. |
• | request – A request function your function can use to perform authentication from a website. |
Or:
UI for Login/Logout
You can define IDs (#name) with listeners that perform login and logout functions. In your HTML, you can then assign these IDs to the appropriate buttons or links.
UI for Login/Logout With SSO Token
The code is slightly different if you have a login/logout UI and use SSO tokens. Note that the logout uses the .always event instead of .done.
Sharing Credentials Among Calls
Use the visualize.config function to define and store authentication credentials. It uses the same auth structure as the visualize function. You can then create several containers with separate calls to visualize, using the common credentials.
Using Visualize.js Without Authentication
Internally, Visualize.js uses the REST API to authenticate and interact with the server. However, the REST client receives and reuses the JSESSIONID cookie that identifies it as authenticated, which is also the same cookie used in regular browser clients. Therefore, users who access the JasperReports Server web app UI and use the same browser to run a visualize.js client before their session expires don't need to authenticate in visualize.js.
If your visualize.js solution includes other browser windows or other authenticated REST calls, then you can simplify your visualize.js and remove the authentication:
Recommended Comments
There are no comments to display.