๊ด€๋ฆฌ ๋ฉ”๋‰ด

Coding Planet

[Spring Security] ๋ณด์•ˆ๊ตฌ์„ฑ ์„ค์ •ํ•˜๊ธฐ - context-security.xml(์ „์ž์ •๋ถ€ ๋ชจ๋“ˆ ํฌํ•จ) ๋ณธ๋ฌธ

๐ŸŒฑSPRING

[Spring Security] ๋ณด์•ˆ๊ตฌ์„ฑ ์„ค์ •ํ•˜๊ธฐ - context-security.xml(์ „์ž์ •๋ถ€ ๋ชจ๋“ˆ ํฌํ•จ)

jhj.sharon 2024. 2. 14. 17:33
๋ฐ˜์‘ํ˜•

 

|Spring Security๋ž€?

Spring Security๋Š” Spring ๊ธฐ๋ฐ˜์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋ณด์•ˆ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค๊ณ„๋œ ํ”„๋ ˆ์ž„์›Œํฌ์ด๋‹ค. ์ธ์ฆ(Authentication)๊ณผ ๊ถŒํ•œ๋ถ€์—ฌ(Authorization)์„ ์œ„ํ•œ ํฌ๊ด„์ ์ด๊ณ  ํ™•์žฅ ๊ฐ€๋Šฅํ•œ ์†”๋ฃจ์…˜์„ ์ œ๊ณตํ•œ๋‹ค.
Spring Security๋Š” ๋ฉ”์„œ๋“œ ์ˆ˜์ค€, URL ์ˆ˜์ค€์—์„œ ๋ณด์•ˆ ๋“ฑ ๋ณด์•ˆ ์ˆ˜์ค€์„ ์„ค์ •ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
 
Spring Security๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ๊ฐœ๋ฐœ์ž๊ฐ€ ๋ณด์•ˆ ๊ด€๋ จ ์ฝ”๋“œ๋ฅผ ์ง์ ‘ ์ž‘์„ฑํ•˜์ง€ ์•Š์•„๋„ ๊ฐ„๋‹จํžˆ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ณ ์•ˆ๋˜์—ˆ๋Š”๋ฐ ์ฃผ์š” ๊ธฐ๋Šฅ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
 
  • ์ธ์ฆ: ์‚ฌ์šฉ์ž๊ฐ€ ๋ˆ„๊ตฌ์ธ์ง€ ํ™•์ธํ•˜๋Š” ๊ณผ์ •. ์˜ˆ๋ฅผ ๋“ค์–ด, ์‚ฌ์šฉ์ž ์ด๋ฆ„๊ณผ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์‚ฌ์šฉํ•œ ๋กœ๊ทธ์ธ ๊ณผ์ •์ด ์—ฌ๊ธฐ์— ํ•ด๋‹นํ•œ๋‹ค.
  • ๊ถŒํ•œ ๋ถ€์—ฌ: ์ธ์ฆ๋œ ์‚ฌ์šฉ์ž๊ฐ€ ํŠน์ • ์ž์›์— ์ ‘๊ทผํ•˜๊ฑฐ๋‚˜ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”์ง€ ๊ฒฐ์ •ํ•˜๋Š” ๊ณผ์ •.
  • CSRF(Cross-Site Request Forgery) ๋ณดํ˜ธ: ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ CSRF ๊ณต๊ฒฉ์œผ๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•œ๋‹ค.
  • ์„ธ์…˜ ๊ด€๋ฆฌ: ์„ธ์…˜ ๊ณ ์ • ๊ณต๊ฒฉ ๋ฐฉ์ง€, ๋™์‹œ ์„ธ์…˜ ์ œ์–ด, ์„ธ์…˜ ๋งŒ๋ฃŒ ๊ด€๋ฆฌ ๋“ฑ์˜ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค.
  • LDAP, ํผ ๊ธฐ๋ฐ˜ ์ธ์ฆ, Basic ์ธ์ฆ ๋“ฑ ๋‹ค์–‘ํ•œ ์ธ์ฆ ๋ฉ”์ปค๋‹ˆ์ฆ˜ ์ง€์›: ๋‹ค์–‘ํ•œ ์ธ์ฆ ๋ฐฉ๋ฒ•์„ ์‰ฝ๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•œ๋‹ค.

 

