스프링시큐리티 시작하기 - XML을 통한 인증 예제(묻지마 따라하기!)

2014. 1. 14. 14:42OpenSource/Spring Security

반응형


spring-security 시작하기(묻지마 따라하기!)

1) 설정

2) 테스트

3) 참고문서

4) Tip

5) 같이 보기

 

본 블로그에서 기본프로젝트를 만드는 스프링프레임워크 강좌의 소스를 기반으로 테스트 하였습니다.

고로 web이 구축되어있는 상태에서 spring-security를 구축하는 내용 입니다.^^;


<< 설정 >>

maven 3

Eclipse Indigo

jdk 1.6

springframework 3.1

spring-security 3.1.3.Release 



3.1.0 version은 Bug 있음. 

    - 참고 URL : http://stackoverflow.com/questions/10216563/spring-security-error-

                       creating-bean-org-springframework-security-filterchains

    - 오류내역 : error creating bean with name org.springframework.security.filterchains' 

                     initialization of bean failed


1) pom.xml(해당 jar 가져오기)

 <dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-core</artifactId>

<version>3.1.3.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-taglibs</artifactId>

<version>3.1.3.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-config</artifactId>

<version>3.1.3.RELEASE</version>

</dependency> 


2) web.xml

<!-- Spring Security Filter Proxy -->

<filter>

<filter-name>springSecurityFilterChain</filter-name>

<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

</filter>

<filter-mapping>

<filter-name>springSecurityFilterChain</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>


※ 아래의 설정으로 context-security.xml 을 가져온다.

<!-- Context definition -->

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:spring/context/*.xml</param-value>

</context-param>



3) context-security.xml

<beans:beans xmlns="http://www.springframework.org/schema/security"

xmlns:beans="http://www.springframework.org/schema/beans" 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

http://www.springframework.org/schema/security

http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<http auto-config="true">

<intercept-url pattern="/*" access="ROLE_USER" />

</http>

<authentication-manager alias="authenticationManager">

<authentication-provider>

<user-service>

<user authorities="ROLE_USER" name="acet" password="1"/>

</user-service>

</authentication-provider>

</authentication-manager>

</beans:beans>

 

 

심각: Exception starting filter springSecurityFilterChain 관련 bean이 생성되지 않았다는 오류가 날 수가 있다. 제대로 contextConfigLocation 이 설정되지 않았을 가능성이 있다.


 


<< 테스트 >>

was 기동 후 아래의 URL로 접근하면..Login 화면이 나오게 된다.

http://localhost:8080/acet/spring_security_login

 

 


<<  참고문서 >>

SpringSecurity3 - 도마뱀그림 있는 책ㅋㅋ;


<< Tip >>

SpringSecurity version을 조심! 3.1사용 시 3.1.3 Realse를 사용하자!


<< 같이 보기>>

2013/02/13 - [OpenSource/Spring Security] - 먼저 알아두면 좋은스프링 시큐리티 용어


2013/05/19 - [OpenSource/Spring Security] - 스프링 시큐리티 시작하기 Lesson 01


2013/08/12 - [OpenSource/Spring Security] - 스프링시큐리티 - DelegatingFilterProxy


2013/08/17 - [OpenSource/Spring Security] - 스프링시큐리티 - Filter Chain




                                            - END -





반응형