TIL 23.12.02

ν™©μ€ν•˜Β·2023λ…„ 12μ›” 4일
0

TIL

λͺ©λ‘ 보기
127/146

πŸ“ŒToday I Learned

Spring

web socket μ±„νŒ… - 슀크둀, 이λͺ¨ν‹°μ½˜


μƒˆ ν”„λ‘œμ νŠΈ λ§Œλ“€κΈ°

New > Spring Legacy Project > Spring MVC Project > "SecurityTest" > "com.test.spring" > Finish


이전 인증 방식 > μ„Έμ…˜(μΏ ν‚€) 기반 + 직접 처리 μŠ€ν”„λ§ ν”„λ ˆμž„μ›Œν¬ > 인증 > Spring Security Project

μŠ€ν”„λ§ μ‹œνλ¦¬ν‹°

μ–΄λ €μš°λ‹ˆκΉŒ μ§‘μ€‘ν•˜μž!

ν”„λ‘œμ νŠΈ μ„€μ •
1. 일괄 μ„€μ •
- pom.xml
- web.xml
- root-context.xml

  1. Web-INF > lib > ojdbc6.jar

    • Build Path μΆ”κ°€
  2. pom.xml

    • μ‹œνλ¦¬ν‹° μ˜μ‘΄μ„± 4개 μΆ”κ°€
    <!-- Security -->
    	<dependency>
    		<groupId>org.springframework.security</groupId>
    		<artifactId>spring-security-web</artifactId>
    		<version>5.0.7.RELEASE</version>
    	</dependency>
    	<dependency>
    		<groupId>org.springframework.security</groupId>
    		<artifactId>spring-security-config</artifactId>
    		<version>5.0.7.RELEASE</version>
    	</dependency>
    	<dependency>
    		<groupId>org.springframework.security</groupId>
    		<artifactId>spring-security-core</artifactId>
    		<version>5.0.7.RELEASE</version>
    	</dependency>
    	<dependency>
    		<groupId>org.springframework.security</groupId>
    		<artifactId>spring-security-taglibs</artifactId>
    		<version>5.0.7.RELEASE</version>
    	</dependency>
  3. νŒ¨ν‚€μ§€

    • "com.test.controller"
    • "com.test.persistence"
    • "com.test.domain"
    • "com.test.mapper"
    • "com.test.security"
  4. servlet-context.xml

    • μŠ€μΊ” μΆ”κ°€ (domain, mapper λΉΌκ³ )
    <context:component-scan base-package="com.test.controller" />
    <context:component-scan base-package="com.test.persistence" />
    <context:component-scan base-package="com.test.security" />
  5. security-context.xml
    - 파일 생성
    - /WEB-INF/spring/security-context.xml
    - μŠ€ν”„λ§ μ‹œνλ¦¬ν‹°μ˜ μ „λ°˜μ μΈ μ„€μ •



    "-5.0" μ œκ±°ν•˜κΈ°

  6. web.xml

    • μŠ€ν”„λ§ μ‹œνλ¦¬ν‹°κ°€ λ™μž‘ν•  수 있게 ν•„ν„° μΆ”κ°€
    <!-- μ‹œνλ¦¬ν‹° ν•„ν„°(λ°˜λ“œμ‹œ 인코딩 ν•„ν„° λ‹€μŒμ— μœ„μΉ˜) -->
    <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>
  7. μ‹€ν–‰

    • μ—λŸ¬ > "No beans ..."
    • security-context.xml을 찾지 λͺ»ν•΄μ„œ

8.1. web.xml > security-context.xml μœ„μΉ˜ μΆ”κ°€

ν•œ 쀄 μΆ”κ°€

8.2. security-context.xml > κΈ°λ³Έ ꡬ문 μž‘μ„±

  1. 기본적인 URI 섀계
    • /index.do > 초기 νŽ˜μ΄μ§€(λͺ¨λ‘ μ ‘κ·Ό)
    • /member/member.do > νšŒμ› νŽ˜μ΄μ§€(νšŒμ›λ§Œ μ ‘κ·Ό, κ΄€λ¦¬μžλ„ μ ‘κ·Ό)
    • /admin/admin.do > κ΄€λ¦¬μž νŽ˜μ΄μ§€(κ΄€λ¦¬μžλ§Œ μ ‘κ·Ό)

9.1. 파일 생성
- com.test.controller > "TestController.java"
- views > "index.jsp"
> "member" > "member.jsp"
> "admin" > "admin.jsp"
> "inc" > "header.jsp"