| context-security.xml ๋œฏ์–ด๋ณด๊ธฐ

context-security.xml ์„ค์ • ํŒŒ์ผ์€ Spring Security๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋ณด์•ˆ ๊ตฌ์„ฑ์„ ์ •์˜ํ•˜๋Š” ์„ค์ •ํŒŒ์ผ์ด๋‹ค. 

	<security:http pattern="/auth/login.do" security="none"/>
	<security:http pattern="/favicon.ico" security="none"/>
	<security:http pattern="/css/**" security="none"/>
	<security:http pattern="/html/**" security="none"/>
    <security:http pattern="/images/**" security="none"/>
 	<security:http pattern="/js/**" security="none"/>
 	<security:http pattern="/resource/**" security="none"/>
 	<security:http pattern="\A/WEB-INF/jsp/.*\Z" request-matcher="regex" security="none"/>

    <egov-security:config id="securityConfig"
		loginUrl="/auth/login.do"
		logoutSuccessUrl="/"
		loginFailureUrl="/auth/login.do?code=failure"
		accessDeniedUrl="/auth/login.do?code=denied"
		dataSource="egov.dataSource"
		jdbcUsersByUsernameQuery="SELECT m.USER_ID, m.USER_ID AS PSWD, 1 ENABLED, m.user_nm, '' as USER_ZIP,
                                                              '' as USER_ADRES, '' as USER_EMAIL, 'GNR' as USER_SE, '' as ORGNZT_ID, m.user_id as ESNTL_ID,
                                                              m.inst_nm as ORGNZT_NM,
                                                              (
																SELECT author_cd
																FROM author
																WHERE del_yn = 'N'
																AND user_id = m.user_id
																ORDER BY author_sn DESC
																LIMIT 1
                                                              ) as AUTZR_CD
                                                       FROM user_info m
                                                       WHERE m.id_del_yn = 'N' AND concat('GNR', m.user_id) = ?"
		jdbcAuthoritiesByUsernameQuery="select user_id,
						   case author_cd
							when 'OP' then 'ROLE_OPER'
							when 'AD' then 'ROLE_ADMIN'
							else 'ROLE_USER' end as authority
					from author where del_yn = 'N' and user_id = ?"
		jdbcMapClass="chungnam.portal.sec.security.common.EgovSessionMapping"

		requestMatcherType="regex"
		hash="plaintext"
		hashBase64="false"

		concurrentMaxSessons="1"
		concurrentExpiredUrl="/auth/login.do"
		errorIfMaximumExceeded="false"

		defaultTargetUrl="/index.do"
		alwaysUseDefaultTargetUrl="true"

		sniff="true"
		xframeOptions="SAMEORIGIN" 
		xssProtection="true" 
		cacheControl="false"
		csrf="false"
		csrfAccessDeniedUrl="/egovCSRFAccessDenied.do"
	/>

	<egov-security:secured-object-config id="securedObjectConfig"
		sqlHierarchicalRoles="
			SELECT a.CHLDRN_ROLE as child, a.PARNTS_ROLE parent
			FROM COMTNROLES_HIERARCHY a LEFT JOIN COMTNROLES_HIERARCHY b on (a.CHLDRN_ROLE = b.PARNTS_ROLE)"
		sqlRolesAndUrl="
			SELECT a.ROLE_PTTRN url, b.AUTHOR_CODE authority
			FROM COMTNROLEINFO a, COMTNAUTHORROLERELATE b
			WHERE a.ROLE_CODE = b.ROLE_CODE
				AND a.ROLE_TY = 'url'  ORDER BY a.ROLE_SORT"
		sqlRolesAndMethod="
			SELECT a.ROLE_PTTRN as 	&quot;method&quot;, b.AUTHOR_CODE authority
			FROM COMTNROLEINFO a, COMTNAUTHORROLERELATE b
			WHERE a.ROLE_CODE = b.ROLE_CODE
			AND a.ROLE_TY = 'method'  ORDER BY a.ROLE_SORT"
		sqlRolesAndPointcut="
			SELECT a.ROLE_PTTRN pointcut, b.AUTHOR_CODE authority
			FROM COMTNROLEINFO a, COMTNAUTHORROLERELATE b
			WHERE a.ROLE_CODE = b.ROLE_CODE
			AND a.ROLE_TY = 'pointcut'  ORDER BY a.ROLE_SORT"
		sqlRegexMatchedRequestMapping="
			SELECT a.ROLE_PTTRN uri, b.AUTHOR_CODE authority
			FROM COMTNROLEINFO a, COMTNAUTHORROLERELATE b
			WHERE a.ROLE_CODE = b.ROLE_CODE
			AND a.ROLE_TY = 'regex'  
			ORDER BY a.ROLE_SORT"
	/>

	<egov-security:initializer id="initializer" supportMethod="true" supportPointcut="false" />

    <!-- URL์— ์„ธ๋ฏธ์ฝœ๋ก (semicolon)ํ—ˆ์šฉ ์—ฌ๋ถ€(๊ธฐ๋ณธ๊ฐ’/false) -->
	<bean id="egovStrictHttpFirewall" class="org.springframework.security.web.firewall.StrictHttpFirewall">
		<property name="allowSemicolon" value="true"/>
	</bean>
	<security:http-firewall ref="egovStrictHttpFirewall"/>


</beans>

 

1. ๋ณด์•ˆ ์˜ˆ์™ธ ์ฒ˜๋ฆฌํ•˜๊ธฐ

<security:http pattern="/auth/login.do" security="none"/>

 

์œ„ ์ฝ”๋“œ๋Š” ํŠน์ • URL ํŒจํ„ด์— ๋Œ€ํ•œ ๋ณด์•ˆ ํ•„ํ„ฐ ์ ์šฉ์„ ์˜ˆ์™ธ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ธฐ๋Šฅ์ด๋‹ค. ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€์˜ ๊ฒฝ์šฐ ๋ชจ๋“  ์‚ฌ์šฉ์ž๊ฐ€ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•ด์•ผํ•˜๋ฏ€๋กœ ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€์— ํ•ด๋‹นํ•˜๋Š” URL์— Spring Security ๊ธฐ๋Šฅ์„ ๊บผ๋‘” ๊ฒƒ์ด๋‹ค.

์ฆ‰, ์‚ฌ์šฉ์ž๊ฐ€ /auth/login.do URL์— ์ ‘๊ทผํ•  ๋•Œ, ์ธ์ฆ(๋กœ๊ทธ์ธ) ์ ˆ์ฐจ ์—†์ด๋„ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

์ผ๋ฐ˜์ ์œผ๋กœ ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€๋‚˜, ๊ณต๊ฐœ์ ์œผ๋กœ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•ด์•ผ ํ•˜๋Š” ์ž์›(์˜ˆ: CSS, JS ํŒŒ์ผ ๋“ฑ)์— ์ด๋Ÿฌํ•œ ์„ค์ •์„ ์‚ฌ์šฉํ•œ๋‹ค.

 

2. <egov-security:config> ์ „์ž์ •๋ถ€ ํ”„๋ ˆ์ž„์›Œํฌ ํ™•์žฅ ๊ธฐ๋Šฅ

