Package org.apache.cxf.ws.security.sts.provider

Examples of org.apache.cxf.ws.security.sts.provider.STSException


                if (!STSConstants.COMPUTED_KEY_PSHA1.equals(computedKeyAlgorithm)) {
                    LOG.log(
                        Level.WARNING,
                        "The computed key algorithm of " + computedKeyAlgorithm + " is not supported"
                    );
                    throw new STSException(
                        "Computed Key Algorithm not supported", STSException.INVALID_REQUEST
                    );
                }
            } else if (STSConstants.SYMMETRIC_KEY_TYPE.equals(binarySecret.getBinarySecretType())
                || binarySecret.getBinarySecretType() == null) {
                byte[] secretValue = binarySecret.getBinarySecretValue();
                if ((secretValue.length * 8) < signatureProperties.getMinimumKeySize()
                    || (secretValue.length * 8) > signatureProperties.getMaximumKeySize()) {
                    LOG.log(
                        Level.WARNING, "Received secret of length " + secret.length
                        + " bits is not accepted"
                    );
                    LOG.log(Level.WARNING, "User Entropy rejected");
                    clientEntropy = null;
                }
            } else {
                LOG.log(
                    Level.WARNING, "The type " + binarySecret.getBinarySecretType() + " is not supported"
                );
                throw new STSException(
                    "No user supplied entropy for SymmetricKey case", STSException.INVALID_REQUEST
                );
            }
        } else if (clientEntropy.getDecryptedKey() != null) {
            byte[] secretValue = clientEntropy.getDecryptedKey();
            if ((secretValue.length * 8) < signatureProperties.getMinimumKeySize()
                || (secretValue.length * 8) > signatureProperties.getMaximumKeySize()) {
                LOG.log(
                    Level.WARNING, "Received secret of length " + secret.length
                    + " bits is not accepted"
                );
                LOG.log(Level.WARNING, "User Entropy rejected");
                clientEntropy = null;
            }
        } else {
            LOG.log(Level.WARNING, "The user supplied Entropy structure is invalid");
            throw new STSException(
                "The user supplied Entropy structure is invalid", STSException.INVALID_REQUEST
            );
        }
    }
View Full Code Here


            try {
                entropyBytes = WSSecurityUtil.generateNonce(keySize / 8);
                secret = entropyBytes;
            } catch (WSSecurityException ex) {
                LOG.log(Level.WARNING, "", ex);
                throw new STSException("Error in creating symmetric key", ex, STSException.INVALID_REQUEST);
            }
            if (clientEntropy != null && clientEntropy.getBinarySecret() != null) {
                byte[] nonce = clientEntropy.getBinarySecret().getBinarySecretValue();
                try {
                    P_SHA1 psha1 = new P_SHA1();
                    secret = psha1.createKey(nonce, entropyBytes, 0, keySize / 8);
                    computedKey = true;
                } catch (ConversationException ex) {
                    LOG.log(Level.WARNING, "", ex);
                    throw new STSException("Error in creating symmetric key", STSException.INVALID_REQUEST);
                }
            }
        }
    }
View Full Code Here

            try {
                if (certificate == null) {
                    certificate = getCertificateFromRequest(requestObject);
                }
            } catch (CertificateException e) {
                throw new STSException(
                        "Can't extract X509 certificate from request", e);
            }

            // TokenType
            if (requestObject instanceof JAXBElement) {
                JAXBElement<?> jaxbElement = (JAXBElement<?>) requestObject;
                if (QNAME_WST_TOKEN_TYPE.equals(jaxbElement.getName())) {
                    tokenType = (String) jaxbElement.getValue();
                }
            }
        }
        if (certificate == null) {
            if (context == null || context.getMessageContext() == null) {
                throw new STSException("No message context found");
            }
            //find the username
            MessageContext ctx = context.getMessageContext();
            UsernameToken unt = (UsernameToken)ctx.get(SecurityToken.class.getName());
            if (unt != null) {
                username = unt.getName();
            }
        }

        // check input arguments
        if (certificate != null) { // certificate
            try {
                verifyCertificate(certificate);
            } catch (Exception e) {
                throw new STSException(
                        "Can't verify X509 certificate from request", e);
            }
        }

        // create token
        TokenProvider tokenProvider = null;
        for (TokenProvider tp : tokenProviders) {
            if (tokenType.equals(tp.getTokenType())) {
                tokenProvider = tp;
                break;
            }
        }
        if (tokenProvider == null) {
            throw new STSException(
                    "No token provider found for requested token type: "
                            + tokenType);
        }

        Element elementToken = null;
View Full Code Here

                if (x509CertData != null && x509CertData.getLength() > 0) {
                    try {
                        x509 = Base64Utility.decode(x509CertData.item(0)
                                                    .getTextContent());
                    } catch (Exception e) {
                        throw new STSException(e.getMessage(), e);
                    }
                }
            }
            if (x509 != null) {
                CertificateFactory cf = CertificateFactory.getInstance(X_509);
View Full Code Here

            XMLSignature signature = signFactory.newXMLSignature(si, ki);

            signature.sign(dsc);

        } catch (Exception e) {
            throw new STSException("Cannot sign xml document: "
                    + e.getMessage(), e);
        }
    }