9.2. μ‹€ν–‰
- 정상 μ‹€ν–‰

  1. 둜그인
    • security-context.xml μˆ˜μ •

10.1. pattern 속성
- μ ‘κ·Όν•  URI

10.2. access 속성
- ν‘œν˜„μ‹
- μ ‘κ·Ό κΆŒν•œ

10.3. μ‹€ν–‰
- index.do
Β Β Β Β > μ ‘κ·Ό 성곡
- member.do
Β Β Β Β > μ ‘κ·Ό μ‹€νŒ¨
Β Β Β Β > http://localhost:8090/spring/login
Β Β Β Β > 빌트인 둜그인 νŽ˜μ΄μ§€λ‘œ 이동(κΆŒν•œ μ—†μ–΄μ„œ..)


11. λ‹¨μˆœ 둜그인
- 직접 κ΅¬ν˜„(X)
- λ‚΄μž₯ κ΅¬ν˜„(O)

11.1. 주의점(***)
- 일반 μ‹œμŠ€ν…œ(id) == μŠ€ν”„λ§ μ‹œνλ¦¬ν‹°

11.2. security-context.xml μˆ˜μ •
- 계정 μΆ”κ°€

11.3. λ‘œκ·Έμ•„μ›ƒ

  1. μ—¬λŸ¬ κΆŒν•œμ„ κ°€μ§€λŠ” μ‚¬μš©μž
    • κ΄€λ¦¬μž > 일반 νšŒμ› κΆŒν•œ + κ΄€λ¦¬μž κΆŒν•œ

12.1. security-context.xml

12.2. μ‹€ν–‰
- hong 둜그인
- member.do > 성곡
- admin.do > μ‹€νŒ¨ > 403

  1. 403 νŽ˜μ΄μ§€ κ΅¬ν˜„

    • con.test.controller > "AuthController.java"
    • views > "auth" > "accesserror.jsp"
  2. 둜그인 νŽ˜μ΄μ§€ κ΅¬ν˜„

    • μ»€μŠ€ν…€ 둜그인 νŽ˜μ΄μ§€
    • μ ‘κ·Ό μ œν•œ(403) νŽ˜μ΄μ§€μ²˜λŸΌ 직접 νŠΉμ • URIλ₯Ό 지정할 수 μžˆλ‹€.

14.1. security-context.xml

14.2. AuthController.xml
- "AuthController.java"
- views > "mylogin.jsp"

14.3. CSRF, Cross-site request forgery
- ν•΄ν‚Ή 기법
- μš”μ²­ 정보λ₯Ό λ‹€λ₯Έ μ‚¬μ΄νŠΈμ—μ„œ λ³΄λ‚΄μ„œ μœ„μ‘°ν•˜λŠ” 기법
- μŠ€ν”„λ§ μ‹œνλ¦¬ν‹° > CSFR 방지
- λͺ¨λ“  POST μš”μ²­μ„ ν•  λ•Œ > μœ„μ‘°κ°€ λ˜μ§€ μ•Šμ•˜λ‹€λŠ” 사싀을 증λͺ…ν•΄μ•Όν•œλ‹€.


15. 둜그인 성곡 이후 처리
- 정해진 URI둜 μ΄λ™ν•˜κΈ°
- 일반 νšŒμ› > member.do 이동
- κ΄€λ¦¬μž > admin.do 이동

15.1.
- com.test.security > "CustomLoginSuccessHandler.java"

15.2. security-context.xml


16. λ‘œκ·Έμ•„μ›ƒ 처리
- 둜그인처럼 νŠΉμ •ν•œ URIλ₯Ό μ§€μ •ν•˜κ³ , λ‘œκ·Έμ•„μ›ƒ 처리 ν›„ 직접 λ‘œμ§μ„ μ²˜λ¦¬ν•˜λŠ” ν•Έλ“€λŸ¬λ₯Ό λ“±λ‘ν•œλ‹€.

16.1 security-context.xml

16.2 AuthController

16.3 views > auth > "mylogout.jsp"


내일
계정 정보(였라클) + μ‹œνλ¦¬ν‹° 연동

aws μ‹œμž‘ => μ‹ μš©μΉ΄λ“œ κ°€μ Έμ˜€κΈ°

profile
μ°¨κ·Όμ°¨κ·Ό ν•˜λ‚˜μ”©

0개의 λŒ“κΈ€