First we try to call the /rest-api/hello
end-point of the demo application
without any authentication:
$ curl localhost:8080/rest-api/hello -v
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /rest-api/hello HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 403 Forbidden
< Connection: keep-alive
< Content-Type: text/html;charset=UTF-8
< Content-Length: 34
< Date: Sun, 01 May 2022 11:31:35 GMT
<
* Connection #0 to host localhost left intact
Access forbidden: role not allowed
In contrast, to Payara (Glassfish) the Wildfly application responds with an
status of 403 (Forbidden), when actually status 401 (Unauthorized) is expected.
Because the (basic) authentication information was not provided at all, the
401 response of Payara (Glassfish) makes much more sense. But for a REST API
this may be acceptable, even if not consistent with the specification.
For the next call of the REST API, we prepare an Authorization
header
accordingly and call the same end-point again:
$ echo -n "gunther:secret" | base64
Z3VudGhlcjpzZWNyZXQ=
$ curl localhost:8080/rest-api/hello -v -H"Authorization: Basic Z3VudGhlcjpzZWNyZXQ="
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /rest-api/hello HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: */*
> Authorization: Basic Z3VudGhlcjpzZWNyZXQ=
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Connection: keep-alive
< Content-Type: application/octet-stream
< Content-Length: 11
< Date: Sun, 01 May 2022 11:37:12 GMT
<
* Connection #0 to host localhost left intact
Hello world
This time the application is able to authenticate the provided user, returns
the greeting message and says "Hello world".
The next test requests the privileged end-point, which should only be accessible
for users of group admins
. We’re still providing the credentials of the
non-privileged user:
$ curl localhost:8080/rest-api/hello/privileged -v -H"Authorization: Basic Z3VudGhlcjpzZWNyZXQ="
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /rest-api/hello/privileged HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: */*
> Authorization: Basic Z3VudGhlcjpzZWNyZXQ=
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 403 Forbidden
< Connection: keep-alive
< Content-Type: text/html;charset=UTF-8
< Content-Length: 34
< Date: Sun, 01 May 2022 11:38:14 GMT
<
* Connection #0 to host localhost left intact
Access forbidden: role not allowed
In this case the application responds with HTTP status 403 (Forbidden), because
although the user could be authenticated, it is not authorized to access the
end-point.
Eventually, an Authorization
header for the privileged user is prepared and
added to the request:
$ echo -n "gunther_admin:topsecret" | base64
Z3VudGhlcl9hZG1pbjp0b3BzZWNyZXQ=
$ curl localhost:8080/rest-api/hello/privileged -v -H"Authorization: Basic Z3VudGhlcl9hZG1pbjp0b3BzZWNyZXQ="
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /rest-api/hello/privileged HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: */*
> Authorization: Basic Z3VudGhlcl9hZG1pbjp0b3BzZWNyZXQ=
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Connection: keep-alive
< Content-Type: application/octet-stream
< Content-Length: 22
< Date: Sun, 01 May 2022 11:39:30 GMT
<
* Connection #0 to host localhost left intact
Hello, privileged dude
The application server responds as expected with a greeting to the privileged
user.
After additional security configuration and activation of role-based security
for RESTeasy, the application behaves (almost) the same as on Payara (Glassfish).
The only exception is the unexpected response status when no authentication
information at all is provided.