0

I'm trying to do this in my groovy class which is in src directory of my grails application.

Its an Filter. The class looks like this :

class Proxy implements Filter {
}

Inside the init method I'm getting the springSecurityService bean using :

GrailsApplication application = org.codehaus.groovy.grails.commons.ApplicationHolder.getApplication()
springSecurityService = application.getMainContext().getBean("springSecurityService")

And inside my doFilter I'm trying to find whether the user is been authenticated or not. I tried:

springSecurityService.isLoggedIn()

but its always returning false.

Where I'm making the mistake?

Thanks in advance.

sriram
  • 8,562
  • 19
  • 63
  • 82
  • Were you trying to create a Grails filter? If so there is a command to do so, and that will wire up everything for you – James Kleeh Jan 31 '13 at 13:33
  • Its not an grails filter. Its an class inside `src` directory. And I configured `web.xml` to intercept the requests. – sriram Jan 31 '13 at 13:41

2 Answers2

0

Try to use SecurityContextHolder

SecurityContextHolder.getContext().getAuthentication()

(but this is Java; I'm sure there is something similar you can find)

OhadR
  • 8,276
  • 3
  • 47
  • 53
0

Is it possible the order of your filters are incorrect? Your custom Filter would need to be invoked after the Spring Security Filter. If you perform new Exception().printStackTrace() inside your filter, do you see the SecurityContextPersistenceFilter in the stack? If not, then you need to change your Filter (Proxy) to be after the springSecurityFilterChain.

Rob Winch
  • 21,440
  • 2
  • 59
  • 76
  • oh you mean in the `web.xml` file? – sriram Feb 01 '13 at 17:12
  • If you are using a web.xml with Grails, then yes this is one way to control the ordering. Remember it will invoke in the order you specify the filter-mappings elements. – Rob Winch Feb 01 '13 at 17:17