Version Control2011. 4. 20. 13:57

## 설치파일 다운로드

http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91

 
1.  C:\repository 폴더를 생성합니다.

     C:\Documents and Settings\Administrator>md c:\repository

     C:\Documents and Settings\Administrator>cd c:\repository


2.
  
저장소 생성하기
     - 버클리 DB를 이용한 저장소

     C:\repository>svnadmin create --fs-type bdb sample

     - 파일시스템을 이용한 저장소

     C:\repository>svnadmin create --fs-type fsfs sample

 
3. 저장소 설정 및 사용자 등록
  Repository 폴더로 이동하면 conf폴더가 있습니다. 하위에는 아래와 같이 3개의 파일이 있습니다.

Authz / passwd / svnserve.conf


1)     Svnserve.conf 파일 설정

 

### This file controls the configuration of the svnserve daemon, if you

### use it to allow access to this repository.  (If you only allow

### access through http: and/or file: URLs, then this file is

### irrelevant.)

 

### Visit http://subversion.tigris.org/ for more information.

 

[general]

### These options control access to the repository for unauthenticated

### and authenticated users.  Valid values are "write", "read",

### and "none".  The sample settings below are the defaults.

anon-access = none

auth-access = write

### The password-db option controls the location of the password

### database file.  Unless you specify a path starting with a /,

### the file's location is relative to the directory containing

### this configuration file.

### If SASL is enabled (see below), this file will NOT be used.

### Uncomment the line below to use the default password file.

password-db = passwd

### The authz-db option controls the location of the authorization

### rules for path-based access control.  Unless you specify a path

### starting with a /, the file's location is relative to the the

### directory containing this file.  If you don't specify an

### authz-db, no path-based access control is done.

### Uncomment the line below to use the default authorization file.

#authz-db = authz

### This option specifies the authentication realm of the repository.

### If two repositories have the same authentication realm, they should

### have the same password database, and vice versa.  The default realm

### is repository's uuid.

#realm = My First Repository

 

[sasl]

### This option specifies whether you want to use the Cyrus SASL

### library for authentication. Default is false.

### This section will be ignored if svnserve is not built with Cyrus

### SASL support; to check, run 'svnserve --version' and look for a line

### reading 'Cyrus SASL authentication is available.'

# use-sasl = true

### These options specify the desired strength of the security layer

### that you want SASL to provide. 0 means no encryption, 1 means

### integrity-checking only, values larger than 1 are correlated

### to the effective key length for encryption (e.g. 128 means 128-bit

### encryption). The values below are the defaults.

# min-encryption = 0

# max-encryption = 256


2)    passwd 파일 설정 (사용자 등록 및 암호 설정)
### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.
[users]
# harry = harryssecret
# sally = sallyssecret
suma = 123
tiwaz = 123

3)    authz 파일 설정 (사용자 그룹 설정 및 접근 설정)

### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization line can refer to:
###  - a single user,
###  - a group of users defined in a special [groups] section,
###  - an alias defined in a special [aliases] section,
###  - all authenticated users, using the '$authenticated' token,
###  - only anonymous users, using the '$anonymous' token,
###  - anyone, using the '*' wildcard.
###
### A match can be inverted by prefixing the rule with '~'. Rules can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').
 