์ „์ž์ •๋ถ€์—์„œ ์ œ๊ณตํ•˜๋Š” ํ™•์žฅ ์„ค์ •์œผ๋กœ Spring Security๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์ฆ ๋ฐ ๊ถŒํ•œ ๋ถ€์—ฌ, ๋กœ๊ทธ์ธ ๋ฐ ๋กœ๊ทธ์•„์›ƒ ์ฒ˜๋ฆฌ, ์„ธ์…˜ ๊ด€๋ฆฌ ๋“ฑ์˜ ๋ณด์•ˆ ๊ด€๋ จ ์„ค์ •์„ ์ปค์Šคํ„ฐ๋งˆ์ด์ฆˆํ•˜๊ธฐ ์œ„ํ•œ ๋‹ค์–‘ํ•œ ์†์„ฑ์„ ์ œ๊ณตํ•œ๋‹ค. ์ฃผ์š” ๊ธฐ๋Šฅ์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

  • ๋กœ๊ทธ์ธ ๋ฐ ๋กœ๊ทธ์•„์›ƒ ๊ด€๋ จ URL ์„ค์ •: ์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธํ•˜๊ฑฐ๋‚˜ ๋กœ๊ทธ์•„์›ƒํ•  ๋•Œ ์ด๋™ํ•  URL์„ ์ง€์ •ํ•œ๋‹ค.
    • loginUrl: ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€์˜ URL
    • logoutSuccessUrl: ๋กœ๊ทธ์•„์›ƒ ์„ฑ๊ณต ์‹œ ๋ฆฌ๋””๋ ‰์…˜๋  URL
    • loginFailureUrl: ๋กœ๊ทธ์ธ ์‹คํŒจ ์‹œ ๋ฆฌ๋””๋ ‰์…˜๋  URL
    • accessDeniedUrl: ์ ‘๊ทผ ๊ถŒํ•œ์ด ์—†์„ ๋•Œ ๋ฆฌ๋””๋ ‰์…˜๋  URL
  • ๋ฐ์ดํ„ฐ ์†Œ์Šค ๋ฐ ์‚ฌ์šฉ์ž ์ •๋ณด ์กฐํšŒ ์„ค์ •: ์ธ์ฆ ๊ณผ์ •์—์„œ ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ์กฐํšŒํ•˜๊ธฐ ์œ„ํ•œ SQL ์ฟผ๋ฆฌ์™€ ๋ฐ์ดํ„ฐ ์†Œ์Šค๋ฅผ ์ง€์ •
    • dataSource: ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ์กฐํšŒํ•  ๋•Œ ์‚ฌ์šฉํ•  ๋ฐ์ดํ„ฐ ์†Œ์Šค์˜ ๋นˆ ์ด๋ฆ„
    • jdbcUsersByUsernameQuery: ์‚ฌ์šฉ์ž ์ด๋ฆ„์œผ๋กœ ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ์กฐํšŒํ•  SQL ์ฟผ๋ฆฌ
    • jdbcAuthoritiesByUsernameQuery: ์‚ฌ์šฉ์ž์˜ ๊ถŒํ•œ ์ •๋ณด๋ฅผ ์กฐํšŒํ•  SQL ์ฟผ๋ฆฌ
  • ์„ธ์…˜ ๊ด€๋ฆฌ: ๋™์‹œ ๋กœ๊ทธ์ธ ์„ธ์…˜ ์ˆ˜๋ฅผ ์ œํ•œํ•˜๊ณ , ์„ธ์…˜ ๋งŒ๋ฃŒ ์‹œ์˜ ์ฒ˜๋ฆฌ๋ฅผ ์„ค์ •
    • concurrentMaxSessons: ๋™์‹œ์— ํ—ˆ์šฉ๋˜๋Š” ์ตœ๋Œ€ ์„ธ์…˜ ์ˆ˜
    • concurrentExpiredUrl: ์„ธ์…˜ ๋งŒ๋ฃŒ ์‹œ ๋ฆฌ๋””๋ ‰์…˜๋  URL
  • ๋ณด์•ˆ ๊ด€๋ จ ํ—ค๋” ์„ค์ •: ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ณด์•ˆ์„ ๊ฐ•ํ™”ํ•˜๊ธฐ ์œ„ํ•œ ์—ฌ๋Ÿฌ HTTP ํ—ค๋” ์„ค์ •์„ ์ œ๊ณต
    • sniff: ๋ธŒ๋ผ์šฐ์ €์˜ MIME ํƒ€์ž… ์Šค๋‹ˆํ•‘์„ ๋ฐฉ์ง€
    • xframeOptions: ํด๋ฆญ์žฌํ‚น ๊ณต๊ฒฉ์œผ๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•˜๊ธฐ ์œ„ํ•ด ํ”„๋ ˆ์ž„ ๋‚ด์—์„œ์˜ ํŽ˜์ด์ง€ ๋ Œ๋”๋ง์„ ์ œํ•œ
    • xssProtection: ๋ธŒ๋ผ์šฐ์ €์˜ XSS ํ•„ํ„ฐ๋ฅผ ํ™œ์„ฑํ™”
    • cacheControl: ๋ธŒ๋ผ์šฐ์ € ์บ์‹ฑ์„ ๋น„ํ™œ์„ฑํ™”
    • csrf: ์‚ฌ์ดํŠธ ๊ฐ„ ์š”์ฒญ ์œ„์กฐ(CSRF) ๊ณต๊ฒฉ ๋ฐฉ์ง€ ๊ธฐ๋Šฅ์˜ ํ™œ์„ฑํ™”/๋น„ํ™œ์„ฑํ™”๋ฅผ ์„ค์ •

 

3. <egov-security:secured-object-config>  ์ „์ž์ •๋ถ€ ํ”„๋ ˆ์ž„์›Œํฌ ๋ณด์•ˆ ๋ชจ๋“ˆ

<egov-security:secured-object-config> ํƒœ๊ทธ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋‚ด์˜ ๋ณด์•ˆ ๊ฐ์ฒด(URL, ๋ฉ”์„œ๋“œ, ํฌ์ธํŠธ ์ปท)์— ๋Œ€ํ•œ ์ ‘๊ทผ ์ œ์–ด ์ •์ฑ…์„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ํ†ตํ•ด ๋™์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ •์ด๋‹ค. ์ด ์„ค์ •์„ ํ†ตํ•ด ๊ฐœ๋ฐœ์ž๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ๋œ ๊ถŒํ•œ ์ •๋ณด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํŠน์ • URL์ด๋‚˜ ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์„ ์„ธ๋ฐ€ํ•˜๊ฒŒ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฃผ์š” ๊ธฐ๋Šฅ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

 

  • ๊ถŒํ•œ ๊ณ„์ธต ์„ค์ • (sqlHierarchicalRoles): ๊ถŒํ•œ ๊ฐ„์˜ ๊ณ„์ธต ๊ตฌ์กฐ๋ฅผ ์ •์˜ํ•œ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์ƒ์œ„ ๊ถŒํ•œ์ด ํ•˜์œ„ ๊ถŒํ•œ์„ ์ž๋™์œผ๋กœ ํฌํ•จํ•˜๋Š” ๊ด€๊ณ„๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์ด ์‚ฌ์šฉ์ž ๊ถŒํ•œ์„ ํฌํ•จํ•˜๋Š” ๊ด€๊ณ„ ๋“ฑ์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • URL ๊ธฐ๋ฐ˜ ์ ‘๊ทผ ์ œ์–ด ์„ค์ • (sqlRolesAndUrl): ํŠน์ • URL ํŒจํ„ด์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ฟผ๋ฆฌ๋ฅผ ํ†ตํ•ด ์ •์˜ํ•œ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ๊ฐ URL์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์„ ๋™์ ์œผ๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๋ฉ”์†Œ๋“œ ๊ธฐ๋ฐ˜ ์ ‘๊ทผ ์ œ์–ด ์„ค์ • (sqlRolesAndMethod): ํŠน์ • ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœ์— ๋Œ€ํ•œ ์ ‘๊ทผ ์ œ์–ด๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ฟผ๋ฆฌ๋ฅผ ํ†ตํ•ด ์„ค์ •ํ•œ๋‹ค. ์ด๋Š” ์„œ๋น„์Šค ๋ ˆ์ด์–ด์˜ ๋ฉ”์†Œ๋“œ์— ๋Œ€ํ•œ ๊ถŒํ•œ์„ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.
  • ํฌ์ธํŠธ์ปท ๊ธฐ๋ฐ˜ ์ ‘๊ทผ ์ œ์–ด ์„ค์ • (sqlRolesAndPointcut): AspectJ ํฌ์ธํŠธ์ปท ํ‘œํ˜„์‹์„ ์‚ฌ์šฉํ•˜์—ฌ ์ง€์ •๋œ ํฌ์ธํŠธ์ปท์— ๋Œ€ํ•œ ์ ‘๊ทผ ์ œ์–ด๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ฟผ๋ฆฌ๋ฅผ ํ†ตํ•ด ์„ค์ •ํ•œ๋‹ค. ์ด๋Š” AOP(Aspect-Oriented Programming)๋ฅผ ํ™œ์šฉํ•œ ๋ณด์•ˆ ์ •์ฑ…์„ ๊ตฌํ˜„ํ•  ๋•Œ ์‚ฌ์šฉ๋œ๋‹ค.
  • ์ •๊ทœ ํ‘œํ˜„์‹ ๋งค์นญ URL ์ ‘๊ทผ ์ œ์–ด ์„ค์ • (sqlRegexMatchedRequestMapping): ์ •๊ทœ ํ‘œํ˜„์‹์„ ์‚ฌ์šฉํ•˜์—ฌ URL ํŒจํ„ด์„ ๋งค์นญํ•˜๊ณ , ํ•ด๋‹น URL์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ฟผ๋ฆฌ๋ฅผ ํ†ตํ•ด ์„ค์ •ํ•œ๋‹ค. ์ด๋Š” ๋” ๋ณต์žกํ•œ URL ํŒจํ„ด์˜ ์ ‘๊ทผ ์ œ์–ด๋ฅผ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•œ๋‹ค.

 

3. <egov-security:initializer> ๋ณด์•ˆ ๋ชจ๋“ˆ ์ดˆ๊ธฐํ™” ์„ค์ •

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋ณด์•ˆ ์ดˆ๊ธฐํ™” ์‹œ ์–ด๋–ค ๋ณด์•ˆ ๊ธฐ๋Šฅ์„ ํ™œ์„ฑํ™” ํ• ์ง€ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์ดˆ๊ธฐ ๋ณด์•ˆ ์„ค์ •์„ ๊ฐ„ํŽธํ•˜๊ฒŒ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋„์™€์ฃผ๋ฉฐ ๊ฐœ๋ฐœ์ž๊ฐ€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋ณด์•ˆ ์š”๊ตฌ ์‚ฌํ•ญ์— ๋งž์ถฐ ํ•„์š”ํ•œ ๋ณด์•ˆ ๊ธฐ๋Šฅ์„ ์„ ํƒ์ ์œผ๋กœ ํ™œ์„ฑํ™”ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค.

  • supportMethod="true": ์ด ์†์„ฑ์ด true๋กœ ์„ค์ •๋˜๋ฉด, ๋ฉ”์†Œ๋“œ ์ˆ˜์ค€์—์„œ์˜ ๋ณด์•ˆ ์„ค์ •์„ ํ™œ์„ฑํ™”ํ•œ๋‹ค. ์ฆ‰, ํŠน์ • ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœ์— ๋Œ€ํ•œ ์ ‘๊ทผ ์ œ์–ด๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์„œ๋น„์Šค ๋ ˆ์ด์–ด๋‚˜ ์ปจํŠธ๋กค๋Ÿฌ ๋ ˆ์ด์–ด์—์„œ ํŠน์ • ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์˜ ์‹คํ–‰ ๊ถŒํ•œ์„ ์„ธ๋ฐ€ํ•˜๊ฒŒ ์ œ์–ดํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.
  • supportPointcut="false": ์ด ์†์„ฑ์ด false๋กœ ์„ค์ •๋˜๋ฉด, ํฌ์ธํŠธ์ปท์„ ์‚ฌ์šฉํ•œ ๋ณด์•ˆ ์„ค์ •์€ ๋น„ํ™œ์„ฑํ™”๋œ๋‹ค. ํฌ์ธํŠธ์ปท์„ ์‚ฌ์šฉํ•œ ๋ณด์•ˆ ์„ค์ •์€ AspectJ ํ‘œํ˜„์‹์„ ํ™œ์šฉํ•˜์—ฌ, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋‹ค์–‘ํ•œ ์ง€์ (์˜ˆ: ๋ฉ”์†Œ๋“œ ์‹คํ–‰ ์ „ํ›„, ๊ฐ์ฒด ์ƒ์„ฑ ์‹œ ๋“ฑ)์— ๋ณด์•ˆ ๋กœ์ง์„ ์ ์šฉํ•˜๋Š” ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ์ด๋‹ค. ์ด ์„ค์ •์ด false๋ผ๋Š” ๊ฒƒ์€ ํ•ด๋‹น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ๋Š” ์ด๋Ÿฌํ•œ ๋ฐฉ์‹์˜ ๋ณด์•ˆ ์„ค์ •์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์ด๋‹ค.

 

