spring-projects / spring-projects/spring-security

Method security aspects not woven in spring-security-config tests

Open
#5,072 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

When running the test suite for spring-security-config, tests that exercise AspectJ are not seeing relevant advice woven in at runtime.

This behavior is confirmed for NamespaceGlobalMethodSecurityTests, which has two AspectJ tests that, to date, only confirm that the application context was correctly wired. Repairing this issue would allow these two tests to be enhanced to verify method security behavior when configured to use AspectJ.

For reference, the repo has samples whose test suite exercises AspectJ correctly. The Gradle build file is materially different between spring-security-samples-javaconfig-aspectj and spring-security-config:

Gradle Configuration for spring-security-config

(AspectJ advice not woven in tests)

dependencies {
    	optional 'org.aspectj:aspectjweaver'
}
Gradle Configuration for spring-security-samples-javaconfig-aspectj

(AspectJ advice woven in tests)

apply plugin: 'aspectj'

dependencies {
    aspectpath project(':spring-security-aspects')
    
    runtime project(':spring-security-aspects')
}

As an initial sanity check, I copied the classes from spring-security-samples-javaconfig-aspectj into spring-security-config and ran them there. When they were launched from within spring-security-config, they failed to wire the appropriate advice as well.

Actual Behavior

When using @EnableGlobalMethodSecurity(mode = AdviceMode.ASPECTJ, prePostEnabled = true), for example, the following method is allowed:

public class MethodSecurityService {
    @PreAuthorize("denyAll")
    public String denyAll() {
        return "you shall not pass";
    }
}
Expected Behavior

Invoking the above-mentioned denyAll method would throw an AccessDeniedException, as indicated by the AspectJ advice. And generally, all Spring Security-supported pointcuts would also work.

Configuration

Edit a test that uses AspectJ, specifically to invoke a method on a @PreAuthorize-annotated bean that would precipitate a denial from the AspectJ advice. Then, run the test.

Version

Spring Security 5.1.0.M1

Sample

See https://github.com/spring-projects/spring-security/tree/master/config for a misconfigured project
See https://github.com/spring-projects/spring-security/tree/master/samples/javaconfig/aspectj for a working project

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 the spring-security-config Gradle build and NamespaceGlobalMethodSecurityTests, then compare their AspectJ setup with samples/javaconfig/aspectj. Run the AspectJ tests after correcting the test weaving configuration and confirm that invoking a @PreAuthorize("denyAll") method throws AccessDeniedException.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.