스프링 시큐리티를 이용한 웹 보안

33
스스스 스스스스스 스스스 스 스스 스스스 [email protected]

Upload: amal-jenkins

Post on 30-Dec-2015

171 views

Category:

Documents


1 download

DESCRIPTION

스프링 시큐리티를 이용한 웹 보안. 고종봉 [email protected]. 발표의 목적 / 목표 목적 웹 애플리케이션 보안 요구사항을 쉽고 효과적으로 해결할 수 있는 스프링 시큐리티를 좀더 널리 알려 보고자 그 결과로 개발자들이 불필요한 중복개발의 덫에서 벗어날 수 있다면 … 스프링 시큐리티에 대해 좀더 쉽게 다가갈 수 있다면 … 목표 스프링 시큐리티 소개 스프링 시큐리티 사용하기 보안 기본 개념 설명 스프링 시큐리티 응용하기. step by step…. 소개 . 스프링 시큐리티 ? 보안 ? - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 스프링 시큐리티를 이용한 웹 보안

스프링 시큐리티를 이용한 웹 보안

고종봉[email protected]

Page 2: 스프링 시큐리티를 이용한 웹 보안

발표의 목적 /목표

• 목적• 웹 애플리케이션 보안 요구사항을 쉽고 효과적으로 해결할

수 있는 스프링 시큐리티를 좀더 널리 알려 보고자• 그 결과로 개발자들이 불필요한 중복개발의 덫에서 벗어날

수 있다면…• 스프링 시큐리티에 대해 좀더 쉽게 다가갈 수 있다면…

• 목표• 스프링 시큐리티 소개• 스프링 시큐리티 사용하기• 보안 기본 개념 설명• 스프링 시큐리티 응용하기

step by step…

Page 3: 스프링 시큐리티를 이용한 웹 보안

소개 .스프링 시큐리티 ? 보안 ?

‘ 봄 보안’이 도대체 뭐야 ..

Page 4: 스프링 시큐리티를 이용한 웹 보안

스프링 시큐리티 소개

• 배경• 스프링 개발자들의 메일링 리스트에 스프링 - 기반의 보안

구현체는 고려하고 있지 않는지에 대한 질문이 올라왔다 . • 2003 년 후반 " 스프링을 위한 아씨지 시큐리티 시스템 "

으로 출발 . 심플한 시큐리티 구현체가 완성 . 초기 사용 시작 .

• 2004 년 3 월에 정식으로 출범 . 몇 년 후 스프링 프레임웍의 공식적인 서브프로젝트가 됨

• 2007 년 후반에 공식적으로 스프링 포트폴리오 프로젝트가 되었고 , " 스프링 시큐리티 " 로 브랜드가 변경

• 목적• J2EE- 기반 엔터프라이즈 소프트웨어 애플리케이션을 위한

종합적인 보안 서비스를 제공

Spring Security

Page 5: 스프링 시큐리티를 이용한 웹 보안

시작 .스프링 시큐리티 적용하기

초간단 네임스페이스 설정

“ 백문이 불여일코드”

Page 6: 스프링 시큐리티를 이용한 웹 보안

준비물…

-Eclipse IDE

-관련 라이브러리 JARs

포함 라이브러리 : spring-framework-3.0.2.RELEASE.zipspring-framework-3.0.2.RELEASE-dependencies.ziphttp://www.springsource.com/download/communityspring-security-3.0.2.RELEASE.ziphttp://www.springsource.com/download/community?project=Spring%20Security

포함 라이브러리 : spring-framework-3.0.2.RELEASE.zipspring-framework-3.0.2.RELEASE-dependencies.ziphttp://www.springsource.com/download/communityspring-security-3.0.2.RELEASE.ziphttp://www.springsource.com/download/community?project=Spring%20Security

Page 7: 스프링 시큐리티를 이용한 웹 보안

배포버전 다운받기http://springsource.org

Page 8: 스프링 시큐리티를 이용한 웹 보안

Maven ?

난 한 놈만 패 !!!

선택과 집중 ..

Page 9: 스프링 시큐리티를 이용한 웹 보안

작업 #1 웹 프로젝트 생성

1.eclipse IDE 실행

