UPDATE If you are using Spring Security 3.1.2+ you should use the Gradle Eclipse Plugin instead of gradlew eclipse
Note: Vote on these JIRA's if you would like STS to be able to import Spring Security without use of the command line.
Introduction
This blog will teach you how to run the sample applications/tests for Spring Security 3.1.x in STS. It is assumed that you have already installed STS. Since STS is a flavor of Eclipse, the process for doing this in Eclipse is similar.
The main goal is to demonstrate how to setup a workspace with STS. In later posts I will describe how to run the other sample applications within STS. Once you can run Spring Security in an IDE, I will describe how to contribute back to Spring Security.
Screencast
If you want to see this in action, you can view the screen cast too.
STS Setup
Spring Security uses git to manage the source code. There are quite a few different git clients to choose from, but in this blog I will demonstrate how to obtain the source using EGit.
Some of the tests are written in Groovy. If you want to run the tests, you will need to install the Groovy Eclipse plugin.
To install the plugins:
- Open up STS to a new workspace
- You should see an option to Open Dashboard
- At the bottom of the Dashboard View select the Extensions tab
- In the Find box type in EGit and select the check box next to it
- In the Find box type in Groovy Eclipse and select the check box next to it
- Click the Install button in the lower right
- Follow the instructions on any dialogs that pop up
- After everything is installed, restart STS
- Once STS starts back up navigate to File->Import->Git->Projects from Git
- Click the Clone... button
- Fill out the URI with git://github.com/SpringSource/spring-security.git
- Click the Next button to view the branches for this repository
- Ensure that all the branches are selected
- Click the Next button again to clone all the branches
- Accept all the defaults and click the Finish button
- The repository will be cloned and the local location will be displayed next to it
- Remember the path to the repository as the Destination Directory
- Open up a command prompt and navigate to the Destination Directory from the previous step
- When using EGit, I have to add the execution bit the gradle wrapper. Since this does not happen when I use git from the command line, I suspect it is an EGit bug. To change the permissions in a Linux environment execute chmod +x gradlew from the command line.
- Linux/Mac users run ./gradlew eclipse
- Windows users run .\gradlew.bat eclipse
- Gradle will automatically be downloaded, installed, download the required dependencies, and then the Eclipse configuration will be generated
- Navigate back to Eclipse and click the Next button
- Ensure Import Existing Projects is selected
- Click the Next button
- Click Select All
- Click the Finish button
- The project will be imported and there should be no errors.
At this point you should be able to run all of the unit tests by right clicking the project and navigating to Run As -> JUnit Tests. Of course that is not all that fun, so instead we will run the tutorial sample on tc Server. To run the tutorial follow these steps:
- Right click spring-security-samples-tutorial and select Run As -> Run on Server
- Select Finish
- When prompted if you want to enable Spring Insight click No
- The application will be opened up in Spring Tool Suite
- When prompted to login, you can use the users defined in spring-security-samples-tutorial/src/main/webapp/WEB-INF/applicationContext-security.xml (i.e. rod / koala)
What Next?
You can read about Running Spring Security's CAS and PreAuth Samples in STS