spring-projects / spring-projects/spring-security
Target Class in AbstractMethodSecurityMetadataSource is proxy
Nobody has claimed this yet.
- 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
- 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;
}
}
- Register custom source:
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends GlobalMethodSecurityConfiguration {
@Override
public MethodSecurityMetadataSource customMethodSecurityMetadataSource() {
return new RepositorySecurityMetadataSource();
}
}
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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