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 | 29 | 30 |
Tags
- JavaScript
- 도커
- AWS
- docker
- 웹게임
- tiles.xml
- express
- model1
- autowired
- 비트코인
- PL/SQL
- phaser
- node.js
- Spring
- 배포
- Cookie
- CSS
- Ajax
- JSP
- Servlet
- 웹소켓
- 알고리즘
- 암호화
- websocket
- EC2
- 블록체인
- jQuery
- SQL
- RDS
- HTML
Archives
- Today
- Total
記錄
Spring) security + 암호화 세팅 본문
pom.xml
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
web.xml
<!-- Root IOC 컨테이너 구성하기 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/security-context.xml
</param-value>
</context-param>
<!-- 인증권한 관련 Filter -->
<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>
security-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
">
<security:http>
<security:csrf disabled="true"/>
<security:form-login login-page="/joinus/login.htm"
authentication-failure-url="/joinus/login.htm?error" />
<security:logout logout-success-url="/index.htm" />
<!-- Role 검사하고 싶은 요청값 설정과 Role 설정 -->
<security:intercept-url pattern="/customer/*Reg.htm" access="hasRole('ROLE_USER')" />
<security:intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')" />
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:jdbc-user-service data-source-ref="driverManagerDataSource"
users-by-username-query="select userid, pwd as password, 1 enabled from
member where userid=?"
authorities-by-username-query="select m.userid, r.ROLE_NAME
from member m join roll r
on m.userid = r.userid
where m.userid=?"
/>
<security:password-encoder ref="bCryptPasswordEncoder"/>
</security:authentication-provider>
</security:authentication-manager>
</beans>
applicationContext.xml
<bean id="bCryptPasswordEncoder" class="org.springframework.security.crypto.
bcrypt.BCryptPasswordEncoder">
</bean>
Controller 사용 예시
@Autowired
private BCryptPasswordEncoder bCryptPasswordEncoder;
@RequestMapping(value="join.htm",method=RequestMethod.POST)
public String join(Member member) {
//회원가입 처리 .... NewMemberDao
//System.out.println(member.toString());
member.setPwd(this.bCryptPasswordEncoder.encode(member.getPwd()));
MemberDao memberdao = sqlsession.getMapper(MemberDao.class);
try {
memberdao.insertMember(member);
} catch (Exception e) {
e.printStackTrace();
}
return "redirect:/index.htm"; //수정하면 안되면 페이지 다시 요청
}
'Web > Spring framework' 카테고리의 다른 글
Spring) ajax _2(@ResponseBody, @RequestBody 사용) (0) | 2018.05.11 |
---|---|
Spring) ajax _1(MappingJackson2JsonView 사용) (0) | 2018.05.11 |
Spring+Mybatis+Tiles 4) Tiles의 사용(layout.jsp를 중심으로) (0) | 2018.05.06 |
Spring+Mybatis+Tiles 3) Controller (0) | 2018.05.06 |
Spring+Mybatis+Tiles 2) Mybatis설정(.jsp, DTO, DAO, mapper(Emp.xml)) (0) | 2018.05.06 |
Comments