Playing with authentication
A frequent piece of functionality needed when designing a new web application involves authentication and authorization. Authentication usually requires that the user provide the credentials to log in to the application in the form of a username/password. Authorization is the mechanism by which the system can ensure that a user can perform only the operations that he/she is entitled to. In this section, we are going to extend our helloworld
sample with security features that are part of the Play distribution, as a way to demonstrate how the usage of traits in Scala can provide an elegant solution to conventional problems.
Let's define a new controller that we will call Authentication
, which contains common methods such as login
to retrieve a sign-in page, authenticate
and check
to perform the verification of the authentication, and logout
to go back to the login page. This is done as follows:
object Authentication extends Controller { val loginForm = Form( ...