Incorporating Login/ Authentication into Play 2.x (Scala) application


Incorporating Login/ Authentication into Play 2.x

Krishna's Blog

For people in hurry here is the code and the steps.

In continuation of Play 2.x (Scala) is it a Spring MVC contender? – Introduction, in this blog, I will demonstrate how to extend Security.Authenticated standard Play API to implement basic authentication in your application.

I took this code play-test-security as my basis for implementing Security.Authenticated based authentication.

As a first step, I will extend this class to implement a Security trait as below,

As provided in the comment section it is clear what each method does. Next step is to plumb the login steps refer Application.scala as below,

The User Slick domain object and the authenticate method in User.scala looks as below,

Finally the CoffeesController.scala where we need to override onUnauthorized method and put the IsAuthenticated block in each action as below,

To test if authentication worked, start play,

And when you type the url http://localhost:9000/coffee, you get…

View original post 24 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s