Skip to content

Commit

Permalink
Migrate auth JDBC example to auth SQL
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Segismont <[email protected]>
  • Loading branch information
tsegismont committed Jun 28, 2023
1 parent adcfb3a commit dfe86a4
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 108 deletions.
119 changes: 41 additions & 78 deletions web-examples/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

Here you will find examples demonstrating Vert.x-Web in action.

Vert.x-Web is a tool-kit for writing web applications with Vert.x. Please consult the Vert.x-Web manual for detailed
documentation on Vert.x-Web.
Vert.x-Web is a tool-kit for writing web applications with Vert.x.
Please consult the Vert.x-Web manual for detailed documentation on Vert.x-Web.

== Logging

Expand All @@ -26,8 +26,7 @@ Group ID: io.vertx
Artifact ID: vertx-web
----

If you're using a template engine you will also need to add the engine dependency explicitly, depending on the engine
you are using.
If you're using a template engine you will also need to add the engine dependency explicitly, depending on the engine you are using.

== Hello World

Expand Down Expand Up @@ -60,16 +59,15 @@ This example shows a simple web-site containing some static pages and also a pag

The link:src/main/java/io/vertx/example/web/templating/[templating example]

Multiple examples with different templating engines, including FreeMarker, Handlebars, MVEL, Pebble, Rocker,
and Thymeleaf are available.
Multiple examples with different templating engines, including FreeMarker, Handlebars, MVEL, Pebble, Rocker, and Thymeleaf are available.

Run the server in your IDE, then open your browser and hit
link:http://localhost:8080/[localhost:8080] and click on the links

== Sessions example

This example shows how to use sessions with Vert.x-Web. Sessions are available between requests and last the length of the
browser session.
This example shows how to use sessions with Vert.x-Web.
Sessions are available between requests and last the length of the browser session.

The link:src/main/java/io/vertx/example/web/sessions/[Java sessions example]

Expand All @@ -78,9 +76,7 @@ The example increments a counter in the session every time a request hits the se
Run the server in your IDE, then open your browser and hit
link:http://localhost:8080/[localhost:8080] then refresh the page a few times - you should see the hit count increase.

NOTE: Depending on your browser you may see it increase by two each time you refresh!Why is that?Some browsers will
actually send two HTTP requests every time you refresh - one to request the favicon for the site and one to request the
actual page.
NOTE: Depending on your browser you may see it increase by two each time you refresh!Why is that?Some browsers will actually send two HTTP requests every time you refresh - one to request the favicon for the site and one to request the actual page.

== Real-time - client side event bus

Expand All @@ -97,21 +93,17 @@ This is ideal for so-called _real-time_ web applications where you want quick, r

Run the server in your IDE, then open your browser and hit link:http://localhost:8080

This serves the link:src/main/java/io/vertx/example/web/realtime/webroot/index.html[index page] which contains
some JavaScript which opens an event bus connection to the server.
This serves the link:src/main/java/io/vertx/example/web/realtime/webroot/index.html[index page] which contains some JavaScript which opens an event bus connection to the server.

When the connection is open, a handler is registered on the event bus against the address `news-feed`.When data
arrives in the handler the script just uses some simple JQuery to write the message to the page.
When the connection is open, a handler is registered on the event bus against the address `news-feed`.When data arrives in the handler the script just uses some simple JQuery to write the message to the page.

On the server side, in the link:src/main/java/io/vertx/example/web/realtime/Server.java[server] we set a periodic
timer that fires every second and sends a message to the `news-feed` address.
On the server side, in the link:src/main/java/io/vertx/example/web/realtime/Server.java[server] we set a periodic timer that fires every second and sends a message to the `news-feed` address.

When you get the index page in your browser you should see it update every second as it receives a message.

== Real-time - chat service

This example demonstrates 2-way communication between the client and the server using the event bus bridge
and web sockets.
This example demonstrates 2-way communication between the client and the server using the event bus bridge and web sockets.

The link:src/main/java/io/vertx/example/web/chat/Server.java[Java real-time chat example]

Expand All @@ -135,18 +127,13 @@ Requests to paths starting with `/private/` will require login.
The example uses a simple auth service which gets user/password/role information from a properties file
`src/main/resources/vertx-users.properties`.

The type of login used here is redirect login.If a request is made to a private resource and the session isn't already
logged in a redirect will be sent to the browser causing it to load the login page.When the login form is submitted it
is handled by the form login handler which then redirects the browser back to the originally requested resource if login
was successful.
The type of login used here is redirect login.If a request is made to a private resource and the session isn't already logged in a redirect will be sent to the browser causing it to load the login page.When the login form is submitted it is handled by the form login handler which then redirects the browser back to the originally requested resource if login was successful.

Run the server in your IDE, then open your browser and hit
link:http://localhost:8080 and click around the links
Run the server in your IDE, then open your browser and hit link:http://localhost:8080 and click around the links

== Cookie example

