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 확인 이름의 기본값을 제공합니다. 기본 토큰 동작은 다음과 같습니다.
생성기 토큰 결정 | 기본 동작 |
---|---|
사용할 토큰 유형 | 토큰 유형은 메시지 무결성, 메시지 기밀성 또는 메시지 확실성을 위해 사용할 토큰 유형을 지정합니다. WebSphere Application Server는 메시지 무결성 및 메시지 기밀성을 위해 다음 사전 구성된 생성기 토큰 유형을 제공합니다.
WebSphere Application Server는 메시지 확실성을 위해 다음 사전 구성된 생성기 토큰 유형을 제공합니다.
필요에 따라 사용자 정의 토큰 유형을 작성할 수도 있습니다. |
지정할 JAAS 로그인 구성 이름 | JAAS 로그인 구성 이름은 사용할 JAAS 로그인 확인 이름을 지정합니다. |
사용할 구성 유형 | JAAS 로그인 모듈은 구성 유형을 지정합니다. 사전 구성된 생성기 구성 유형만 생성기 토큰 유형에 사용할 수 있습니다. |
SecurityToken 클래스(com.ibm.websphere.wssecurity.wssapi.token.SecurityToken)는 일반 토큰 클래스이며 ID, XML 형식 및 암호 키를 얻기 위한 메소드가 있는 보안 토큰을 표시합니다. SecurityToken 클래스를 사용하면 SOAP 메시지에 서명 및 암호화를 모두 적용할 수 있습니다. 그러나 이 둘 모두를 적용하기 위해서는 서명과 암호화용으로 두 개의 SecurityToken 오브젝트가 있어야 합니다.
다음 토큰 유형은 일반 보안 토큰 클래스의 서브클래스입니다.
토큰 유형 | JAAS 로그인 구성 이름 |
---|---|
Username 토큰 | system.wss.generate.unt |
보안 컨텍스트 토큰 | system.wss.generate.sct |
파생 키 토큰 | system.wss.generate.dkt |
다음 토큰 유형은 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 애플리케이션 클라이언트에 대해 지원되지 않습니다.
프로시저
결과
예
다음 예제 코드는 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);
// 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 정보를 사용하여 작성됩니다.
// 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 메시지를 보안 설정할 수 있습니다.