One of the basic functions of an application is the need for authentication and authorization. If you only have basic needs and checks, you can use the security module that is already bundled with Play. This recipe shows simple use cases for it.
You can find the source code of this example in the chapter3/secure
directory.
Create an application and put the security module in the configuration. Though you do need to install the module, you do not need to specify a version because it is built in with the standard Play distribution. The conf/dependencies.yml
entry looks like the following:
require: - play - play -> secure
As usual, nothing is complete without a test, here it goes:
public class SecurityTest extends FunctionalTest { @Test public void testThatIndexPageNeedsLogin() { Response response = GET("/"); assertStatus(302, response); assertLocationRedirect("/login", response); } @Test public void...