WSS API를 사용하여 생성기 보안 토큰 구성

WSS API(Web Services Security API)를 사용하여 정책 세트를 사용하지 않고도 SOAP 메시지를 보안 설정할 수 있습니다. 생성기 측에서 토큰을 구성하려면 WSS API(Web Services Security API)를 사용하십시오. 생성기 보안 토큰은 com.ibm.websphere.wssecurity.wssapi.token 인터페이스 패키지의 파트입니다.

시작하기 전에

WebSphere® Application Server의 플러그 가능 토큰 프레임워크가 WSS API의 같은 프레임워크를 다시 사용할 수 있도록 다시 설계되었습니다. 보안 토큰 작성 및 유효성 검증에 대한 동일한 구현은 웹 서비스 보안 런타임 및 WSS API 애플리케이션 코드 둘 다에 사용할 수 있습니다. 다시 설계된 프레임워크는 SPI 프로그래밍 모델을 단순화하고 보안 토큰 유형의 추가를 용이하게 합니다.

WSS API를 사용하거나 관리 콘솔을 통해 토큰을 구성할 수 있습니다. 토큰을 구성하려면 다음 토큰 태스크를 완료해야 합니다.

  • 생성기 토큰을 구성하십시오.
  • 이용자 토큰을 구성하십시오.

이 태스크 정보

JAAS CallbackHandler 및 JAAS LoginModule은 생성기 측에서 보안 토큰 작성을 담당합니다.

생성기 측에서 토큰은 JAAS LoginModule을 사용하여 작성되고 인증 데이터 전달에 JAAS CallbackHandler를 사용하여 작성됩니다. 그러면 JAAS LoginModule이 securityToken 오브젝트(예: UsernameToken)를 작성하고 이 오브젝트를 웹 서비스 보안 런타임에 전달합니다.

이용자 측에서 XML 형식이 유효성 검증 및 인증을 위해 JAAS LoginModule에 전달됩니다. 그러면 JAAS CallbackHandler가 사용되어 웹 서비스 보안 런타임에서 로그인 모듈로 인증 데이터를 전달합니다. 토큰이 인증되고 보안 토큰 오브젝트가 작성된 후에는 토큰이 이 오브젝트를 웹 서비스 보안 런타임에 전달합니다.

생성기 토큰 작성에 WSS API를 사용하면 특정 기본 동작이 발생합니다. WSS API를 사용하는 가장 간단한 방법은 기본 동작을 사용하는 것입니다(예제 코드 참조). WSS API는 토큰 유형, 토큰 값 및 JAAS 확인 이름의 기본값을 제공합니다. 기본 토큰 동작은 다음과 같습니다.

표 1. 토큰 결정 및 기본 동작. 기본적으로 여러 토큰 특성이 구성됩니다.
생성기 토큰 결정 기본 동작
사용할 토큰 유형

토큰 유형은 메시지 무결성, 메시지 기밀성 또는 메시지 확실성을 위해 사용할 토큰 유형을 지정합니다.

WebSphere Application Server는 메시지 무결성 및 메시지 기밀성을 위해 다음 사전 구성된 생성기 토큰 유형을 제공합니다.
  • 파생 키 토큰
  • X509 토큰
필요에 따라 사용자 정의 토큰 유형을 작성할 수도 있습니다.

WebSphere Application Server는 메시지 확실성을 위해 다음 사전 구성된 생성기 토큰 유형을 제공합니다.

  • Username 토큰
  • LTPA 토큰
  • X509 토큰

필요에 따라 사용자 정의 토큰 유형을 작성할 수도 있습니다.

지정할 JAAS 로그인 구성 이름

JAAS 로그인 구성 이름은 사용할 JAAS 로그인 확인 이름을 지정합니다.

사용할 구성 유형 JAAS 로그인 모듈은 구성 유형을 지정합니다. 사전 구성된 생성기 구성 유형만 생성기 토큰 유형에 사용할 수 있습니다.

SecurityToken 클래스(com.ibm.websphere.wssecurity.wssapi.token.SecurityToken)는 일반 토큰 클래스이며 ID, XML 형식 및 암호 키를 얻기 위한 메소드가 있는 보안 토큰을 표시합니다. SecurityToken 클래스를 사용하면 SOAP 메시지에 서명 및 암호화를 모두 적용할 수 있습니다. 그러나 이 둘 모두를 적용하기 위해서는 서명과 암호화용으로 두 개의 SecurityToken 오브젝트가 있어야 합니다.

다음 토큰 유형은 일반 보안 토큰 클래스의 서브클래스입니다.

표 2. SecurityToken의 서브클래스. 서브클래스를 사용하여 보안 토큰을 표시합니다.
토큰 유형 JAAS 로그인 구성 이름
Username 토큰 system.wss.generate.unt
보안 컨텍스트 토큰 system.wss.generate.sct
파생 키 토큰 system.wss.generate.dkt