This example shows a basic user Tracking system based on Cookies.On each page refresh a cookie is incremented with the
number of visits.
This example shows a basic user Tracking system based on Cookies.On each page refresh a cookie is incremented with the number of visits.

The link:src/main/java/io/vertx/example/web/cookie/[Java cookie example]

Expand All @@ -157,19 +144,13 @@ Cross-origin resource sharing (CORS) is a mechanism that allows restricted resou

The link:src/main/java/io/vertx/example/web/cors/[Java cors example]

CORS requests fall in two types, request that require a pre-flight check and requests that do not require it.HTTP GET
does not require such a check while other HTTP verbs do.When the CORS handler is active the `Origin` header is checked
to allow, disallow the request.
CORS requests fall in two types, request that require a pre-flight check and requests that do not require it.HTTP GET does not require such a check while other HTTP verbs do.When the CORS handler is active the `Origin` header is checked to allow, disallow the request.

In order to run the example, you need to download the 2 example HTML pages and run them from your hard disk.If you are
using a modern browser when clicking on the links they will pop up the download pop-up, however this might not work for
older browsers.
In order to run the example, you need to download the 2 example HTML pages and run them from your hard disk.If you are using a modern browser when clicking on the links they will pop up the download pop-up, however this might not work for older browsers.

If the CORS Handler is not present, then only the no preflight check call will work, since the browser will disallow the
POST.
If the CORS Handler is not present, then only the no preflight check call will work, since the browser will disallow the POST.

Run the server in your IDE, then open your browser and hit
link:http://localhost:8080 and click around the links
Run the server in your IDE, then open your browser and hit link:http://localhost:8080 and click around the links

== Upload example

Expand All @@ -187,8 +168,7 @@ This example shows a basic HTML form web-site and a backend end point that just

The link:src/main/java/io/vertx/example/web/form/[Java form example]

Run the server in your IDE, then open your browser and hit
link:http://localhost:8080 and click around the links
Run the server in your IDE, then open your browser and hit link:http://localhost:8080 and click around the links

== JWT example

Expand All @@ -202,18 +182,15 @@ This exclusion is normally used as the login end point, however in this example
The application contains a simple form where you can request some data from the API if there is no token loaded then the response is an `HTTP error 401`.
When a token is loaded, then a successful response if received from the API.

Run the server in your IDE, then open your browser and hit
link:http://localhost:8080 and click around the links
Run the server in your IDE, then open your browser and hit link:http://localhost:8080 and click around the links

== Blocking handler example

This example shows a blocking handler which blocks the calling thread for 5 seconds before calling the next handler
to serve the page.
This example shows a blocking handler which blocks the calling thread for 5 seconds before calling the next handler to serve the page.

Blocking handlers are run on a worker thread and don't block an event loop.

Run the server in your IDE, then open your browser and hit
link:http://localhost:8080 - after 5 seconds the response should arrive.
Run the server in your IDE, then open your browser and hit link:http://localhost:8080 - after 5 seconds the response should arrive.

== Static web server example

Expand All @@ -223,26 +200,24 @@ The server can be run either in your IDE with the main class or at the command l

== SQL Client example

This example shows a basic REST server backed by a SQL client. It is exactly the same as the REST client however its
data is persisted in a relational database using the asynchronous SQL client.
This example shows a basic REST server backed by a SQL client.
It is exactly the same as the REST client however its data is persisted in a relational database using the asynchronous SQL client.

The link:src/main/java/io/vertx/example/web/sqlclient/[SQL client example]

Run the server in your IDE, then open your browser and hit
link:http://localhost:8080/products to get the list of products, or link:http://localhost:8080/products/0 for accessing
a product with id 0. In order to create new products use the POST method to link:http://localhost:8080/products
Run the server in your IDE, then open your browser and hit link:http://localhost:8080/products to get the list of products, or link:http://localhost:8080/products/0 for accessing a product with id 0. In order to create new products use the POST method to link:http://localhost:8080/products

- curl http://localhost:8080/products
- curl http://localhost:8080/products/Spatula
- curl -X POST -H "Content-Type: application/json" -d '{"name":"Spoon","price":1.0,"weight":1.0}' http://localhost:8080/products

== Auth JDBC example
== Auth SQL example

This example shows a basic static web-site that contains both public pages and pages that are only accessible to a logged-in user.
This is a remake of the auth example, however using a different auth provider.
In this case it uses the JDBC Auth Provider.
In this case it uses the SQL Client Auth Provider.

The link:src/main/java/io/vertx/example/web/authjdbc/[Java authjdbc example]
The link:src/main/java/io/vertx/example/web/authsql/[Java authsql example]

Requests to paths starting with `/private/` will require login.

Expand All @@ -252,8 +227,7 @@ Run the server in your IDE, then open your browser and hit link:http://localhost

== Angular realtime example

This example shows a music store implemented with angular js, where all album data and orders are taken in realtime.The
example expects that there is a local instance of mongo db running.
This example shows a music store implemented with angular js, where all album data and orders are taken in realtime.The example expects that there is a local instance of mongo db running.