2.New Project > Dynamic Web Project 생성

3.Index.jsp 작성

4.Run As > Run on Server

Page 10: 스프링 시큐리티를 이용한 웹 보안

작업 #2 초간단 HTTP 보안 적용하기

1.Web App Libraries 추가

2.WEB-INF/web.xml 수정

3.applicationContext-security.xml 작성

4./Index.jsp 작성

5./admin/index.jsp 작성

Page 11: 스프링 시큐리티를 이용한 웹 보안

개념정리 .보안 기본개념 소개

인증 ? 인가 ? …

Page 12: 스프링 시큐리티를 이용한 웹 보안

보안 핵심 개념

• 인증 (Authentication)• 자신이 누구라고 주장하는 사람의 주체 (principal, " 주

체 " 는 보통 사용자를 의미하며 , 애플리케이션을 사용하는 장비나 시스템이 될 수도 있다 ) 를 확증하는 절차

• 인가 (Authorization)• 주체가 해당 애플리케이션 기능을 사용할 수 있도록

허용되었는지를 결정하는 프로세스• 주체의 신원이 인증을 거쳐 이미 확증되어 있어야 한다

흐음 ..

Page 13: 스프링 시큐리티를 이용한 웹 보안

Ex) 군사보안

< 군사제한구역 >

진입

누구냐 !

진입

통과 !

< 군사통제구역 >

진입

통과 !

인증(Authenticatio

n)

진입

권한없음 !

인가(Authorization)

Page 14: 스프링 시큐리티를 이용한 웹 보안

주요 객체

• 보안검사자 (Security Interceptor)• 권한 확인이 필요한 지점에서 요청에 대한 인증 및 인가를

검사한다

• 인증담당자 (Authentication Manager)• 사용자 정보 (UserDetails) 의 목록에서 주체 (Principal) 의

신원증명 (Credentials) 이 일치하는지 검사한다

• 인가 ( 권한제어 ) 담당자 (Authorization Manager)• 주체가 해당 요청에 대하여 부여된 권한 (Granted

Authority) 을 가지고 있는지 검사한다

Page 15: 스프링 시큐리티를 이용한 웹 보안

Ex) 군사보안

< 군사제한구역 >

진입

누구냐 !

진입

통과 !

< 군사통제구역 >

< 보안본부 >

진입

통과 !

진입

권한없음 !

보안검사자

인증담당자

보안검사자

인가담당자

인증요청인가요청

인증 인가

Page 16: 스프링 시큐리티를 이용한 웹 보안

응용 .웹 애플리케이션 보안

실무에서 마주치는 상황들 ..

Page 17: 스프링 시큐리티를 이용한 웹 보안

응용 #1 직접 만든 로그인 폼

“ 로그인 폼이 왜 이렇게 못생겼어 ?? 영어로 나오고 ,,”

1.applicationContext.xml 수정

2.login.jsp 작성

Page 18: 스프링 시큐리티를 이용한 웹 보안

응용 #2 로그아웃

“ 들어오는 것은 네 마음이지만 , 나가는 것은 네 맘대로 할 수 없다 ?!!”

1.index.jsp 수정

Page 19: 스프링 시큐리티를 이용한 웹 보안

응용 #3 사용자 로그인 확인

“ 지금 로그인이 되어 있는건가 ? 로그아웃 버튼은 왜 계속 보이는 거야 ?”

1.index.jsp 수정

Page 20: 스프링 시큐리티를 이용한 웹 보안

응용 #4 친절한 안내

“HTTP Status 403 - Access is denied ?!!! 헉 , 오류다 !!”

1.applicationContext-security.xml 수정

2.noAuthorized.jsp 수정

Page 21: 스프링 시큐리티를 이용한 웹 보안

응용 #5 로그인 실패 메시지

“ 아이디나 비밀번호를 잘못 입력했다면 ?”

1.applicationContext-security.xml 수정

2.login.jsp 수정

Page 22: 스프링 시큐리티를 이용한 웹 보안

응용 #6 로그인 성공 페이지

“ 로그인 성공시 , 메인 페이지로 보내고 싶다 ..”

1.applicationContext-security.xml 수정