다음 토큰 유형은 2진 보안 토큰 클래스의 서브클래스입니다.

표 3. BinarySecurityToken의 서브클래스. 서브클래스를 사용하여 2진 보안 토큰을 표시합니다.
토큰 유형 JAAS 로그인 구성 이름
LTPA 토큰 system.wss.generate.ltpa
LTPA 전파 토큰 system.wss.generate.ltpaProp
X.509 토큰 system.wss.generate.x509
X.509 PKI 경로 토큰 system.wss.generate.pkiPath
X.509 PKCS7 토큰 system.wss.generate.pkcs7
참고:
  • 각 JAAS 로그인 토큰 생성기 구성 이름의 경우 각각 토큰 이용자 구성 이름이 있습니다. 예를 들어, 사용자 이름 토큰의 경우 각 토큰 이용자 구성 이름은 system.wss.consume.unt입니다.
  • LTPA 및 LTPA 전파 토큰은 서버 기반 클라이언트로서 실행 중인 요청자에서만 사용 가능합니다. LTPA 및 LTPA 전파 토큰은 Java™ SE 6 또는 Java EE 애플리케이션 클라이언트에 대해 지원되지 않습니다.

프로시저

  1. securityToken 패키지 com.ibm.websphere.wssecurity.wssapi.token을 구성하려면 먼저 애플리케이션 서버가 설치되어 있는지 확인하십시오.
  2. 웹 서비스 보안 토큰 생성기 프로세스를 사용하여 토큰을 구성하십시오. 각 토큰 유형마다 프로세스는 UsernameToken 토큰 생성기 프로세스를 표시하는 다음 프로세스와 유사합니다.
    1. WSSFactory.getInstance()를 사용하여 WSS API 구현 인스턴스를 가져오십시오.
    2. WSSFactory 인스턴스로부터 WSSGenerationContext 인스턴스를 작성하십시오.
    3. JAAS CallbackHandler를 작성하십시오. 사용자 이름 및 비밀번호와 같은 인증 데이터는 CallbackHandler의 일부로 지정됩니다. 예를 들어, 다음 코드는 Chris를 사용자 이름으로 지정하고 sirhC를 비밀번호로 지정합니다. UNTGenerationCallbackHandler("Chris", "sirhC");
    4. 임의의 JAAS CallbackHandler 매개변수를 호출하고 매개변수가 필수 또는 선택인 토큰 클래스 정보를 검토하십시오. 예를 들어, UsernameToken의 경우 다음 매개변수를 구성할 수도 있습니다.
      난스(nonce)
      난스(nonce)가 토큰 생성기의 사용자 이름 토큰에 포함되어 있는지 여부를 표시합니다. 난스(nonce)는 고유한 암호화 번호로, 이는 사용자 이름 토큰의 반복적인 무단 공격을 중지하는 데 도움이 되도록 메시지에 포함됩니다. 난스(nonce) 값은 생성된 토큰 유형이 UsernameToken인 경우와 요청 생성기 바인딩에 적용될 때에만 유효합니다.
      작성된 시간소인
      시간소인을 UsernameToken에 삽입할지 여부를 표시합니다. 시간소인 값은 생성된 토큰 유형이 UsernameToken인 경우와 요청 생성기 바인딩에 적용될 때에만 유효합니다.
    5. WSSFactory에서 SecurityToken을 작성하십시오.

      기본적으로 UsernameToken API는 ValueType을 다음과 같이 지정합니다. "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken"

      기본적으로 UsernameToken API는 이 클래스의 QName을 제공하고 NamespaceURI를 http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd로 지정하며 LocalPart를 UsernameToken으로 지정합니다.

    6. 옵션: JAAS 로그인 모듈 구성 이름을 지정하십시오. 생성기 측에서 구성 유형은 항상 generate(예: system.wss.generate.unt)입니다.
    7. WSSGenerationContext에 SecurityToken을 추가하십시오.
    8. WSSGenerationContext.process()를 호출하고 WS-Security 헤더를 생성하십시오.

결과

오류 조건이 있는 경우 WSSException이 제공됩니다. 성공할 경우 WSSGenerationContext process()가 호출되고 생성기 바인딩의 보안 토큰이 첨부됩니다.

다음 예제 코드는 WSS API를 사용하여 Username 보안 토큰을 작성하고 Username 토큰을 SOAP 메시지에 첨부하고 생성기 바인딩에서 Username 토큰을 구성하는 방법을 보여줍니다.

// import the packages
import javax.xml.ws.BindingProvider;
import com.ibm.websphere.wssecurity.wssapi.*;
import com.ibm.websphere.wssecurity.callbackhandler.*;
...
   // obtain the binding provider
   BindingProvider bp = ... ;

   // get the request context
   Map<String, Object> reqContext = bp.getRequestContext();

   // generate WSSFactory instance
   WSSFactory factory = WSSFactory.getInstance();

   // generate WSSGenerationContext instance
   WSSGenerationContext gencont = factory.newWSSGenerationContext();

   // generate callback handler
   UNTGenerateCallbackHandler untCallbackHandler = 
   new UNTGenerateCallbackHandler("Chris", "sirhC");

   // generate the username token 
   SecurityToken unt = factory.newSecurityToken(UsernameToken.class, untCallbackHandler);

   // add the SecurityToken to the WSSGenerationContext
   gencont.add(unt);

   // generate the WS-Security header
   gencont.process(reqContext);
다음 예제 코드는 앞의 Username 토큰 샘플을 수정하여 현재 스레드의 runAs ID로부터 LTPAv2 토큰을 작성하는 방법을 보여줍니다. 콜백 핸들러를 인스턴스화하고 보안 토큰을 작성하는 두 코드 행이 다음 두 코드 행으로 대체됩니다.
// generate callback handler
LTPAGenerateCallbackHandler ltpaCallbackHandler = new LTPAGenerateCallbackHandler(null, null);

// generate the LTPAv2 token 
SecurityToken ltpa = wssfactory.newSecurityToken(LTPAv2Token.class, ltpaCallbackHandler);

(null, null)을 갖는 LTPAGenerateCallbackHandler 오브젝트의 인스턴스화는 LTPA 토큰이 현재 runAs ID로부터 생성되어야 함을 표시합니다. 콜백 핸들러가 basicAuth 정보인 ("userName", "password")를 사용하여 인스턴스화되는 경우 새 LTPA 토큰이 지정된 basicAuth 정보를 사용하여 작성됩니다.

