일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- java
- AWS
- it
- JVM
- devops
- 맛집
- db
- 요리
- Git
- IntelliJ
- laravel
- MySQL
- ReactJS
- tool
- javascript
- jsp
- Spring
- php
- Oracle
- ubuntu
- Spring Boot
- Spring Batch
- Web Server
- Design Patterns
- springboot
- redis
- linux
- elasticsearch
- jenkins
- Gradle
- Today
- Total
아무거나
[spring] 보안 Security - 1 본문
[spring] 보안 Security - 1
1. 보안 관련 라이브러리 추가
방법 1. https://docs.spring.io/spring-security/site/docs/5.0.6.RELEASE/reference/htmlsingle/ 에서 다운받거나 dependency 추가
방법 2. 이클립스 기준 pom.xml -> 하단 Dependencies탭 클릭 -> Add.. 클릭 -> Enter groupId, artifactId or sha1 prefix ... 에 security 검색
-> org.springframework.security(spring-security-acl) 선택
(1) security-context.xml 생성 ( src/main/webapp/WEB-INF/spring/appServlet/security-context.xml )
[내용]
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">
</beans>
* 해당경로에 오른쪽 클릭해서 xml생성을해서 next를 누르면 사용할 bean을 선택한다
security를 체크하고 맨위의 최신버전을 체크해서 사용하자.
(2) web.xml에 security-context.xml를 추가하자. ( src/main/webapp/WEB-INF/web.xml )
[web.xml]
....
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
/WEB-INF/spring/appServlet/security-context.xml
</param-value>
</context-param>
....
2. In-Memory 인증
(1) security-context.xml 생성 후 내용추가 ( src/main/webapp/WEB-INF/spring/appServlet/security-context.xml )
[내용]
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<security:http auto-config="true">
<!-- 페이지 별로 접근제어 ex: ROLE_USER -->
<security:intercept-url pattern="/login.html*" access="ROLE_USER"/>
<security:intercept-url pattern="/welcome.html*" access="ROLE_ADMIN"/>
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<!-- login.html에 접근시 아래 name, password대로 입력해야 통과된다. -->
<security:user name="user" password="123" authorities="ROLE_USER"/>
<!-- 아래 룰은 admin유저가 ROLE_ADMIN,ROLE_USER 둘다 접근이 가능하다 -->
<security:user name="admin" password="123" authorities="ROLE_ADMIN,ROLE_USER"/>
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
</beans>
(2) 필터추가 ( src/main/webapp/WEB-INF/web.xml )
[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>
....
'Java & Kotlin > Spring Security' 카테고리의 다른 글
[Spring Security] Spring Security + H2 DB + Swagger 연동시 페이지 접근 예외 처리 (0) | 2021.01.16 |
---|---|
[spring] 보안 Security - 2 (0) | 2019.12.26 |
[Spring Security] Spring Boot + Spring Security + Mybatis + Thymeleaf + Gradle 로그인 기능 구현 (8) | 2019.01.18 |
Spring Security 사용시 원하는 호출 URI에 권한허용 방법 (0) | 2019.01.07 |