Skip to content

Migration to EnableMethodSecurity break Transactional on custom PermissionEvaluator #13152

Closed
@kris2kris

Description

@kris2kris

Hello,

I perform the migration from EnableGlobalMethodSecurity to EnableMethodSecurity.
So I :

  1. Change the annotation
  2. Stop to extend GlobalMethodSecurityConfiguration class
  3. Replace override of createExpressionHandler() by a Bean to put my custom permission evaluator

I have a method with two annotations Transactionnal and PreAuthorize.
PreAuthorize call my custom hasPermission method.

Before migration my custom hasPermission method is executed after Transaction creation.
After migration my custom hasPermission method is executed before Transaction creation, so I cannot use some operation like a findAll which return a stream.

The workaround that I found is to change the order of annotation EnableTransactionManagement to put HIGHEST_PRECEDENCE.

Are you aware about this problem ? Is there a better way to fix it ? I didn't find anything in migration guide about this.

I use spring boot 3.0.6

You can find a simple sample here https://github.com/kris2kris/migration-method-security
Once started you must perform a get on localhost:8080/entities to reproduce the problem.

If you switch comment in Config.class and rollback on old version it works, if you uncomment the order EnableTransactionManagement it also works

Metadata

Metadata

Assignees

Labels

in: configAn issue in spring-security-configtype: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions