Spring Security 따라하기.

ITWeb/개발일반 2012. 3. 5. 11:43
[원본링크]

[원본글]

THURSDAY, MARCH 17, 2011

Running Spring Security's Tutorial Sample in Spring Tool Suite

Note
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 installedSTS. 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
Checking Out the Source Code
  • 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
Generating the Eclipse Configuration Files
  • 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
Importing the Projects
  • 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.
Running the Code

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


[위와 같이 했을 경우 발생 하는 문제]

SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)

at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)

at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)

at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)

at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)

at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)

at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

at java.util.concurrent.FutureTask.run(FutureTask.java:138)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

at java.lang.Thread.run(Thread.java:619)

08.11.2011 15:23:30 org.apache.catalina.core.StandardContext listenerStart

SEVERE: Error configuring application listener of class org.springframework.security.web.session.HttpSessionEventPublisher

java.lang.ClassNotFoundException: org.springframework.security.web.session.HttpSessionEventPublisher

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)

at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)

at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)

at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)

at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)

at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)

at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

at java.util.concurrent.FutureTask.run(FutureTask.java:138)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

at java.lang.Thread.run(Thread.java:619)

- 이와 같은 에러는 classpath 상에 spring-web 관련 jar 파일이 없어서 발생을 합니다.
- classpath 를 살펴 보니 정상적으로 path 등록이 되어 있으나 에러가 발생 할 경우.
- 아래 경로에 spring-web 관련 jar 파일들을 복사해서 넣어 주시면 됩니다.

[Spring Security Samples tutorial 의 lib Path확인]

D:\Development\Workspace_SpringSource\.metadata\.plugins\org.eclipse.wst.server.core\
tmp0\wtpwebapps\spring-security-samples-tutorial\WEB-INF\lib

- workspace
D:\Development\Workspace_SpringSource\  

- 해당 경로에 실제 spring web 관련 jar 파일이 존재 하지 않아 위와 같은 에러가 발생을 하였습니다.
- 아래 파일들을 복사후 tomcat start 시 정상 동작 합니다.

[jar 파일 복사]


- 어떤 파일을 복사 해야 할지 잘 모를경우, 그냥 spring mvc 프로젝트 하나 생성 하셔서 빌드 하신 후 해당 lib 경로에 들어 있는 파일들을 몽땅 복사해서 넣으시면 됩니다.
: