GenericSecurityTokenFactory SPI を使用して Web サービス・セキュリティーのカスタム・セキュリティー・トークンを作成する
GenericSecurityTokenFactory SPI を使用して、WS-Security ランタイムで使用される カスタム・セキュリティー・トークンを作成します。これらのセキュリティー・トークンは WSSAPI、JAAS ログイン・モジュール、および カスタム・セキュリティー・トークンに使用できますが、使用できるのはこれらに限定されません。
このタスクについて
GenericSecurityTokenFactory では、GenericIssuedTokenGenerateLoginModule で発行できるカスタム・トークンを作成するいくつかの SPI が提供されます。
GenericSecurityTokenFactory で作成されるカスタム・セキュリティー・トークンは、
WS-Security ランタイムによる発行が可能な完全形式のセキュリティー・トークンです。
これらの SPI を使用して作成するトークンには、writeExternal や readExternalなどのエミッターまたはレシーバーを記述する必要はありません。
必要なのは、以下の 2 つの情報のみです。
- トークン・エレメント。Axiom または w3c.dom 実装のどちらかです。
- 値のタイプ
以下の手順では、UsernameToken というカスタム・トークンを作成します。 作成するカスタム・トークンとしてこのトークンを選んだのは、既知のフォームであり、 エレメントやサブエレメント、属性が適切に混じり合っているからです。 独自のカスタム・トークンの作成に必要なメソッドを決めるには、UsernameToken の XML を 参照し、その XML を以下のいずれかの手順に含まれるメソッドの実行内容と突き合わせます。
手順
- ストリングからカスタム・トークンを作成します。
import javax.xml.namespace.QName; import com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory; import com.ibm.websphere.wssecurity.wssapi.token.SecurityToken; //Create a UsernameToken SecurityToken from a String final String untString="<sec:UsernameToken utl:ID=\"_unt999\" xmlns:sec=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"xmlns:utl=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"+ "<sec:Username>myUsername</sec:Username>"+ "<sec:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">myPassword</sec:Password>"+ "</sec:UsernameToken>"; GenericSecurityTokenFactory gst = GenericSecurityTokenFactory.getInstance(); QName valueType = new QName("", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken"); SecurityToken unt = gst.getToken(untString,valueType); //Create a custom SecurityToken from a String final String customString="<acme:MyToken xmlns:acme=\"http://www.acme.com\""+ "xmlns:utl=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" utl:Id=\"cust_3\">"+ "<acme:Email>joe.smith@acme.com</acme:Email>"+ "</acme:MyToken>"; QName custValueType = new QName("http://www.acme.com","MyToken"); SecurityToken custSt = gst.getToken(customString, custValueType);
- w3c.dom エレメントからカスタム・トークンを作成します。
import javax.xml.soap.SOAPElement; import com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory; import com.ibm.websphere.wssecurity.wssapi.token.SecurityToken; import javax.xml.namespace.QName; ... GenericSecurityTokenFactory gstFactory = GenericSecurityTokenFactory.getInstance(); SOAPElement untElement = getDomUntElement("myUsername", "myPassword", gstFactory.createUniqueId()); QName valueType = new QName("", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken"); SecurityToken unt = gstFactory.getToken(untElement, valueType);
- Axiom エレメントからカスタム・トークンを作成します。
import org.apache.axiom.om.OMElement; import com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory; import com.ibm.websphere.wssecurity.wssapi.token.SecurityToken; import javax.xml.namespace.QName; ... GenericSecurityTokenFactory gstFactory = GenericSecurityTokenFactory.getInstance(); OMElement untElement = getAxiomUntElement("myUsername", "myPassword", gstFactory.createUniqueId()); QName valueType = new QName("", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken"); SecurityToken unt = gstFactory.getToken(untElement, valueType);
- w3c.dom カスタム・トークン・エレメントを作成します。
import javax.xml.soap.SOAPFactory; import javax.xml.soap.SOAPElement; SOAPElement getDomUntElement(String username, String password, String uniqueId) { SOAPFactory factory = SOAPFactory.newInstance(); //Create the UsernameToken element SOAPElement untElement = factory.createElement("UsernameToken", "sec", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); untElement.addAttribute(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Id", "utl"), uniqueId); //Create the Username element SOAPElement unameElement = factory.createElement("Username", "sec", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); unameElement.addTextNode(username); //Add the Username element to the UsernameToken untElement.addChildElement(unameElement); if (password != null) { //Create the Password element SOAPElement passElement = factory.createElement("Password", "sec", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); passElement.addAttribute(new QName("Type"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"); passElement.addTextNode(password); //Add the Password element to the UsernameToken untElement.addChildElement(passElement); } return untElement; }
- Axiom カスタム・トークン・エレメントを作成します。
import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMNamespace; OMElement getAxiomUntElement(String username, String password, String uniqueId) { OMFactory factory = OMAbstractFactory.getOMFactory(); //Create the UsernameToken element OMElement untElement = factory.createOMElement("UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "sec"); OMNamespace idNs = factory.createOMNamespace("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "utl"); untElement.addAttribute("Id", uniqueId, idNs); //Create the Username element OMElement unameElement = factory.createOMElement("Username", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "sec"); unameElement.setText(username); //Add the Username element to the UsernameToken untElement.addChild(unameElement); if (password != null) { //Create the Password element OMElement passElement = factory.createOMElement("Password", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "sec"); passElement.addAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText", null); passElement.setText(password); //Add the Password element to the UsernameToken untElement.addChild(passElement); } return untElement; }


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_createcustomtokens
ファイル名:twbs_createcustomtokens.html