Grails session.user, user already logged in
Im using "session.user" to do a simple login system to my website. Is there any way of knowing if a user is alrea开发者_高级运维dy logged in or not, whitout having to store that information in the DB ?
It's never a good idea to roll your own security implementation. You want your site to end up on Slashdot because it's awesome, not because you thought you were more clever than hackers.
Use http://grails.org/plugin/spring-security-core or http://grails.org/plugin/shiro - they're both simple to get started with but have lots of optional advanced features.
You could just check if session.user exists or not. If it does, then the user is logged in, it does not, then user is not logged in.
You can use grails Filters to check that before getting to your controller. From the grails docs (Filter Types):
class SecurityFilters {
def filters = {
loginCheck(controller:'*', action:'*') {
before = {
if(!session.user && !actionName.equals('login')) {
redirect(action:'login')
return false
}
}
}
}
}
精彩评论