[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
 
[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
mygroup = suma,tiwaz
 
# [/foo/bar]
# harry = rw
# &joe = r
# * =
 
#[repository:/]
# @harry_and_sally = rw
# * = r
 
[/]
@mygroup = rw
 
[sample:/]
* = r

@mygroup = rw


4. 서버 구동하기
  
- svnserve를 사용한 서버

     C:\>svnserve -d -r C:\repository


Posted by Tiwaz
JSP2011. 4. 20. 11:50

JSP 프로그래밍에서 페이지 이동 방법이 여러가지가 있습니다.
비지니스 로직 수행에서 redirect나 forward 아니면 해당 페이지에서 직접 redirect, forward, html, javascript 를 이용한 페이지 이동 등등..

그중에서 request.getRequestDispatcher("/view.jsp").forward(request, response) 를 사용하였을때 중복 저장 또는 중복 로직 수행에 대해서 알아 보려고 합니다.

forward를 사용하는 이유는 아래처럼 정리 할 수 있지만.. forward의 특징 중 하나가 이전페이지의 객체를 보존하고 있습니다.
'특정 페이지에서 전달된 데이터를 로직을 수행하고 수행된 결과(Object Data)를 원하는 페이지에 전달 후 보여주려고 한다.'

예로
              '사용자가 입력 페이지의 폼에서 저장버튼 클릭 -> 저장 로직 수행 후 DB 입력 -> 리스트 페이지 이동'
을 하였을 경우 이동한 리스트 페이지에서 F5키 나 새로고침을 하였을 경우 위의 로직을 다시 타는 경우가 발생합니다.
만약 DB의 PK 설정이 oracle의 sequence나 mssql의 시드를 이용한 자동 증가가 아닐 경우 PK 값 위반에 대한 Exception 이 일어 날 것이며 PK 가 없다면 같은 데이터가 중복 저장되는 경우가 생깁니다.

그래서 double submit을 막아 보려고 구글링 등등 이것저것 찾아 보았는데
Spring의 경우 SessionStatus, Struts의 Token, Post - Redirect- Get 패턴 등등 ;;

이미 프로젝트가 막바지라 급하게 손쓸 방법을 찾다가 쉽게 쓸수 있을 것 같아 적용해 보았는데 성공하여 포스트 합니다;;
http://blog.naver.com/PostView.nhn?blogId=canya83&logNo=40094442229&parentCategoryNo=15&viewDate=&currentPage=1&listtype=0

## 원리 ::
1. 최초 페이지(Token 없음) : jsp에서 Token을 생성 ( T1 생성)
2. 서버의 컨트롤러에서 JSP에서 생성된 Token이 컨트롤러의 Token과 같을 경우 신규 요청으로 설정
     (T1 == T2 으면 Token 생성)
3. 비지니스 로직 처리 후 특정 페이지로 이동하여 새로고침 ( T1 != T2)
4. 서버의 컨트롤러에서 이전 JSP에서 생성된 Token이 컨트롤러의 Token과 다르므로 Token 생성 안함
     (T1 != T2 )  해당 요청에 대해서는 비지니스 로직을 수행 안함.

## 코드
1. 공통 Controller에서 사용할 Token.java 를 하나 만들자!

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class Token {
 
 private static final String TOKEN_KEY = "TOKEN_KEY";
 
 public static void set(HttpServletRequest request) {
  HttpSession session = request.getSession(true);
  long systemTime = System.currentTimeMillis();
  byte[] time = new Long(systemTime).toString().getBytes();
  byte[] id = session.getId().getBytes();
  
  try {
   MessageDigest md5 = MessageDigest.getInstance("MD5");
   md5.update(id);
   md5.update(time);
   
   String token = toHex(md5.digest());
   request.setAttribute(TOKEN_KEY, token);
   session.setAttribute(TOKEN_KEY, token);
  } catch (NoSuchAlgorithmException e) {
   e.printStackTrace();
  }
 }
 
 public static boolean isValid(HttpServletRequest request) {
  HttpSession session = request.getSession(true);
  String requestToken = request.getParameter(TOKEN_KEY);
  String sessionToken = (String)session.getAttribute(TOKEN_KEY);
  if(requestToken == null || sessionToken == null) {
   return false;
  } else {
   return requestToken.equals(sessionToken);
  }
 }
 
 private static String toHex(byte[] digest) {
  StringBuffer buf = new StringBuffer();
  for(int i=0;i<digest.length;i++) {
   buf.append(Integer.toHexString((int)digest[i] & 0x00ff));
  }
  return buf.toString();
 }
}


2. HttpServlet 을 재구현한 공통 컨트롤러의 forward 부분에 아래와 같이 추가 한다.

if(Token.isValid(request)) {
    Token.set(request);
    request.setAttribute("TOKEN_SAVE_CHECK", "TRUE");
} else {
     request.setAttribute("TOKEN_SAVE_CHECK", "FALSE");
}


3. 중복 저장을 막고자하는 JSP 페이지 아래와 같이 추가 한다.

       <%
        if(request.getAttribute("TOKEN_KEY")==null) Token.set(request);
       %>
       <input type="hidden" name="TOKEN_KEY" value="<%=request.getAttribute("TOKEN_KEY")%>"/>


4. business logic을 수행하는 부분에서 CRUD 등등 처리 부분의 처음 부분에 아래와 같이 추가한다.

if("TRUE".equals(request.getAttribute("TOKEN_SAVE_CHECK"))) {
   // 신규 요청이므로 원하는 로직 작성
} else {
  // 중복 요청이므로 그에 따른 로직 작성
}


5. 테스트!

'JSP' 카테고리의 다른 글

사용자 정의 태그  (0) 2010.04.09
필터와 리스너  (0) 2010.04.09
Posted by Tiwaz
Database/SQL Server2011. 3. 2. 09:42

JDBC 테스트 중 sqljdbc.jar가 포함된 runnable jar 파일을 실행하면 아래와 같은 Exception을 일으키며 파일이 실행되지 않는다.

Exception in thread "main" java.lang.SecurityException: invalid SHA1 signature f
ile digest for com/microsoft/sqlserver/jdbc/SQLServerException.class
at sun.security.util.SignatureFileVerifier.verifySection(Unknown Source)

at sun.security.util.SignatureFileVerifier.processImpl(Unknown Source)
at sun.security.util.SignatureFileVerifier.process(Unknown Source)
at java.util.jar.JarVerifier.processEntry(Unknown Source)
at java.util.jar.JarVerifier.update(Unknown Source)
at java.util.jar.JarFile.initializeVerifier(Unknown Source)
at java.util.jar.JarFile.getInputStream(Unknown Source)
at sun.misc.URLClassPath$JarLoader$2.getInputStream(Unknown Source)
at sun.misc.Resource.cachedInputStream(Unknown Source)
at sun.misc.Resource.getByteBuffer(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)



내 나름대로 정의한 이유인즉 sqljdbc에 포함된 class 파일에 SHA1 방식으로 암호화 맵핑이 되어 있는데 JVM에서 풀지 못하여 Exception이 발생하지 않을까 한다.

그래서 간단한 해결 방법을 찾아보자~!

1. Microsoft 홈페이지로 들어가서 sqljdbc 파일을 다운로드 받는다.(해당 링크는 2.0 버젼)
http://www.microsoft.com/downloads/ko-kr/details.aspx?displaylang=ko&FamilyID=99b21b65-e98f-4a61-b811-19912601fdc9

2. 다운로드 받은 후 설치를 하면 디렉토리 안에 2.0 버젼의 경우 sqljdbc.jar와 sqljdbc4.jar 파일이 있음을 확인 할 수 있다.

3. sqljdbc.jar 또는 sqljdbc4.jar 파일을 압축 해제 한다.

3. 압축 해제한 디렉토리에서 META-INF 폴더로 이동한다.

4. 폴더에 있는 SIGNED.SF / SIGNED.RSA 파일을 삭제한다.
단, 2005 이하 버전용 sqljdbc의 경우 zigbert.sf / zigbert.rsa 이며 동일하게 삭제 한다.

5. MANIFEST.MF 파일을 열어보면 아래와 같은 내용을 확인 할 수 있다.
아래 부분의 1, 2, 3 Line 을 제외한 나머지 Line을 모두 지운 후 다시 sqljdbc.jar 파일로 압축을 한다.

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.5.0_15-b04 (Sun Microsystems Inc.)

Name: com/microsoft/sqlserver/jdbc/SQLServerException.class
SHA1-Digest: wJmi22LxY0sGSj6Fo/b+189olOA=

.....


6. sqljdbc.jar 파일을 해당 프로젝트에 다시 추가한후 runnable jar에 포함하여 실행 가능한지 테스트 한다.

Posted by Tiwaz
Version Control2010. 12. 21. 22:02
ERROR
    failed to load javaHL Library

해결 방법
1. root@localhost ~] yum install subversion - javahl

2. 설치가 완료되면 /usr/lib/ 디렉토리에 libsvn* 항목으로 설치된 파일을 확인 할 수 있다.

3. 이클립스가 설치된 디렉토리로 이동하여 eclipse.ini 파일을 연다.

4. --vmargs 아래에 -Djava.library.path=/usr/lib/ 를 추가 해준다.

이클립스 구동하 sync를 맞춰주면 해결 완료!!

'Version Control' 카테고리의 다른 글

Subversion 서버 설치 및 간단 설정  (0) 2011.04.20
Posted by Tiwaz
Linux & Unix2010. 12. 21. 21:52
ERROR
    failed to execute child process "eclipse" (permission denie)

해결 방법
    root@localhost ~] cd /usr/local/bin
    root@localhost bin] ln -s /opt/eclipse/eclipse eclipse
Posted by Tiwaz