I am new to Play Framework. I am doing practicing (Play+Java) by creating various types of scenario eg link with the DB, retrieve data from Database using JPA, Master Detail forms, saving data into database etc.
I want to implement user authentication. User login to application. To access application user must have authorization.
For example : Employee - Add/Edit/View/Delete. Some users may have all the authorization and some users have View only or Add/Edit/Delete or only Edit. Even in Employee Edit option user can only edit certain field eg Emplyee name is not allowed but employee's address can edit. ie field level authorization.
Thanks
use an Authentication Controller to check user login id/password class AuthController @Inject()(cache: CacheApi, cached: Cached, actorSystem: ActorSystem) extends Controller {
if id/password is correct, generate an UUID key, and stored user object (uservo) in memory cache with UUID key. The key can be stored in browser cookie.
val cacheTimeout = 10.minutes val key = UUID.randomUUID.toString cache.set(key, uservo, cacheTimeout) Ok().withSession( request.session + ("key" -> key) )
(request.session.get("key").flatMap { key => cache.get[Uservo](key) } map { uservo => // need to set cache with "key" again, or else the memory will timeout in 10 minutes cache.set(request.session.get("key").get, uservo, cacheTimeout) // do the action.. }).orElse { // failed and return to login home page Some(Future(Redirect("/").withNewSession)) }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.