This tool generates a table report to verify access control on your Spring Boot routes. It scans for the @PreAuthorize
, @Secured
, or @RolesAllowed
annotations from spring-security-config
to create a table.html
file with an easy-to-read list of all your routes and their access control annotations.
Follow these three steps to quickly use the Spring Access Inspector:
-
Add the plugin: Add the following plugin to the
<plugins>
section of your project'spom.xml
:Java 21
<build> <pluginManagement> <plugins> <!-- ...existing plugins... --> <plugin> <groupId>com.theodo</groupId> <artifactId>spring-access-inspector-plugin</artifactId> <version>2.0.3</version> <configuration> <projectBaseDir>${project.basedir}</projectBaseDir> <htmlOutputFile>./table.html</htmlOutputFile> </configuration> </plugin> <!-- ...existing plugins... --> </plugins> </pluginManagement> </build>
Java 17
<build> <pluginManagement> <plugins> <!-- ...existing plugins... --> <plugin> <groupId>com.theodo</groupId> <artifactId>spring-access-inspector-plugin</artifactId> <version>1.0.3</version> <configuration> <projectBaseDir>${project.basedir}</projectBaseDir> <htmlOutputFile>./table.html</htmlOutputFile> </configuration> </plugin> <!-- ...existing plugins... --> </plugins> </pluginManagement> </build>
-
Compile the project: Run the following command to compile your project and ensure the plugin is installed:
mvn clean install -U
-
Run the inspector: Execute the inspector using the following command:
mvn inspector:inspect
The result will be generated in a
table.html
file at the root of your project.
This project is composed of two parts:
- The Inspector: The core tool that performs the analysis.
- The Maven Plugin: A wrapper plugin that simplifies using the inspector in any project.
The inspector uses Java 21. A Java 17 version is available on the branch v1-java-17
.
To use the inspector locally without the plugin, follow these steps:
-
Clone the repository:
git clone [email protected]:theodo-group/spring-access-inspector.git
-
Navigate to the inspector folder:
cd spring-access-inspector/inspector
-
Compile the code:
mvn compile exec:java -Dexec.mainClass=com.theodo.inspector.SpringAccessInspector
-
Run the code (using the Maven exec plugin) and provide the path to the
pom.xml
files you want to analyze:mvn exec:java -Dexec.mainClass=com.theodo.inspector.SpringAccessInspector -Dexec.args="/path/to/poms"
Note: You may need to compile your code beforehand:
mvn clean install -DskipTests
The Maven plugin simplifies launching the inspector by adding it to the pom.xml
of the project you want to inspect. It is available on Maven Central, but you can also use it locally.
-
Navigate to the plugin folder:
cd spring-access-inspector/inspector-maven-plugin
-
Compile the plugin:
mvn clean install
-
Add the plugin to the
build/pluginManagement
section of your project'spom.xml
:<build> <!-- ...existing build configuration... --> <pluginManagement> <plugins> <plugin> <groupId>com.theodo</groupId> <artifactId>spring-access-inspector-plugin</artifactId> <version>2.0.3</version> <configuration> <projectBaseDir>${project.basedir}</projectBaseDir> <htmlOutputFile>./table.html</htmlOutputFile> </configuration> </plugin> </plugins> </pluginManagement> </build>
Configuration Options:
projectBaseDir
: Specifies the base directory of the project to analyze. Defaults to${project.basedir}
.htmlOutputFile
: Specifies the path to the output HTML file. Defaults to./table.html
.
-
Run the analysis in your shell or CI:
mvn inspector:inspect
Note: You may need to compile the inspector code beforehand (see above).
When upgrading the version, update the following:
- The version in the three
pom.xml
files (inspector, plugin, and aggregate). - This README file.
To deploy the project:
-
Add the username and password for the "public" server to your root
.m2/settings.xml
:<server> <id>public</id> <username>thesonatypetokenusername</username> <password>thesonatypetokenpassword</password> </server>
-
Add your GPG key passphrase to your root
.m2/settings.xml
:<server> <id>gpg</id> <passphrase>yourgpgkeypassphrase</passphrase> </server>
-
Run the following command to deploy only the plugin and the inspector:
mvn clean deploy --projects inspector,inspector-maven-plugin