다음 예에서는 WSS API가 포함된 보안 대화를 사용하여 생성기 토큰 및 이용자 토큰을 구성하는 방법을 보여줍니다. 이 예에서 SecurityContextToken 토큰은 WS-SecureConversation 드래프트 네임스페이스 http://schemas.xmlsoap.org/ws/2005/02/sc/sct를 사용하여 작성됩니다. WS-SecureConversation 버전 1.3 네임스페이스 http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512/sct를 사용하려면 SecurityContextToken.class 대신 SecurityContextToken13.class를 지정하십시오.
// import the packages
import javax.xml.ws.BindingProvider;
import com.ibm.websphere.wssecurity.wssapi.*;
import com.ibm.websphere.wssecurity.callbackhandler.*;
...
   // obtain the binding provider
   BindingProvider bp = ... ;

   // get the request context
   Map<String, Object> reqContext = bp.getRequestContext();

   // generate WSSFactory instance
   WSSFactory wssFactory = WSSFactory.getInstance();

   WSSGenerationContext bootstrapGenCon = wssFactory.newWSSGenerationContext();

   // Create a Timestamp
   ...
   // Add Timestamp
   ...

   // Sign the SOAP Body, WS-Addressing headers, and Timestamp
   X509GenerateCallbackHandler btspReqSigCbHandler = new X509GenerateCallbackHandler(...);
   SecurityToken btspReqSigToken = wssFactory.newSecurityToken(X509Token.class,
                                                               btspReqSigCbHandler);
   WSSSignature bootstrapReqSig = wssFactory.newWSSSignature(btspReqSigToken);
   bootstrapReqSig.setCanonicalizationMethod(WSSSignature.EXC_C14N);

   // Add Sign Parts
   ...
   bootstrapGenCon.add(bootstrapReqSig);

   // Encrypt the SOAP Body and the Signature
   X509GenerateCallbackHandler btspReqEncCbHandler = new X509GenerateCallbackHandler(...);
   SecurityToken btspReqEncToken = wssFactory.newSecurityToken(X509Token.class,
                                                               btspReqEncCbHandler);
   WSSEncryption bootstrapReqEnc = wssFactory.newWSSEncryption(btspReqEncToken);
   bootstrapReqEnc.setEncryptionMethod(WSSEncryption.AES128);
   bootstrapReqEnc.setKeyEncryptionMethod(WSSEncryption.KW_RSA15);

   // Add Encryption parts
   ...
   bootstrapGenCon.add(bootstrapReqEnc);
   WSSConsumingContext bootstrapConCon = wssFactory.newWSSConsumingContext();
   X509ConsumeCallbackHandler btspRspVfyCbHandler = new X509ConsumeCallbackHandler(....);
   WSSVerification bootstrapRspVfy = wssFactory.newWSSVerification(X509Token.class,
                                                                   btspRspVfyCbHandler);
   bootstrapRspVfy.addAllowedCanonicalizationMethod(WSSVerification.EXC_C14N);

   // Add Verify parts
   ...
   bootstrapConCon.add(bootstrapRspVfy);
   X509ConsumeCallbackHandler btspRspDecCbHandler = new X509ConsumeCallbackHandler(...);
   WSSDecryption bootstrapRspDec = wssFactory.newWSSDecryption(X509Token.class,
                                                               btspRspDecCbHandler);
   bootstrapRspDec.addAllowedEncryptionMethod(WSSDecryption.AES128);
   bootstrapRspDec.addAllowedKeyEncryptionMethod(WSSDecryption.KW_RSA15);

   // Add Decryption parts
   ...
   bootstrapConCon.add(bootstrapRspDec);
   SCTGenerateCallbackHandler sctgch = new SCTGenerateCallbackHandler(bootstrapGenCon,
                                                                      bootstrapConCon,
                                                                      ENDPOINT_URL,
                                                                      WSSEncryption.AES128);
   SecurityToken[] scts = wssFactory.newSecurityTokens(new Class[]{SecurityContextToken.class},
                                                       sctgch);
   SecurityContextToken sct = (SecurityContextToken)scts[0];

   // Use the SCT to generate DKTs for Secure Conversation
   // Signature algorithm and client and service labels
   DerivedKeyToken dktSig = sct.getDerivedKeyToken(WSSSignature.HMAC_SHA1,
                                                   "WS-SecureConversation",
                                                   "WS-SecureConversation");

   // Encryption algorithm and client and service labels
   DerivedKeyToken dktEnc = sct.getDerivedKeyToken(WSSEncryption.AES128,
                                                   "WS-SecureConversation",
                                                   "WS-SecureConversation");

   // Create the application generation context for the request message
   WSSGenerationContext applicationGenCon = wssFactory.newWSSGenerationContext();

   // Create and add Timestamp
   ...

   // Add the derived key token and Sign the SOAP Body and WS-Addressing headers
   WSSSignature appReqSig = wssFactory.newWSSSignature(dktSig);
   appReqSig.setSignatureMethod(WSSSignature.HMAC_SHA1);
   appReqSig.setCanonicalizationMethod(WSSSignature.EXC_C14N);
   ...
   applicationGenCon.add(appReqSig);

   // Add the derived key token and Encrypt the SOAP Body and the Signature
   WSSEncryption appReqEnc = wssFactory.newWSSEncryption(dktEnc);
   appReqEnc.setEncryptionMethod(WSSEncryption.AES128);
   appReqEnc.setTokenReference(SecurityToken.REF_STR);
   appReqEnc.encryptKey(false);
   ...
   applicationGenCon.add(appReqEnc);

   // Create the application consuming context for the response message
   WSSConsumingContext applicationConCon = wssFactory.newWSSConsumingContext();

   //client and service labels and decryption algorithm
   SCTConsumeCallbackHandler sctCbHandler = new SCTConsumeCallbackHandler("WS-SecureConversation",
                                                                          "WS-SecureConversation",
                                                                          WSSDecryption.AES128);

   // Derive the token from SCT and use it to Decrypt the SOAP Body and the Signature
   WSSDecryption appRspDec = wssFactory.newWSSDecryption(SecurityContextToken.class,
                                                         sctCbHandler);
   appRspDec.addAllowedEncryptionMethod(WSSDecryption.AES128);
   appRspDec.encryptKey(false);
   ...
   applicationConCon.add(appRspDec);

   // Derive the token from SCT and use it to Verify the
   // signature on the SOAP Body, WS-Addressing headers, and Timestamp
   WSSVerification appRspVfy = wssFactory.newWSSVerification(SecurityContextToken.class,
                                                             sctCbHandler);
   ...
   applicationConCon.add(appRspVfy);
   ...
   applicationGenCon.process(reqContext);
   applicationConCon.process(reqContext);

다음에 수행할 작업

각 토큰 유형에 대해 WSS API 또는 관리 콘솔을 사용하여 토큰을 구성하십시오. 그런 다음 아직 지정하지 않은 경우 유사한 이용자 토큰을 지정하십시오.

생성기 및 이용자 토큰이 모두 구성된 경우에는 필요에 따라 SOAP 메시지에 서명하거나 메시지를 암호화하여 계속해서 SOAP 메시지를 보안 설정하십시오. WSS API 또는 관리 콘솔을 사용하여 SOAP 메시지를 보안 설정할 수 있습니다.


주제 유형을 표시하는 아이콘 태스크 주제



시간소인 아이콘 마지막 업데이트 날짜: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_confwssgeneratortoken
파일 이름:twbs_confwssgeneratortoken.html