Package org.apache.ws.security.message.token

Examples of org.apache.ws.security.message.token.BinarySecurity


        WSSConfig.getNewInstance();

        WSSecHeader secHeader = new WSSecHeader();
        secHeader.insertSecurityHeader(doc);
       
        BinarySecurity bst = new BinarySecurity(doc);
        bst.setValueType(AP_REQ);
        bst.setEncodingType(BASE64_NS);
        bst.setToken("12345678".getBytes());
        bst.setID("Id-" + bst.hashCode());
        WSSecurityUtil.prependChildElement(secHeader.getSecurityHeader(), bst.getElement());
       
        WSSecTimestamp timestamp = new WSSecTimestamp();
        timestamp.setTimeToLive(600);
        timestamp.build(doc, secHeader);
       
        WSSecSignature sign = new WSSecSignature();
        sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
        sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
       
        Vector parts = new Vector();
        parts.add(new WSEncryptionPart(bst.getID()));
        parts.add(new WSEncryptionPart(timestamp.getId()));
        sign.setParts(parts);
       
        Document signedDoc = sign.build(doc, crypto, secHeader);
       
View Full Code Here


        byte[] secretKey = null;
        switch (keyIdentifierType) {
            case WSConstants.BST_DIRECT_REFERENCE:
                Reference ref = new Reference(wssConfig, doc);
                ref.setURI("#" + certUri);
                BinarySecurity bstToken = null;
                if (!useSingleCert) {
                    bstToken = new PKIPathSecurity(wssConfig, doc);
                    ((PKIPathSecurity) bstToken).setX509Certificates(certs,
                            false,
                            crypto);
                } else {
                    bstToken = new X509Security(wssConfig, doc);
                    ((X509Security) bstToken).setX509Certificate(certs[0]);
                }
                ref.setValueType(bstToken.getValueType());
                secRef.setReference(ref);
                bstToken.setID(certUri);
                WSSecurityUtil.prependChildElement(doc,
                        securityHeader,
                        bstToken.getElement(),
                        false);
                wsDocInfo.setBst(bstToken.getElement());
                break;

            case WSConstants.ISSUER_SERIAL:
                XMLX509IssuerSerial data =
                        new XMLX509IssuerSerial(doc, certs[0]);
View Full Code Here

        switch (keyIdentifierType) {
        case WSConstants.BST_DIRECT_REFERENCE:
            Reference ref = new Reference(wssConfig, doc);
            if (senderVouches) {
                ref.setURI("#" + certUri);
                BinarySecurity bstToken = null;
                bstToken = new X509Security(wssConfig, doc);
                ((X509Security) bstToken).setX509Certificate(certs[0]);
                bstToken.setID(certUri);
                WSSecurityUtil.prependChildElement(doc, securityHeader,
                        bstToken.getElement(), false);
                wsDocInfo.setBst(bstToken.getElement());
                ref.setValueType(bstToken.getValueType());
            } else {
                ref.setURI("#" + assertion.getId());
                ref.setValueType(WSConstants.WSS_SAML_NS
                        + WSConstants.WSS_SAML_ASSERTION);
            }
View Full Code Here

                break;

            case WSConstants.BST_DIRECT_REFERENCE:
                Reference ref = new Reference(wssConfig, doc);
                ref.setURI("#" + certUri);
                BinarySecurity bstToken = null;
                bstToken = new X509Security(wssConfig, doc);
                ((X509Security) bstToken).setX509Certificate(remoteCert);
                bstToken.setID(certUri);
                ref.setValueType(bstToken.getValueType());
                secToken.setReference(ref);
                WSSecurityUtil.prependChildElement(doc,
                        wsseSecurity,
                        bstToken.getElement(),
                        false);
                break;

            default :
                throw new WSSecurityException(WSSecurityException.FAILURE,
View Full Code Here

                secToken.setX509IssuerSerial(new XMLX509IssuerSerial(doc, remoteCert));
                WSSecurityUtil.setNamespace(secToken.getElement(), WSConstants.WSSE_NS, WSConstants.WSSE_PREFIX);
                break;

            case WSConstants.BST_DIRECT_REFERENCE:
                BinarySecurity bstToken = null;
                bstToken = new X509Security(WSSConfig.getDefaultWSConfig(), doc);
                ((X509Security) bstToken).setX509Certificate(remoteCert);
                bstToken.setID(certUri);
                Reference ref = new Reference(WSSConfig.getDefaultWSConfig(), doc);
                ref.setURI("#" + certUri);
                ref.setValueType(bstToken.getValueType());
                secToken.setReference(ref);
//                WSSecurityUtil.prependChildElement(
//                    doc,
//                    wsseSecurity,
//                    bstToken.getElement(),
View Full Code Here

     *
     * @return
     * @throws WSSecurityException
     */
    public BinarySecurity getBinarySecurityToken() throws WSSecurityException {
        BinarySecurity binarySecToken;

        binarySecToken = null;
        String firstChild = this.element.getFirstChild().getLocalName();

        if ("BinarySecurityToken" == firstChild) {

            binarySecToken =
                    new BinarySecurity(WSSConfig.getDefaultWSConfig(), (Element) this.element.getFirstChild());
            return binarySecToken;
        } else if ("SecurityTokenReference" == firstChild) {

            SecurityTokenReference secTokRef =
                    new SecurityTokenReference(WSSConfig.getDefaultWSConfig(),
                            (Element) this.element.getFirstChild());
            binarySecToken =
                    new BinarySecurity(WSSConfig.getDefaultWSConfig(),
                            secTokRef.getTokenElement(element.getOwnerDocument(),
                                    null));
            return binarySecToken;
        } else {
            throw new WSSecurityException(WSSecurityException.INVALID_SECURITY_TOKEN,
View Full Code Here

            if (el.equals(SecurityTokenReference.SECURITY_TOKEN_REFERENCE))
                this.reference = new SecurityTokenReference(wssConfig, element);
            if (el.equals(UsernameToken.TOKEN))
                this.usernameToken = new UsernameToken(wssConfig, element);
            if (el.equals(BinarySecurity.TOKEN))
                this.binarySecurityToken = new BinarySecurity(wssConfig, element);
            doc = element.getOwnerDocument();
        } catch (WSSecurityException e) {
            throw new ElementParsingException("WSSecurityException while trying to create a SecurityTokenOrReference object from an XML Element: "
                    + e.getMessage());
        }
View Full Code Here

                    try {
                        WSSConfig wssConfig = WSSConfig.getDefaultWSConfig();
                        if (el.equals(UsernameToken.TOKEN))
                            return new UsernameToken(wssConfig, tokenElement);
                        if (el.equals(BinarySecurity.TOKEN))
                            return new BinarySecurity(wssConfig, tokenElement);
                    } catch (WSSecurityException e) {
                        throw new ElementParsingException("WSSecurityException while trying to create a SecurityToken object from a SecurityTokenReference: "
                                + e.getMessage());
                    }
                }
View Full Code Here

     * @param doc
     * @return
     */
    public static BinarySecurity findBinarySecurityToken(Document doc){
    try {
      BinarySecurity binarySecurity;
      //first find base token
      Element elemBase=(Element)WSSecurityUtil.findElement(doc,BaseToken.TOKEN.getLocalPart(),BaseToken.TOKEN.getNamespaceURI());
      Element elemBaseChild=(Element)elemBase.getFirstChild();
      //If the first child is null then return
      if((elemBaseChild==null)){
        return null;
      }
      //If the first child is a binary token
         
      if((elemBaseChild.getLocalName().equals("BinarySecurityToken"))   ){
        binarySecurity=new BinarySecurity(WSSConfig.getDefaultWSConfig(),elemBaseChild);
        return binarySecurity;
      }else if((elemBaseChild.getLocalName().equals(SecurityTokenReference.SECURITY_TOKEN_REFERENCE) )  ){
        return null;
      }else{
          return null;
View Full Code Here

     * @param element The XML element that contains either a <code>BinarySecurityToken
     *                </code> or a <code>PKIPath</code> element.
     * @throws WSSecurityException
     */
    private void createSecurityToken(Element element) throws WSSecurityException {
        this.token = new BinarySecurity(element);
        type = token.getValueType();

        if (X509Security.X509_V3_TYPE.equals(type)) {
            this.token = new X509Security(element);
        } else if (PKIPathSecurity.getType().equals(type)) {
View Full Code Here

TOP

Related Classes of org.apache.ws.security.message.token.BinarySecurity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.