Issue with Spring Security MethodSecurityEvaluationContext lookupVariable and addArgumentsAsVariables methods

StackOverflow https://stackoverflow.com/questions/22499730

  •  17-06-2023
  •  | 
  •  

Domanda

I have an issue with MethodSecurityEvaluationContext lookupVariable and addArgumentsAsVariables methods which is as follows:

The paramNames local variable itself is not null but always contains a null entry.

Does anyone know what could cause this?

screen capture

Here is the method annotated with @PreAuthorize (in a Roo-generated itd):

@PreAuthorize("isAuthenticated() AND hasPermission(#id, 'CurriculumService:findCurriculumIsAllowed')")
public Curriculum CurriculumServiceImpl.findCurriculum(Long id) {
    return curriculumRepository.findOne(id);
}
È stato utile?

Soluzione

I was given the answer to the above question. One has to annotate the parameter with @P("id") as shown below:

@PreAuthorize("isAuthenticated() AND hasPermission(#id, 'CurriculumService:findCurriculumIsAllowed')")
public Curriculum CurriculumServiceImpl.findCurriculum(@P("id") Long id) {
    return curriculumRepository.findOne(id);
}

See documentation here.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top