Lightbend Activator

Play Framework SSL/TLS Example

Play Framework SSL/TLS Example

July 7, 2014
playframework scala tls https ssl playws

A Play application using HTTPS and WS with optional client authentication

How to get "Play Framework SSL/TLS Example" on your computer

There are several ways to get this template.

Option 1: Choose play-tls-example in the Lightbend Activator UI.

Already have Lightbend Activator (get it here)? Launch the UI then search for play-tls-example in the list of templates.

Option 2: Download the play-tls-example project as a zip archive

If you haven't installed Activator, you can get the code by downloading the template bundle for play-tls-example.

  1. Download the Template Bundle for "Play Framework SSL/TLS Example"
  2. Extract the downloaded zip file to your system
  3. The bundle includes a small bootstrap script that can start Activator. To start Lightbend Activator's UI:

    In your File Explorer, navigate into the directory that the template was extracted to, right-click on the file named "activator.bat", then select "Open", and if prompted with a warning, click to continue:

    Or from a command line:

     C:\Users\typesafe\play-tls-example> activator ui 
    This will start Lightbend Activator and open this template in your browser.

Option 3: Create a play-tls-example project from the command line

If you have Lightbend Activator, use its command line mode to create a new project from this template. Type activator new PROJECTNAME play-tls-example on the command line.

Option 4: View the template source

The creator of this template maintains it at

Option 5: Preview the tutorial below

We've included the text of this template's tutorial below, but it may work better if you view it inside Activator on your computer. Activator tutorials are often designed to be interactive.

Preview the tutorial

Play TLS Example


Please see the README for instructions on how to configure and run Play to run over HTTPS.

In particular, note that you must have the following:

  • Be running JDK 1.8
  • Have generated certificates according to the README
  • Added to /etc/hosts
  • Be running the included ./play script
Server HTTPS

Play is capable of running HTTPS on the server. Play's SSLEngine can be configured for client authentication.

In this example, CustomSSLEngineProvider does the work of setting up the SSLEngine's parameters.

Client HTTPS

Play can also talk to an HTTPS server using Play WS, even using client authentication. With some additional code, it can use Play WS to communicate outside of Play's application context.

In this example, the Main class can be run independently, and will connect to the Play HTTPS server. Play WS will use Play WS SSL configured with the ws.conf to set up the appropriate passwords and key stores.