spring-projects / spring-projects/spring-security

Target Class in AbstractMethodSecurityMetadataSource is proxy

Open
#4,756 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Summary

Custom Metadata Source receive the Spring proxy instead of the real class.

Actual Behavior
  1. Create custom Metadata Source:
public class CustomSecurityMetadataSource extends AbstractMethodSecurityMetadataSource {
    public Collection<ConfigAttribute> getAttributes(Method method, Class<?> targetClass) {
        System.out.println("Proxy class: " + targetClass.getClass());

        return Collections.emptyList();
    }

    public Collection<ConfigAttribute> getAllConfigAttributes() {
        return null;
    }
}
  1. Register custom source:
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends GlobalMethodSecurityConfiguration {
    @Override
    public MethodSecurityMetadataSource customMethodSecurityMetadataSource() {
        return new RepositorySecurityMetadataSource();
    }
}
  1. Run the app and notice the output for certain classes. The Spring Data Repositories, specifically have the Spring Proxy instead of the repository interface.
Expected Behavior

Same steps as above, the targetClass received should be the Spring Data Repository interface instead of the Spring Proxy.

Version

I tested this on version 5.0.0.M5 as well as the latest snapshot, it occurs in both versions.

Sample

A sample showing this is available at:
https://github.com/miguelocarvajal/target-class-proxy

Running this Spring Boot sample shows the target class proxy instead of the Data Repository I am expecting.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AbstractMethodSecurityMetadataSource and the customMethodSecurityMetadataSource entry point described in the issue, then reproduce the behavior using the linked target-class-proxy sample. Done means the metadata source receives the Spring Data Repository interface rather than the Spring proxy.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.