View Full Code Here

                    if (!found) {
                        LOG.log(
                            Level.WARNING,
                            "Found a JAXB object of unknown type: " + jaxbElement.getName()
                        );
                        throw new STSException(
                            "An unknown element was received", STSException.BAD_REQUEST
                        );
                    }
                } catch (STSException ex) {
                    LOG.log(Level.WARNING, "", ex);
                    throw ex;
                } catch (RuntimeException ex) {
                    LOG.log(Level.WARNING, "", ex);
                    throw ex;
                }
            // SecondaryParameters/AppliesTo
            } else if (requestObject instanceof Element) {
                Element element = (Element)requestObject;
                if (STSConstants.WST_NS_05_12.equals(element.getNamespaceURI())
                    && "SecondaryParameters".equals(element.getLocalName())) {
                    parseSecondaryParameters(element, claimsParsers);
                } else if ("AppliesTo".equals(element.getLocalName())
                    && (STSConstants.WSP_NS.equals(element.getNamespaceURI())
                        || STSConstants.WSP_NS_04.equals(element.getNamespaceURI()))) {
                    tokenRequirements.setAppliesTo(element);
                    LOG.fine("Found AppliesTo element");
                } else {
                    LOG.log(
                        Level.WARNING,
                        "An unknown (DOM) element was received: " + element.getLocalName()
                    );
                    throw new STSException(
                        "An unknown element was received", STSException.BAD_REQUEST
                    );
                }
            } else {
                LOG.log(Level.WARNING, "An unknown element was received");
                throw new STSException(
                    "An unknown element was received", STSException.BAD_REQUEST
                );
            }
        }
        String context = request.getContext();
View Full Code Here

                try {
                    x509 = Base64Utility.decode(token.getTextContent().trim());
                    LOG.fine("Found X509Certificate UseKey type via reference");
                } catch (Exception e) {
                    LOG.log(Level.WARNING, "", e);
                    throw new STSException(e.getMessage(), e, STSException.INVALID_REQUEST);
                }
            }
        } else if (useKey.getAny() instanceof Element) {
            if (isTokenReferenced(useKey.getAny())) {
                Element token = fetchTokenElementFromReference(useKey.getAny(), wsContext);
                try {
                    x509 = Base64Utility.decode(token.getTextContent().trim());
                    LOG.fine("Found X509Certificate UseKey type via reference");
                } catch (Exception e) {
                    LOG.log(Level.WARNING, "", e);
                    throw new STSException(e.getMessage(), e, STSException.INVALID_REQUEST);
                }
            } else {
                Element element = (Element)useKey.getAny();
                if ("KeyInfo".equals(element.getLocalName())) {
                    return parseKeyInfoElement((Element)useKey.getAny());
                } else {
                    NodeList x509CertData =
                        element.getElementsByTagNameNS(
                            Constants.SignatureSpecNS, Constants._TAG_X509CERTIFICATE  
                        );
                    if (x509CertData != null && x509CertData.getLength() > 0) {
                        try {
                            x509 = Base64Utility.decode(x509CertData.item(0).getTextContent().trim());
                            LOG.fine("Found X509Certificate UseKey type");
                        } catch (Exception e) {
                            LOG.log(Level.WARNING, "", e);
                            throw new STSException(e.getMessage(), e, STSException.INVALID_REQUEST);
                        }
                    }
                }
            }
        } else {
            LOG.log(Level.WARNING, "An unknown element was received");
            throw new STSException(
                "An unknown element was received", STSException.BAD_REQUEST
            );
        }
       
        if (x509 != null) {
            try {
                CertificateFactory cf = CertificateFactory.getInstance("X.509");
                X509Certificate cert =
                    (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(x509));
                LOG.fine("Successfully parsed X509 Certificate from UseKey");
                ReceivedKey receivedKey = new ReceivedKey();
                receivedKey.setX509Cert(cert);
                return receivedKey;
            } catch (CertificateException ex) {
                LOG.log(Level.WARNING, "", ex);
                throw new STSException("Error in parsing certificate: ", ex, STSException.INVALID_REQUEST);
            }
        }
        return null;
    }
View Full Code Here

                    }
                }
            }
        } catch (MarshalException e) {
            LOG.log(Level.WARNING, "", e);
            throw new STSException(e.getMessage(), e, STSException.INVALID_REQUEST);
        } catch (KeyException e) {
            LOG.log(Level.WARNING, "", e);
            throw new STSException(e.getMessage(), e, STSException.INVALID_REQUEST);
        }
        return null;
    }
View Full Code Here

                    Entropy entropy = new Entropy();
                    entropy.setDecryptedKey((byte[])results.get(0).get(WSSecurityEngineResult.TAG_SECRET));
                    return entropy;
                } catch (WSSecurityException e) {
                    LOG.log(Level.WARNING, "", e);
                    throw new STSException(e.getMessage(), e, STSException.INVALID_REQUEST);
                }
            } else {
                LOG.log(Level.WARNING, "An unknown element was received");
                throw new STSException(
                    "An unknown element was received", STSException.BAD_REQUEST
                );
            }
        }
        return null;
View Full Code Here

        if (IdentityClaimsParser.IDENTITY_CLAIMS_DIALECT.equals(dialect)) {
            return IdentityClaimsParser.parseClaimType(childClaimType);
        }
       
        LOG.log(Level.WARNING, "No ClaimsParser is registered for dialect " + dialect);
        throw new STSException(
            "No ClaimsParser is registered for dialect " + dialect, STSException.BAD_REQUEST
        );
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.ws.security.sts.provider.STSException

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.