Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 소켓통신
- JPA
- IAM 결제
- MFC
- AWS 청구
- web browser external
- hit desktop
- oracle 18
- TCP/IP
- javasecurity
- C++
- html주문폼
- AWS경보
- 깃헙 데스크탑
- aws
- servlet에러
- git stah
- IP통신
- SpringToolSuite4
- springboot
- Update
- hmlt
- AWS요금
- jsp에러
- html사용자함수
- jsNature
- 오라클 c##제거
- bootstrap
- js구구단
- AWS사용자
Archives
- Today
- Total
Ynns
spring security 프로젝트 (3) 본문
# MemberInsertTest 클래스
package com.spring.controller;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.inject.Inject;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//RunWith : 테스트를 실행하기 위해 필요한 어노테이션
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"file:src/main/webapp/WEB-INF/spring/root-context.xml",
"file:src/main/webapp/WEB-INF/spring/security-context.xml"})
public class MemberInsertTest {
@Inject
private DataSource ds; //root-context.xml 에 작성해둔 ds
@Inject
private PasswordEncoder encoder; //암호화 security-context.xml 에 작성해둔 bcrypt
@Test //테스트를 위한 메소드임을 명시한다
public void test() {
String sql="insert into spring_member(userid,userpw,username) values(?,?,?)"; //sql문
Connection con = null;
PreparedStatement pstm = null;
for(int i=0;i<100;i++) {
try {
con=ds.getConnection();
pstm=con.prepareStatement(sql);
pstm.setString(2, encoder.encode("pw"+i)); //userpw 에 집어넣을 때 암호화를 위해 작성
if(i<80) {
pstm.setString(1, "user"+i);
pstm.setString(3, "일반 사용자"+i);
}else if(i<90){
pstm.setString(1, "member"+i);
pstm.setString(3, "운영자"+i);
}else {
pstm.setString(1, "admin"+i);
pstm.setString(3, "관리자"+i);
}
pstm.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if(pstm!=null) {
try {
pstm.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(con!=null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
}
# JUnit Test 로 실행
# DB 에서 생성된 유저 확인
select * from spring_member;
'JAVA > Spring' 카테고리의 다른 글
spring security 프로젝트(4) (0) | 2019.11.26 |
---|---|
spring 프로젝트 암호화 로그인 오류 해결 (0) | 2019.11.14 |
spring security 프로젝트 (2) (0) | 2019.11.08 |
spring security 프로젝트 실행 (1-1) (0) | 2019.11.08 |
spring security 프로젝트 (1) (0) | 2019.11.07 |
Comments