Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- analytics4
- network
- rsync
- 티스토리챌린지
- 차이점
- 트랜잭션
- 명령어
- mssql
- Javascript
- DBMS
- mysql
- git
- MongoDB
- group by
- 리눅스
- Python
- API
- oracle
- Linux
- top
- docker
- 오블완
- IntelliJ
- MariaDB
- java
- JPA
- 자바
- spring
- PostgreSQL
- SQL
Archives
- Today
- Total
hanker
Spring Security (1) - 기본 설정 (xml) 본문
반응형
1. pom.xml 설정
<properties>
<java-version>1.8</java-version>
<org.springframework-version>4.2.5.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<!-- security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${org.springframework-version}</version>
</dependency>
2. web.xml 설정
<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>
<!-- Spring security -->
<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>
<!-- 이하생략 -->
- appServlet 디렉토리 밑에 security-context.xml 파일 생성
3. security-context.xml 설정
<security:http>
<security:intercept-url pattern="/**" access="hasRole('USER')" />
<security:form-login />
<security:logout />
</security:http>
<!-- provider -->
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="user" password="password" authorities="ROLE_USER" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
- hasRole('USER') : hasRole 안에 USER는 ROLE_USER 와 같다. ROLE 생략가능
- 로그인 할 id, password 임의 지정 : id(user), pw(password), authorities(ROLE_USER)
설정 후 서버 실행 시
로그인 UI가 기본적으로 제공된다.
임의로 지정했던 id, password 입력 후 login
<로그인 성공시 화면>
4. home.jsp 소스
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html lang="en">
<head>
</head>
<body>
<h1>HOME!</h1>
<form:form action="${pageContext.request.contextPath}/logout" method="POST">
<input type="submit" value="로그아웃" />
</form:form>
</body>
</html>
반응형
'SPRING' 카테고리의 다른 글
SPRING - mybatis에서 resultType=boolean 사용하기 (0) | 2020.11.02 |
---|---|
SPRING - openlayers 지도보기, mouseOver 좌표확인 (0) | 2020.08.19 |
SPRING - VO클래스 alias 설정 (0) | 2020.08.18 |
Spring Security (3) - JDBC 설정 (xml) (0) | 2020.08.15 |
Spring Security (2) - 로그인, 로그아웃 설정 (xml) (0) | 2020.08.13 |