2

i'm a bit new on the groovy grails technology and i'm having a problem with this one

i looked at this could not initialize proxy - no Session but the application don't get stale too long

I am trying to access the session object on my SecurityFilter placed on the config subfolder. I just wanted to do a check for every request on the controllers to verify if a user has the rights to do such actions.

class SecurityFilters {
    def filters = {

    userFilterList(controller:"user", action:"list") {
        before = {
            if (!session.user.accountType.equals("Admin")) {
                redirect(uri: "/")
            }
        }
    }
    userFilterShow(controller:"user", action:"show") {
        before = {
            if (!session.user.accountType.equals("Admin")) {
                redirect(uri: "/")
            }
        }
    }
    userFilterEdit(controller:"user", action:"edit") {
        before = {
            if (!session.user.accountType.equals("Admin")) {
                redirect(uri: "/")
            }
        }
    }

    }
}

but I get this error

Message: could not initialize proxy - no Session
Line | Method
->>    6 | doCall    in SecurityFilters$_closure1_closure2_closure5
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    186 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    603 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    636 | run       in java.lang.Thread

before I get to this point I placed the user object on the session object right after doing the login instructions but I am not sure what happened that the session object became not available

Community
  • 1
  • 1
chip
  • 3,039
  • 5
  • 35
  • 59

1 Answers1

2

some of the properties of the user object were not retrieved, so in the login when I put the user object in the on the session, I also had to manually transfer the property that I needed so I could retrieve again for later use

session.user = user //not enough
session.user.accountType = user.accountType

now I was able to retrieve the user object from the session object and get the property that I wanted to get

chip
  • 3,039
  • 5
  • 35
  • 59