Skip to content

PrePostMethodSecurityConfiguration is missing a setter for custom PermissionEvaluator #19084

Closed

Description

@Siggen

Describe the bug
PrePostMethodSecurityConfiguration takes in account custom GrantedAuthorityDefaults, RoleHierarchy and AuthorizationManagerFactory beans but ignores custom PermissionEvaluator bean.

To Reproduce
Setup a context with a custom permission evaluator, for instance PrePostMethodSecurityConfigurationTests with:

@Configuration
@EnableMethodSecurity
static class CustomPermissionEvaluatorConfig {

	@Bean
	PermissionEvaluator permissionEvaluator() {
		return new PermissionEvaluator() {
			@Override
			public boolean hasPermission(Authentication authentication, Object targetDomainObject,
					Object permission) {
				return "grant".equals(targetDomainObject);
			}

			@Override
			public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType,
					Object permission) {
				throw new UnsupportedOperationException();
			}
		};
	}

}

=> custom PermissionEvaluator bean is not injected into PrePostMethodSecurityConfiguration's default expression handler and following test fails:

@WithMockUser
@Test
public void postHasPermissionWhenParameterIsGrantThenPasses() {
	this.spring.register(CustomPermissionEvaluatorConfig.class, MethodSecurityServiceConfig.class).autowire();
	String result = this.methodSecurityService.postHasPermission("grant");
	assertThat(result).isNull();
}

Expected behavior
Custom permission evaluator should be injected in PrePostMethodSecurityConfiguration's default expression handler.

Sample
I will link to a PR soon.

Activity

  1. added
    status: waiting-for-triage
    type: bug
    on Apr 16, 2026
  2. added a commit that references this issue on Apr 16, 2026
    b77cc0d
  3. Siggen commented on Apr 16, 2026

    @Siggen
    ContributorAuthor

    Candidate fix in gh-19085.

  4. self-assigned this
    on Sep 3, 2026
  5. added
    in: core
    type: enhancement
    status: duplicate
    and removed
    status: waiting-for-triage
    type: bug
    on Sep 3, 2026
  6. jzheaux commented on Sep 3, 2026

    @jzheaux
    Collaborator

    Thanks for the PR, @Siggen. I'll close this in favor of continuing the conversation in #19085.

  7. added 3 commits that reference this issue on Sep 3, 2026
    6455465
    1f4d01a
    29f8dd5
  8. added a commit that references this issue on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corestatus: duplicatetype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions