Package com.sun.xml.wss.impl

Examples of com.sun.xml.wss.impl.SecurityTokenException


        String valueType = getAttribute("ValueType");

        // BSP:3031: ValueType MUST always be specified
        if (isBSP && valueType.length()<1) {
            log.log(Level.SEVERE, "BSP3031.ValueType.NotPresent");
            throw new SecurityTokenException("Any wsse:BinarySecurityToken in a SECURE_ENVELOPE MUST have an ValueType attribute.");
        }
        
        if (!"".equals(valueType)) {       
            setValueType(valueType);
        }
       
        if (isBSP) {
            String encoding = getAttribute("EncodingType");

            // BSP:R3029: encodingType MUST be specified.               
            if (encodingType.length()<1) {
                log.log(Level.SEVERE, "BSP3029.EncodingType.NotPresent");
                throw new SecurityTokenException("Any wsse:BinarySecurityToken in a SECURE_ENVELOPE MUST have an EncodingType attribute.");
            }

            if (!encodingType.equalsIgnoreCase(MessageConstants.BASE64_ENCODING_NS))
            {
                log.log(Level.SEVERE, "BSP3030.EncodingType.Invalid");
                throw new SecurityTokenException("EncodingType attribute value in wsse:BinarySecurityToken is invalid.");           
            }
           
            if (!"".equals(encoding)) {
                setEncodingType(encoding);
            }               
View Full Code Here


    public byte[] getRawValue() throws SecurityTokenException {
        try {
            return Base64.decode(encodedText);
        } catch (Base64DecodingException bde) {
            log.log(Level.SEVERE, "WSS0344.error.decoding.bst")
            throw new SecurityTokenException(bde);
        }
    }
View Full Code Here

           
            addTextNode(getTextValue());
           
        } catch (Exception e) {           
            log.log(Level.SEVERE,"WSS0343.error.creating.bst", e.getMessage());           
            throw new SecurityTokenException(
                "There was an error in creating the BinarySecurityToken "  +
                e.getMessage());
        }
        return delegateElement;       
    }
View Full Code Here

        if (setCreatedTimestamp) {
            try {
                this.created = getCreatedFromTimestamp();
            } catch (Exception e) {
                log.log(Level.SEVERE, "WSS0280.failed.create.UsernameToken", e);
                throw new SecurityTokenException(e);
            }
        }       
    }
View Full Code Here

            log.log(
            Level.SEVERE,
            "WSS0329.usernametoken.expected",
            new Object[] {getLocalName()});
           
            throw new SecurityTokenException(
            "Expected UsernameToken Element, but Found " + getLocalName());
        }
       
        boolean invalidToken = false;
       
        Iterator children = getChildElements();
       
        // Check that the first child element is a Username
       
        Node object = null;
        while (children.hasNext() && !(object instanceof SOAPElement)) {
            object = (Node)children.next();
        }

        if ((object != null) && (object.getNodeType() == Node.ELEMENT_NODE)) {
            SOAPElement element = (SOAPElement) object;
            if ("Username".equals(element.getLocalName()) &&
            XMLUtil.inWsseNS(element)) {
                username = element.getValue();
            } else {
                log.log(Level.SEVERE,"WSS0330.usernametoken.firstchild.mustbe.username");
                throw new SecurityTokenException("The first child of a UsernameToken Element, should be"
                + " a Username ");
            }
        } else {
            invalidToken = true;
        }
       
        while (children.hasNext()) {
           
            object = (Node)children.next();

            if (object.getNodeType() == Node.ELEMENT_NODE) {

                SOAPElement element = (SOAPElement) object;
                if ("Password".equals(element.getLocalName()) &&
                XMLUtil.inWsseNS(element)) {
                    String passwordType = element.getAttribute("Type");
                   
                    if (isBSP() && passwordType.length() < 1) {
                        // Type should be specified
                        log.log(Level.SEVERE,"BSP4201.PasswordType.Username");
                        throw new XWSSecurityException(" A wsse:UsernameToken/wsse:Password element in a SECURITY_HEADER MUST specify a Type attribute.");
                    }
                   
                    if (!"".equals(passwordType))                       
                        setPasswordType(passwordType);
                   
                    if (MessageConstants.PASSWORD_TEXT_NS == this.passwordType)
                        password = element.getValue();
                    else
                        passwordDigest = element.getValue();
                }
                else if ("Nonce".equals(element.getLocalName()) && XMLUtil.inWsseNS(element)) {
                    nonce = element.getValue();
                    String encodingType =
                    element.getAttribute("EncodingType");
                    if (!"".equals(encodingType))
                        setNonceEncodingType(encodingType);
                    try {
                        decodedNonce = Base64.decode(nonce);
                    } catch (Base64DecodingException bde) {
                        log.log(Level.SEVERE, "WSS0309.couldnot.decode.base64.nonce", bde);
                        throw new XWSSecurityException(bde);
                    }
                }
                else if ("Created".equals(element.getLocalName()) &&
                XMLUtil.inWsuNS(element)) {
                    created = element.getValue();
                } else {
                    invalidToken = true;
                }
            }
        }
       
        if (invalidToken) {
            log.log(Level.SEVERE, "WSS0331.invalid.usernametoken");
            throw new SecurityTokenException(
            "Element passed was not a SOAPElement or"
            + " is not a proper UsernameToken");
        }
       
        if (null == username) {
            log.log(Level.SEVERE, "WSS0332.usernametoken.null.username");
            throw new SecurityTokenException(
            "Username token does not contain the username");
        }
    }
View Full Code Here

        } else {
            log.log(Level.SEVERE, "WSS0306.invalid.passwd.type",
            new Object[] {
                MessageConstants.PASSWORD_TEXT_NS,
                MessageConstants.PASSWORD_DIGEST_NS});
                throw new SecurityTokenException(
                "Invalid password type. Must be one of   " +
                MessageConstants.PASSWORD_TEXT_NS + " or " +
                MessageConstants.PASSWORD_DIGEST_NS);
        }
    }
View Full Code Here

            MessageConstants.WSSE_PREFIX,
            MessageConstants.WSSE_NS);
           
            if (null == username || MessageConstants._EMPTY.equals(username) ) {
                log.log(Level.SEVERE, "WSS0387.error.creating.usernametoken");
                throw new SecurityTokenException("username was not set");
            } else {
                addChildElement("Username", MessageConstants.WSSE_PREFIX)
                .addTextNode(username);
            }
           
            if (password != null && !MessageConstants._EMPTY.equals(password) ) {
                SOAPElement wssePassword =
                addChildElement("Password", MessageConstants.WSSE_PREFIX);
               
                if (MessageConstants.PASSWORD_DIGEST_NS == passwordType) {
                    createDigest();
                    wssePassword.addTextNode(passwordDigest);
                } else {
                    wssePassword.addTextNode(password);
                }
                wssePassword.setAttribute("Type", passwordType);
            }
           
            if (nonce != null) {
                SOAPElement wsseNonce =
                addChildElement("Nonce", MessageConstants.WSSE_PREFIX);
                wsseNonce.addTextNode(nonce);
               
                if (nonceEncodingType != null) {
                    wsseNonce.setAttribute("EncodingType", nonceEncodingType);
                }
            }
           
            if (created != null) {
                SOAPElement wsuCreated =
                addChildElement(
                "Created",
                MessageConstants.WSU_PREFIX,
                MessageConstants.WSU_NS);
                wsuCreated.addTextNode(created);
            }
           
        } catch (SOAPException se) {
            log.log(Level.SEVERE, "WSS0388.error.creating.usernametoken", se.getMessage());
            throw new SecurityTokenException(
            "There was an error creating Username Token " +
            se.getMessage());
        }
        return delegateElement;
    }
View Full Code Here

        byte[] utf8Bytes;
        try {
            utf8Bytes = utf8String.getBytes("utf-8");
        } catch (UnsupportedEncodingException uee) {
            log.log(Level.SEVERE, "WSS0390.unsupported.charset.exception");
            throw new SecurityTokenException(uee);
        }
       
        byte[] bytesToHash;
        if (decodedNonce != null) {
            bytesToHash = new byte[utf8Bytes.length + 18];
            for (int i = 0; i < 18; i++)
                bytesToHash[i] = decodedNonce[i];
            for (int i = 18; i < utf8Bytes.length + 18; i++)
                bytesToHash[i] = utf8Bytes[i - 18];
        } else {
            bytesToHash = utf8Bytes;
        }
       
        byte[] hash;
        try {
            MessageDigest sha = MessageDigest.getInstance("SHA-1");
            hash = sha.digest(bytesToHash);
        } catch (Exception e) {
            log.log(Level.SEVERE, "WSS0311.passwd.digest.couldnot.be.created",
            new Object[] {e.getMessage()});
            throw new SecurityTokenException(
            "Password Digest could not be created. " + e.getMessage());
        }
        this.passwordDigest = Base64.encode(hash);
    }
View Full Code Here

       
        this.contextDocument = getOwnerDocument();
       
        if (!("DerivedKeyToken".equals(getLocalName()) &&
                XMLUtil.inWsscNS(this))) {
            throw new SecurityTokenException(
                    "Expected DerivedKeyToken Element, but Found " + getPrefix() + ":" + getLocalName());
        }
       
        boolean invalidToken = false;
       
View Full Code Here

            addNamespaceDeclaration(
                    MessageConstants.WSSC_PREFIX,
                    MessageConstants.WSSC_NS);

            if ( securityTokenRefElement == null )  {
                throw new SecurityTokenException("securitytokenreference was not set");
            } else {
                SOAPElement elem = securityTokenRefElement.getAsSoapElement();
                delegateElement.appendChild(elem);
            }
            if (generation == -1) {
                addChildElement("Offset", MessageConstants.WSSC_PREFIX).addTextNode(String.valueOf(offset));
                addChildElement("Length", MessageConstants.WSSC_PREFIX).addTextNode(String.valueOf(length));
            } else {
                addChildElement("Generation", MessageConstants.WSSC_PREFIX).addTextNode(String.valueOf(generation));
                addChildElement("Length", MessageConstants.WSSC_PREFIX).addTextNode(String.valueOf(length));
            }
            if (this.label != null) {
                addChildElement("Label", MessageConstants.WSSC_PREFIX).addTextNode(this.label);
            }
            if ( nonce != null ) {
                addChildElement("Nonce", MessageConstants.WSSC_PREFIX).addTextNode(nonce);
            }
           
            if (wsuId != null) {
                setWsuIdAttr(this, wsuId);
            }
           
        } catch (SOAPException se) {
            throw new SecurityTokenException(
                    "There was an error creating DerivedKey Token " +
                    se.getMessage());
        }
       
        return super.getAsSoapElement();
View Full Code Here

TOP

Related Classes of com.sun.xml.wss.impl.SecurityTokenException

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.