jeudi 26 mars 2015

Grails Spring Security - principle is anonymousUser

I am working on a project on both my own local machine and a linux server.


I have the following strange problem:



  • On the server authentication.principle correctly returns the user that I have logged in with.

  • On my own machine unfortunately "anonymousUser" is being returned.


The code is the exact same, the project is the same. The only difference are the operating systems and the underlying JDKs.


On my own local machine the only place where the correct principle is returned is within the void onApplicationEvent(AuthenticationSuccessEvent event) { method. The event.source.principal is the correct one and not anonymousUser.


I have added a hack that seems to work and forces the correct principle. Could something be causing a logoff after the logon?


The below seems to temporarily solve the weird issue:



void onApplicationEvent(AuthenticationSuccessEvent event) {
log.debug("AuthenticationSuccessEvent, setting session")

//Handles strange fringe case where personService.currentPerson returns anonymousUser even though login has taken place
if(grailsApplication.config.debugForceReauthenticationWithPrinciple)springSecurityService.reauthenticate personService.getCurrentPerson(event.source.principal, true).username

pService.setupSession(pService.getCurrentPerson(event.source.principal, true), session)


To clarify, the problem is that springSecurityService.getPrincipal() returns anonymousUser even though I am logged in (on my own machine).


Aucun commentaire:

Enregistrer un commentaire