How can I write a "user can only access own profile page" type of security check in Play Framework?

Posted by karianneberg on Stack Overflow See other posts from Stack Overflow or by karianneberg
Published on 2012-05-31T14:49:42Z Indexed on 2012/05/31 16:40 UTC
Read the original article Hit count: 245

I have a Play framework application that has a model like this: A Company has one and only one User associated with it.

I have URLs like http://www.example.com/companies/1234, http://www.example.com/companies/1234/departments, http://www.example.com/companies/1234/departments/employees and so on. The numbers are the company id's, not the user id's.

I want that normal users (not admins) should only be able to access their own profile pages, not other people's profile pages. So a user associated with the company with id 1234 should not be able to access the URL http://www.example.com/companies/6789

I tried to accomplish this by overriding Secure.check() and comparing the request parameter "id" to the ID of the company associated with the logged in user. However, this obviously fails if the parameter is called anything else than "id".

Does anyone know how this could be accomplished?

© Stack Overflow or respective owner

Related posts about security

Related posts about playframework