It also demonstrates how to protect the even bus when used with a bridge using one `Auth Provider`.

Expand All @@ -262,16 +236,13 @@ The link:src/main/java/io/vertx/example/web/angular_realtime/[Java angular_realt
The example uses a simple auth service which gets user/password/role information from a properties file
`src/main/resources/vertx-users.properties`.

Run the server in your IDE, then open your browser and hit
link:http://localhost:8080 and click around the links
Run the server in your IDE, then open your browser and hit link:http://localhost:8080 and click around the links

== Programmatic Authentication examples

This examples shows how to use the Auth Handlers to protect resources by asserting if the user has the right authorities
to access the resource.
This examples shows how to use the Auth Handlers to protect resources by asserting if the user has the right authorities to access the resource.

There are 2 implementations, one using the API to verify assertions, and a second where assertions are implemented in
code:
There are 2 implementations, one using the API to verify assertions, and a second where assertions are implemented in code:

* link:src/main/java/io/vertx/example/web/authorisation/[Java authorisation example]
* link:src/main/java/io/vertx/example/web/custom_authorisation/[Java custom_authorisation example]
Expand All @@ -283,17 +254,14 @@ The example shows 4 resource that require different authorities:
* defcon2 link:http://localhost:8080/api/protected/defcon2
* defcon3 link:http://localhost:8080/api/protected/defcon3

You can generate different tokens with different authorities and test it. The example html does not generate defcon3
tokens, in order to show that you cannot access the last resource.
You can generate different tokens with different authorities and test it.
The example html does not generate defcon3 tokens, in order to show that you cannot access the last resource.

Run the server in your IDE, then open your browser and hit
link:http://localhost:8080 and click around the links
Run the server in your IDE, then open your browser and hit link:http://localhost:8080 and click around the links

== HTTP2

The HTTP2 example is a simplified http://http-test-2.frb.io/chuck-norris.html[Chuck Norris] test.The important thing to
note is that there is no API differences between HTTP1.1 and HTTP2 regarding web.The only change is the bootstrap of
the server.
The HTTP2 example is a simplified http://http-test-2.frb.io/chuck-norris.html[Chuck Norris] test.The important thing to note is that there is no API differences between HTTP1.1 and HTTP2 regarding web.The only change is the bootstrap of the server.

The link:src/main/java/io/vertx/example/web/http2/Server.java[HTTP2 example]

Expand All @@ -307,13 +275,11 @@ Important files to note:
* link:src/main/java/io/vertx/example/web/react/app-client.js[React app example]
* link:src/main/java/io/vertx/example/web/react/Server.java[Java Vert.x server]

Run the server in your IDE, then open your browser and hit
link:http://localhost:8080 and chat with a couple of browser windows!
Run the server in your IDE, then open your browser and hit link:http://localhost:8080 and chat with a couple of browser windows!

== OAuth2

The OAuth2 example is a simplified interaction with GitHub OAuth2 server.It will
show how to secure and authenticate users, plus requesting specific authorities:
The OAuth2 example is a simplified interaction with GitHub OAuth2 server.It will show how to secure and authenticate users, plus requesting specific authorities:

* `user:email`

Expand All @@ -323,12 +289,10 @@ The link:src/main/java/io/vertx/example/web/oauth2/Server.java[OAuth2 example]

== HTTP Request Validation and OpenAPI 3 Router Factory

The link:src/main/java/io/vertx/example/web/validation/ValidationExampleServer.java[ValidationExampleServer] is an
example of various usages of validation capabilities included in
The link:src/main/java/io/vertx/example/web/validation/ValidationExampleServer.java[ValidationExampleServer] is an example of various usages of validation capabilities included in
link:http://vertx.io/docs/#web[Vert.x Web API Contract package]

The link:src/main/java/io/vertx/example/web/openapi3/OpenAPI3Server.java[OpenAPI3Server] is an example of
OpenAPI3RouterFactory, the interface to build your design driven router based on your OpenAPI specification.
The link:src/main/java/io/vertx/example/web/openapi3/OpenAPI3Server.java[OpenAPI3Server] is an example of OpenAPI3RouterFactory, the interface to build your design driven router based on your OpenAPI specification.

== Web Proxy example

Expand All @@ -346,5 +310,4 @@ The example is showing that you can mix other handlers with the `ProxyHandler` l

== gRPC example

The link:src/main/java/io/vertx/example/web/grpc/helloworld/Server.java[Server] is an
example of integrating a routing gRPC traffic to a gRPC server.
The link:src/main/java/io/vertx/example/web/grpc/helloworld/Server.java[Server] is an example of integrating a routing gRPC traffic to a gRPC server.
2 changes: 1 addition & 1 deletion web-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-jdbc</artifactId>
<artifactId>vertx-auth-sql-client</artifactId>
<version>${project.version}</version>
</dependency>

Expand Down
Loading

0 comments on commit dfe86a4

Please sign in to comment.