<UsernameToken> エレメントを使用して、ユーザー名を伝搬し、また、オプションでパスワード情報を伝搬できます。 また、このトークン・タイプを使用して、基本認証情報を伝送することもできます。 ユーザー名とパスワードは、ともに SOAP メッセージの認証に使用されます。
ユーザー名を含む UsernameToken は ID アサーションに使用されます。 ID アサーションは、信頼関係に基づいてユーザーの ID を確立します。
以下に、<UsernameToken> エレメントの構文の例を示します。
<wsse:UsernameToken wsu:Id="Example-1"> <wsse:Username> ... </wsse:Username> <wsse:Password Type="..."> ... </wsse:Password> <wsse:Nonce EncodingType="..."> ... </wsse:Nonce> <wsu:Created> ... </wsu:Created> </wsse:UsernameToken>
Web サービス・セキュリティー仕様は、以下のパスワード・タイプを定義します。
WebSphere Application Server は、デフォルトの PasswordText タイプをサポートします。 しかし、パスワードのダイジェストはサポートしません。 これは、ほとんどのユーザー・レジストリー・セキュリティー・ポリシーがアプリケーション・ソフトウェアにパスワードを公開しないためです。
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org /wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <S:Header> ... <wsse:Security> <wsse:UsernameToken> <wsse:Username>Joe</wsse:Username> <wsse:Password>ILoveJava</wsse:Password> </wsse:UsernameToken> </wsse:Security> </S:Header> </S:Envelope>
以下の例では、ユーザー名トークンを作成するサンプル・コードが示されます。
WSSFactory factory = WSSFactory.getInstance(); WSSGenerationContext gencont = factory.newWSSGenerationContext(); // Attach the username token to the message. UNTGenerationCallbackHandler ugCallbackHandler = newUNTGenerationCallbackHandler("alice", "ecila"); SecurityToken ut = factory.newSecurityToken(ugCallbackHandler, UsernameToken.class); gencont.add(ut); // Generate the WS-Security header gencont.process(msgctx);