4. StrictHttpFirewall  

 

Spring Security์˜ HTTP ๋ฐฉํ™”๋ฒฝ ๊ตฌ์„ฑ์„ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•ํ•˜์—ฌ URL ๋‚ด์— ์„ธ๋ฏธ์ฝœ๋ก (;)์„ ํ—ˆ์šฉํ•˜๋„๋ก ์„ค์ •ํ•˜๋Š” ์˜ˆ์‹œ์ด๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ, Spring Security์˜ StrictHttpFirewall ๊ตฌํ˜„์€ URL์— ์„ธ๋ฏธ์ฝœ๋ก ์„ ํฌํ•จํ•˜๋Š” ์š”์ฒญ์„ ์ฐจ๋‹จํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์„ธ๋ฏธ์ฝœ๋ก ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ์—ฌ๋Ÿฌ ๋ณด์•ˆ ์ทจ์•ฝ์ , ์˜ˆ๋ฅผ ๋“ค์–ด ์„ธ๋ฏธ์ฝœ๋ก ์„ ์ด์šฉํ•œ HTTP ํŒŒ๋ผ๋ฏธํ„ฐ ์˜ค์—ผ ๊ณต๊ฒฉ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•จ์ด๋‹ค. ํ•˜์ง€๋งŒ ์ด ์„ค์ •์„ ํ†ตํ•ด ์„ธ๋ฏธ์ฝœ๋ก ์„ ํ—ˆ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์ด ๋ฐฉ์‹์ด ๊ถŒ์žฅ๋˜์ง€๋Š” ์•Š์œผ๋‚˜ ํŠน์ • ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋˜๋Š” ๋ ˆ๊ฑฐ์‹œ ์‹œ์Šคํ…œ์—์„œ URL์˜ ์„ธ๋ฏธ์ฝœ๋ก ์„ ํ•„์š”๋กœ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์–ด ์ด ๋Œ€ ๋ณด์•ˆ์ •์ฑ…์„ ์œ ์—ฐํ•˜๊ฒŒ ์กฐ์ •ํ•ด์•ผํ•  ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์ •๋ง ํ•„์š”ํ•  ๋•Œ๋งŒ ์‚ฌ์šฉํ•  ๊ฒƒ!

 

  • StrictHttpFirewall ๋นˆ ์ •์˜: org.springframework.security.web.firewall.StrictHttpFirewall ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋นˆ์œผ๋กœ ์„ ์–ธํ•œ๋‹ค. ์ด ํด๋ž˜์Šค๋Š” Spring Security์˜ HTTP ์š”์ฒญ์— ๋Œ€ํ•œ ๋ฐฉํ™”๋ฒฝ ์—ญํ• ์„ ํ•œ๋‹ค.
  • allowSemicolon ํ”„๋กœํผํ‹ฐ: true๋กœ ์„ค์ •ํ•จ์œผ๋กœ์จ, URL ๋‚ด ์„ธ๋ฏธ์ฝœ๋ก ์˜ ์‚ฌ์šฉ์„ ํ—ˆ์šฉํ•œ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ false๋กœ, ์„ธ๋ฏธ์ฝœ๋ก ์„ ํฌํ•จํ•œ ์š”์ฒญ์€ ์ฐจ๋‹จ๋œ๋‹ค.
  • ๋ฐฉํ™”๋ฒฝ์„ Spring Security ์„ค์ •์— ์ ์šฉ: <security:http-firewall> ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ egovStrictHttpFirewall ๋นˆ์„ Spring Security์˜ HTTP ๋ฐฉํ™”๋ฒฝ์œผ๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์ „์ฒด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ HTTP ์š”์ฒญ ๊ฒ€์‚ฌ ๋ฐฉ์‹์„ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•ํ•œ.
๋ฐ˜์‘ํ˜•
Comments