Basic Authentication Sample

This sample demonstrates how to configure Tyrus client to connect on access protected server endpoint over HTTPS.

Please note that we were able to run this sample only on Firefox (v27.01). Safari (v7.0.5) do not apply the exception to use unverified SSL certificate to WebSocket connection, which results in immediate end with reported error similar to "Invalid certificate chain". Chrome (v37) for some reason does not pass credentials (acquired from initial request) to new websocket connection, so it ends up with "401" HTTP response code without any way how the user can provide authentication info.

Contents

The application utilizes access protected endpoint org.glassfish.tyrus.sample.echo.auth.BasicAuthEchoEndpoint to receive messages, add the text and send it back. Server endpoint is configured in web.xml to be under access protected resource and Authentication scheme is set to Basic. Transport guarantee is set to CONFIDENTIAL, which basically means over HTTPS.

Configuration of client is quite simple, have a look at org.glassfish.tyrus.sample.echo.auth.SampleBasicAuthTest. If you use Basic or Digest Authentication scheme only ClientProperties.CREDENTIALS property must be set on client and that's it. Hint: It might be useful to deploy some static content into protected area with your server endpoint. If your client does not work at the first attempt you can simply test server configuration in web browser.

Running the Example with Glassfish

Run the example as follows: