2016-09-21 3 views
0

Je me suis heurté à une divergence entre la documentation Spring et ce que je vois à la suite de mes expériences. J'ai une méthode et je dois vérifier les autorisations avant l'invocation de méthode et conformément aux documents de printemps j'ai préparé ce qui suit:Printemps EL pas de "principe" dans l'authentification

@PreAuthorize("authentication.principle.company == #company.company") 
public CompanyForm getCompanyForm(Company company) { 
    //some code here 
} 

Mais invocation surprenante méthode est refusée en raison de cette erreur:

org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 15): Property or field 'principle' cannot be found on object of type 'org.springframework.security.authentication.UsernamePasswordAuthenticationToken' - maybe not public?

Quelqu'un pourrait-il me signaler mon erreur?

Répondre

2

Par le Spring Security Javadocs, le champ dans le jeton d'authentification est principal. Vous l'avez mal orthographié.

@PreAuthorize("authentication.principal.company == #company.company") 
public CompanyForm getCompanyForm(Company company) { 
    //some code here 
} 
+0

Merci beaucoup, la fin de la journée, vous savez :) –