Page 23: 스프링 시큐리티를 이용한 웹 보안

응용 #7 특정 URL 통과시키기

“ 회원전용 사이트 , 모든 URL 에 보안적용 , 하지만 로그인 페이지는 막으면 안됨”

1.applicationContext-security.xml 수정

Page 24: 스프링 시큐리티를 이용한 웹 보안

응용 #8-1 동시에 1 명만 접속 (세션만료 )

“ 하나의 사용자 ID 는 동시에 한곳에서만 로그인 가능”

1.applicationContext-security.xml 수정

Page 25: 스프링 시큐리티를 이용한 웹 보안

응용 #8-2 동시에 1 명만 접속 (로그인에러 )

“ 로그인된 사용자 ID 에 대한 동시 로그인 차단”

1.applicationContext-security.xml 수정

Page 26: 스프링 시큐리티를 이용한 웹 보안

응용 #9 사용자 정보 DB 에서 가져오기

“ 실무에서는 사용자 정보를 대부분 DB 로 관리”

1.DB 관련 라이브러리 추가

2.사용자 테이블 구성

3.applicationContext-security.xml 수정

Page 27: 스프링 시큐리티를 이용한 웹 보안

request

Servlet/JSPServlet/JSP

스프링 시큐리티 아키텍처

web.xml

FilterChainProxy

FilterChainProxy

Delegating

FilterProxy

Delegating

FilterProxy

ChannelProcessingFilt

er

ChannelProcessingFilt

erConcurrentSessionFilterConcurrent

SessionFilterSecurityContext

PersistenceFilter

SecurityContext

PersistenceFilter

SecurityContext

HolderAwareRequestFilter

SecurityContext

HolderAwareRequestFilterRememberMeAuthentication

Filter

RememberMeAuthentication

Filter

UsernamePassword

AuthenticationFilter

UsernamePassword

AuthenticationFilter

AnonymousAuthentication

Filter

AnonymousAuthentication

FilterExceptionTranslationFilt

er

ExceptionTranslationFilt

erFilterSecurityInterceptor

FilterSecurityInterceptor

AccessDecision

Manager

AccessDecision

Manager

SecurityContextHolder

SecurityContextHolder

SecurityContext

SecurityContext

AuthenticationAuthentication

AuthenticationManager

AuthenticationManager

UserDetailsService

UserDetailsService

AuthenticationProvider

AuthenticationProvider

UserDetailsUserDetails

GrantedAuthorityGrantedAuthority

Login.jspLogin.jsp

Page 28: 스프링 시큐리티를 이용한 웹 보안

심화과정 .시큐리티 제대로 사용하기

사실 , 봄 보안은 그렇게 단순하지 않아요…

Page 29: 스프링 시큐리티를 이용한 웹 보안

심화 #1 메서드 권한제어

“ 스프링 AOP 를 사용한 메서드 권한제어”

1.스프링 MVC 를 사용하기 위한 준비 및 AOP(Aspect-Oriented Programming) 관련 라이브러리 추가

2.applicationContext-security.xml 수정

3.MyService 작성

Page 30: 스프링 시큐리티를 이용한 웹 보안

심화 #2 MyUserDetailsService

“UserDetailsService 인터페이스 구현”

1.applicationContext-security.xml 수정

2.MyUserDetails 작성

3.MyUserDetailsService 작성

4.MyDao 작성

Page 31: 스프링 시큐리티를 이용한 웹 보안

심화 #3 XML-Based Configuration

“HTTP 네임스페이스에 숨겨진 구성설정”

1.applicationContext-security.xml

Page 32: 스프링 시큐리티를 이용한 웹 보안

References• Spring Security Reference Guide

http://static.springsource.org/spring-security/site/docs/3.0.x/reference/springsecurity.html

• Spring Security API Javadochttp://static.springsource.org/spring-security/site/docs/3.0.x/

apidocs/index.html

• Spring Security Samplesspring-security-samples-contacts.warspring-security-samples-tutorial.war

• Reference 번역 – SpringSprout Wikihttp://wiki.springsprout.org/display/springsecurity/Home

Page 33: 스프링 시큐리티를 이용한 웹 보안

- 감사합니다 -