|
1 | 1 | # Lightstreamer - Authentication and Authorization Demo - Java Adapter |
2 | 2 |
|
3 | | -TODO |
| 3 | +The Lightstreamer Authentication and Authorization Demo is a simple example illustrating authentication and authorization mechanisms when an external |
| 4 | +Web/Application Server is involved in the process. |
| 5 | + |
| 6 | +This project includes a simple MetadataProvider implementation that includes user validation and items authorization logics. |
| 7 | + |
| 8 | + |
| 9 | +##Details |
| 10 | + |
| 11 | +This *Authentication and Authorization Demo* illustrates the typical best practice used for Lightstreamer Web applications, when a Web/Application server is involved in the process. |
| 12 | +The actual authentication is usually handled by the legacy Web/Application server, irrespective of Lightstreamer. |
| 13 | +Some sort of token is sent back to the Client through cookies, response payload or any other technique. |
| 14 | +When the Web Client creates the Lightstreamer session, instead of sending again the full credentials (usually involving a password) to |
| 15 | +Lightstreamer Server, it sends just the username and the token. |
| 16 | +The Metadata Adapter is passed this information and validates the token against the Web/Application Server that |
| 17 | +generated it (or a database or whatever back-end system). |
| 18 | + |
| 19 | +Here an overview of the whole sequence: |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +In this demo client the Web/Application server is not actually involved and calls to placeholder methods are performed to validate the token. |
| 24 | + |
| 25 | +from `src/authmetadata_demo/adapters/AuthMetadataAdapter.java`: |
| 26 | +```java |
| 27 | +[...] |
| 28 | + |
| 29 | +if (!AuthorizationRequest.isValidToken(user, token)) { |
| 30 | + throw new AccessException("Invalid user/token"); |
| 31 | +} |
| 32 | + |
| 33 | +[...] |
| 34 | +``` |
| 35 | + |
| 36 | +This demo also implements Authorization handling of item subscription requests. |
| 37 | +Every time a subscription is issued, the adapter verifies if the user issuing the request is actually authorized to subscribe to the selected item(s). |
| 38 | +Again, a real case might query an external service to know the various authroizations, while this demo example simply checks on an hard-coded list |
| 39 | + |
| 40 | +from `src/authmetadata_demo/adapters/AuthMetadataAdapter.java`: |
| 41 | +```java |
| 42 | +[...] |
| 43 | + |
| 44 | +if (!AuthorizationRequest.canUserSeeItems(user, items)) { |
| 45 | + throw new CreditsException(-1, "User not authorized", "You are not authorized to see this item"); |
| 46 | +} |
4 | 47 |
|
| 48 | +[...] |
| 49 | +``` |
| 50 | + |
| 51 | +Querying an external service at subscription time is a discouraged approach. If the authorizations are actually placed on an external service, |
| 52 | +it is suggested to use the approach shown in the AuthMetadataAdapterWithAuthCache class. |
| 53 | + |
| 54 | +More details and comments on how the auth/auth cycle is accomplished is available in the source code of the application. |
| 55 | + |
| 56 | +##Deploy |
| 57 | + |
| 58 | +To have something to show to the user (i.e.: items to be subscribed), this demo relies on the the QUOTE_ADAPTER, from the Stock-List Demo |
| 59 | +(see [Lightstreamer - Stock-List Demo - Java Adapter](https://github.com/Weswit/Lightstreamer-example-StockList-adapter-java) ). |
| 60 | + |
| 61 | +* Download Lightstreamer Server (Lightstreamer Server comes with a free non-expiring demo license for 20 connected users) from Lightstreamer Download page, and install it, as explained in the GETTING_STARTED.TXT file in the installation home directory. |
| 62 | +Make sure that Lightstreamer Server is not running. |
| 63 | +* Get the deploy.zip file, from the releases of this project, unzip it, go to the Deployment_LS folder and copy the AuthDemo folder into the adapters |
| 64 | +folder of your Lightstreamer Server installation. |
| 65 | +* Launch Lightstreamer Server. |
| 66 | + |
| 67 | +##Build |
| 68 | + |
| 69 | +TODO |
5 | 70 |
|
6 | 71 | ### The Adapter Set Configuration |
7 | 72 |
|
@@ -34,4 +99,10 @@ The `adapters.xml` file for the *Authentication and Authorization Demo*, should |
34 | 99 | </data_provider> |
35 | 100 |
|
36 | 101 | </adapters_conf> |
37 | | -``` |
| 102 | +``` |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +### Related Projects |
| 107 | + |
| 108 | +* [Lightstreamer - Reusable Metadata Adapters - Java Adapter](https://github.com/Weswit/Lightstreamer-example-ReusableMetadata-adapter-java) |
0 commit comments