Java源码示例:org.opensaml.xml.Configuration
示例1
/**
* Helper method that marshalls the given message.
*
* @param message message the marshall and serialize
*
* @return marshalled message
*
* @throws MessageEncodingException thrown if the give message can not be marshalled into its DOM representation
*/
protected Element marshallMessage(XMLObject message) throws MessageEncodingException {
log.debug("Marshalling message");
try {
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message);
if (marshaller == null) {
log.error("Unable to marshall message, no marshaller registered for message object: "
+ message.getElementQName());
throw new MessageEncodingException(
"Unable to marshall message, no marshaller registered for message object: "
+ message.getElementQName());
}
Element messageElem = marshaller.marshall(message);
if (log.isTraceEnabled()) {
log.trace("Marshalled message into DOM:\n{}", XMLHelper.nodeToString(messageElem));
}
return messageElem;
} catch (MarshallingException e) {
log.error("Encountered error marshalling message to its DOM representation", e);
throw new MessageEncodingException("Encountered error marshalling message into its DOM representation", e);
}
}
示例2
/**
* Log the decoded message to the protocol message logger.
*
* @param messageContext the message context to process
*/
protected void logDecodedMessage(MessageContext messageContext) {
if(protocolMessageLog.isDebugEnabled() && messageContext.getInboundMessage() != null){
if (messageContext.getInboundMessage().getDOM() == null) {
XMLObject message = messageContext.getInboundMessage();
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message);
if (marshaller != null) {
try {
marshaller.marshall(message);
} catch (MarshallingException e) {
log.error("Unable to marshall message for logging purposes: " + e.getMessage());
}
}
else {
log.error("Unable to marshall message for logging purposes, no marshaller registered for message object: "
+ message.getElementQName());
}
if (message.getDOM() == null) {
return;
}
}
protocolMessageLog.debug("\n" + XMLHelper.prettyPrintXML(messageContext.getInboundMessage().getDOM()));
}
}
示例3
/**
* Creates the request entity that makes up the POST message body.
*
* @param message message to be sent
* @param charset character set used for the message
*
* @return request entity that makes up the POST message body
*
* @throws SOAPClientException thrown if the message could not be marshalled
*/
protected RequestEntity createRequestEntity(Envelope message, Charset charset) throws SOAPClientException {
try {
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message);
ByteArrayOutputStream arrayOut = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(arrayOut, charset);
if (log.isDebugEnabled()) {
log.debug("Outbound SOAP message is:\n" + XMLHelper.prettyPrintXML(marshaller.marshall(message)));
}
XMLHelper.writeNode(marshaller.marshall(message), writer);
return new ByteArrayRequestEntity(arrayOut.toByteArray(), "text/xml");
} catch (MarshallingException e) {
throw new SOAPClientException("Unable to marshall SOAP envelope", e);
}
}
示例4
/**
* Obtains a {@link KeyInfoGenerator} for the specified {@link Credential}.
*
* <p>
* The KeyInfoGenerator returned is based on the {@link NamedKeyInfoGeneratorManager} defined by the specified
* security configuration via {@link SecurityConfiguration#getKeyInfoGeneratorManager()}, and is determined by the
* type of the signing credential and an optional KeyInfo generator manager name. If the latter is ommited, the
* default manager ({@link NamedKeyInfoGeneratorManager#getDefaultManager()}) of the security configuration's
* named generator manager will be used.
* </p>
*
* <p>
* The generator is determined by the specified {@link SecurityConfiguration}. If a security configuration is not
* supplied, the global security configuration ({@link Configuration#getGlobalSecurityConfiguration()}) will be
* used.
* </p>
*
* @param credential the credential for which a generator is desired
* @param config the SecurityConfiguration to use (may be null)
* @param keyInfoGenName the named KeyInfoGeneratorManager configuration to use (may be null)
* @return a KeyInfoGenerator appropriate for the specified credential
*/
public static KeyInfoGenerator getKeyInfoGenerator(Credential credential, SecurityConfiguration config,
String keyInfoGenName) {
SecurityConfiguration secConfig;
if (config != null) {
secConfig = config;
} else {
secConfig = Configuration.getGlobalSecurityConfiguration();
}
NamedKeyInfoGeneratorManager kiMgr = secConfig.getKeyInfoGeneratorManager();
if (kiMgr != null) {
KeyInfoGeneratorFactory kiFactory = null;
if (DatatypeHelper.isEmpty(keyInfoGenName)) {
kiFactory = kiMgr.getDefaultManager().getFactory(credential);
} else {
kiFactory = kiMgr.getFactory(keyInfoGenName, credential);
}
if (kiFactory != null) {
return kiFactory.newInstance();
}
}
return null;
}
示例5
/**
* Build an {@link X509IssuerSerial} containing a given issuer name and serial number.
*
* @param issuerName the name content
* @param serialNumber the serial number content
* @return the new X509IssuerSerial
*/
public static X509IssuerSerial buildX509IssuerSerial(String issuerName, BigInteger serialNumber) {
X509IssuerName xmlIssuerName = (X509IssuerName) Configuration.getBuilderFactory()
.getBuilder(X509IssuerName.DEFAULT_ELEMENT_NAME)
.buildObject(X509IssuerName.DEFAULT_ELEMENT_NAME);
xmlIssuerName.setValue(issuerName);
X509SerialNumber xmlSerialNumber = (X509SerialNumber) Configuration.getBuilderFactory()
.getBuilder(X509SerialNumber.DEFAULT_ELEMENT_NAME)
.buildObject(X509SerialNumber.DEFAULT_ELEMENT_NAME);
xmlSerialNumber.setValue(serialNumber);
X509IssuerSerial xmlIssuerSerial = (X509IssuerSerial) Configuration.getBuilderFactory()
.getBuilder(X509IssuerSerial.DEFAULT_ELEMENT_NAME)
.buildObject(X509IssuerSerial.DEFAULT_ELEMENT_NAME);
xmlIssuerSerial.setX509IssuerName(xmlIssuerName);
xmlIssuerSerial.setX509SerialNumber(xmlSerialNumber);
return xmlIssuerSerial;
}
示例6
/**
* Build an {@link X509Digest} containing the digest of the specified certificate.
*
* @param javaCert the Java X509Certificate to digest
* @param algorithmURI digest algorithm URI
* @return a new X509Digest object
* @throws NoSuchAlgorithmException if the algorithm specified cannot be used
* @throws CertificateEncodingException if the certificate cannot be encoded
*/
public static X509Digest buildX509Digest(X509Certificate javaCert, String algorithmURI)
throws NoSuchAlgorithmException, CertificateEncodingException {
String jceAlg = SecurityHelper.getAlgorithmIDFromURI(algorithmURI);
if (jceAlg == null) {
throw new NoSuchAlgorithmException("No JCE algorithm found for " + algorithmURI);
}
MessageDigest md = MessageDigest.getInstance(jceAlg);
byte[] hash = md.digest(javaCert.getEncoded());
X509Digest xmlDigest = (X509Digest) Configuration.getBuilderFactory()
.getBuilder(X509Digest.DEFAULT_ELEMENT_NAME)
.buildObject(X509Digest.DEFAULT_ELEMENT_NAME);
xmlDigest.setAlgorithm(algorithmURI);
xmlDigest.setValue(Base64.encodeBytes(hash));
return xmlDigest;
}
示例7
/**
* Converts a Java DSA or RSA public key into the corresponding XMLObject and stores it
* in a {@link KeyInfo} in a new {@link KeyValue} element.
*
* As input, only supports {@link PublicKey}s which are instances of either
* {@link java.security.interfaces.DSAPublicKey} or
* {@link java.security.interfaces.RSAPublicKey}
*
* @param keyInfo the {@link KeyInfo} element to which to add the key
* @param pk the native Java {@link PublicKey} to add
* @throws IllegalArgumentException thrown if an unsupported public key
* type is passed
*/
public static void addPublicKey(KeyInfo keyInfo, PublicKey pk) throws IllegalArgumentException {
KeyValue keyValue = (KeyValue) Configuration.getBuilderFactory()
.getBuilder(KeyValue.DEFAULT_ELEMENT_NAME)
.buildObject(KeyValue.DEFAULT_ELEMENT_NAME);
if (pk instanceof RSAPublicKey) {
keyValue.setRSAKeyValue(buildRSAKeyValue((RSAPublicKey) pk));
} else if (pk instanceof DSAPublicKey) {
keyValue.setDSAKeyValue(buildDSAKeyValue((DSAPublicKey) pk));
} else {
throw new IllegalArgumentException("Only RSAPublicKey and DSAPublicKey are supported");
}
keyInfo.getKeyValues().add(keyValue);
}
示例8
/**
* Builds an {@link RSAKeyValue} XMLObject from the Java security RSA public key type.
*
* @param rsaPubKey a native Java {@link RSAPublicKey}
* @return an {@link RSAKeyValue} XMLObject
*/
public static RSAKeyValue buildRSAKeyValue(RSAPublicKey rsaPubKey) {
XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
RSAKeyValue rsaKeyValue = (RSAKeyValue) builderFactory
.getBuilder(RSAKeyValue.DEFAULT_ELEMENT_NAME)
.buildObject(RSAKeyValue.DEFAULT_ELEMENT_NAME);
Modulus modulus = (Modulus) builderFactory
.getBuilder(Modulus.DEFAULT_ELEMENT_NAME)
.buildObject(Modulus.DEFAULT_ELEMENT_NAME);
Exponent exponent = (Exponent) builderFactory
.getBuilder(Exponent.DEFAULT_ELEMENT_NAME)
.buildObject(Exponent.DEFAULT_ELEMENT_NAME);
modulus.setValueBigInt(rsaPubKey.getModulus());
rsaKeyValue.setModulus(modulus);
exponent.setValueBigInt(rsaPubKey.getPublicExponent());
rsaKeyValue.setExponent(exponent);
return rsaKeyValue;
}
示例9
/**
* Builds a {@link DSAKeyValue} XMLObject from the Java security DSA public key type.
*
* @param dsaPubKey a native Java {@link DSAPublicKey}
* @return an {@link DSAKeyValue} XMLObject
*/
public static DSAKeyValue buildDSAKeyValue(DSAPublicKey dsaPubKey) {
XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
DSAKeyValue dsaKeyValue = (DSAKeyValue) builderFactory
.getBuilder(DSAKeyValue.DEFAULT_ELEMENT_NAME)
.buildObject(DSAKeyValue.DEFAULT_ELEMENT_NAME);
Y y = (Y) builderFactory.getBuilder(Y.DEFAULT_ELEMENT_NAME).buildObject(Y.DEFAULT_ELEMENT_NAME);
G g = (G) builderFactory.getBuilder(G.DEFAULT_ELEMENT_NAME).buildObject(G.DEFAULT_ELEMENT_NAME);
P p = (P) builderFactory.getBuilder(P.DEFAULT_ELEMENT_NAME).buildObject(P.DEFAULT_ELEMENT_NAME);
Q q = (Q) builderFactory.getBuilder(Q.DEFAULT_ELEMENT_NAME).buildObject(Q.DEFAULT_ELEMENT_NAME);
y.setValueBigInt(dsaPubKey.getY());
dsaKeyValue.setY(y);
g.setValueBigInt(dsaPubKey.getParams().getG());
dsaKeyValue.setG(g);
p.setValueBigInt(dsaPubKey.getParams().getP());
dsaKeyValue.setP(p);
q.setValueBigInt(dsaPubKey.getParams().getQ());
dsaKeyValue.setQ(q);
return dsaKeyValue;
}
示例10
/**
* Constructor.
*
* @param newResolver resolver for data encryption keys.
* @param newKEKResolver resolver for key encryption keys.
* @param newEncKeyResolver resolver for EncryptedKey elements
*/
public Decrypter(KeyInfoCredentialResolver newResolver, KeyInfoCredentialResolver newKEKResolver,
EncryptedKeyResolver newEncKeyResolver) {
resolver = newResolver;
kekResolver = newKEKResolver;
encKeyResolver = newEncKeyResolver;
resolverCriteria = null;
kekResolverCriteria = null;
// Note: this is hopefully only temporary, until Xerces implements DOM 3 LSParser.parseWithContext().
parserPool = new BasicParserPool();
parserPool.setNamespaceAware(true);
// Note: this is necessary due to an unresolved Xerces deferred DOM issue/bug
HashMap<String, Boolean> features = new HashMap<String, Boolean>();
features.put("http://apache.org/xml/features/dom/defer-node-expansion", Boolean.FALSE);
parserPool.setBuilderFeatures(features);
unmarshallerFactory = Configuration.getUnmarshallerFactory();
defaultRootInNewDocument = false;
}
示例11
/**
* Ensure that the XMLObject is marshalled.
*
* @param xmlObject the object to check and marshall
* @throws DecryptionException thrown if there is an error when marshalling the XMLObject
*/
protected void checkAndMarshall(XMLObject xmlObject) throws DecryptionException {
Element targetElement = xmlObject.getDOM();
if (targetElement == null) {
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject);
if (marshaller == null) {
marshaller =
Configuration.getMarshallerFactory().getMarshaller(Configuration.getDefaultProviderQName());
if (marshaller == null) {
String errorMsg = "No marshaller available for " + xmlObject.getElementQName();
log.error(errorMsg);
throw new DecryptionException(errorMsg);
}
}
try {
targetElement = marshaller.marshall(xmlObject);
} catch (MarshallingException e) {
log.error("Error marshalling target XMLObject", e);
throw new DecryptionException("Error marshalling target XMLObject", e);
}
}
}
示例12
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
EncryptionProperty ep = (EncryptionProperty) xmlObject;
if (ep.getID() != null) {
domElement.setAttributeNS(null, EncryptionProperty.ID_ATTRIB_NAME, ep.getID());
domElement.setIdAttributeNS(null, EncryptionProperty.ID_ATTRIB_NAME, true);
}
if (ep.getTarget() != null) {
domElement.setAttributeNS(null, EncryptionProperty.TARGET_ATTRIB_NAME, ep.getTarget());
}
Attr attribute;
for (Entry<QName, String> entry : ep.getUnknownAttributes().entrySet()) {
attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
attribute.setValue(entry.getValue());
domElement.setAttributeNodeNS(attribute);
if (Configuration.isIDAttribute(entry.getKey()) || ep.getUnknownAttributes().isIDAttribute(entry.getKey())) {
attribute.getOwnerElement().setIdAttributeNode(attribute, true);
}
}
}
示例13
/** {@inheritDoc} */
public String put(QName attributeName, String value) {
String oldValue = get(attributeName);
if (value != oldValue) {
releaseDOM();
attributes.put(attributeName, value);
if (isIDAttribute(attributeName) || Configuration.isIDAttribute(attributeName)) {
attributeOwner.getIDIndex().deregisterIDMapping(oldValue);
attributeOwner.getIDIndex().registerIDMapping(value, attributeOwner);
}
if (!DatatypeHelper.isEmpty(attributeName.getNamespaceURI())) {
if (value == null) {
attributeOwner.getNamespaceManager().deregisterAttributeName(attributeName);
} else {
attributeOwner.getNamespaceManager().registerAttributeName(attributeName);
}
}
checkAndDeregisterQNameValue(attributeName, oldValue);
checkAndRegisterQNameValue(attributeName, value);
}
return oldValue;
}
示例14
/**
* Marshall an XMLObject. If the XMLObject already has a cached DOM via {@link XMLObject#getDOM()},
* that Element will be returned. Otherwise the object will be fully marshalled and that Element returned.
*
* @param xmlObject the XMLObject to marshall
* @return the marshalled Element
* @throws MarshallingException if there is a problem marshalling the XMLObject
*/
public static Element marshall(XMLObject xmlObject) throws MarshallingException {
Logger log = getLogger();
log.debug("Marshalling XMLObject");
if (xmlObject.getDOM() != null) {
log.debug("XMLObject already had cached DOM, returning that element");
return xmlObject.getDOM();
}
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject);
if (marshaller == null) {
log.error("Unable to marshall XMLOBject, no marshaller registered for object: "
+ xmlObject.getElementQName());
}
Element messageElem = marshaller.marshall(xmlObject);
if (log.isTraceEnabled()) {
log.trace("Marshalled XMLObject into DOM:");
log.trace(XMLHelper.nodeToString(messageElem));
}
return messageElem;
}
示例15
/**
* Constructs the XMLObject that the given DOM Element will be unmarshalled into. If the DOM element has an XML
* Schema type defined this method will attempt to retrieve an XMLObjectBuilder, from the factory given at
* construction time, using the schema type. If no schema type is present or no builder is registered with the
* factory for the schema type, the elements QName is used. Once the builder is found the XMLObject is create by
* invoking {@link XMLObjectBuilder#buildObject(String, String, String)}. Extending classes may wish to override
* this logic if more than just schema type or element name (e.g. element attributes or content) need to be used to
* determine which XMLObjectBuilder should be used to create the XMLObject.
*
* @param domElement the DOM Element the created XMLObject will represent
*
* @return the empty XMLObject that DOM Element can be unmarshalled into
*
* @throws UnmarshallingException thrown if there is now XMLObjectBuilder registered for the given DOM Element
*/
protected XMLObject buildXMLObject(Element domElement) throws UnmarshallingException {
if (log.isTraceEnabled()) {
log.trace("Building XMLObject for {}", XMLHelper.getNodeQName(domElement));
}
XMLObjectBuilder xmlObjectBuilder;
xmlObjectBuilder = xmlObjectBuilderFactory.getBuilder(domElement);
if (xmlObjectBuilder == null) {
xmlObjectBuilder = xmlObjectBuilderFactory.getBuilder(Configuration.getDefaultProviderQName());
if (xmlObjectBuilder == null) {
String errorMsg = "Unable to locate builder for " + XMLHelper.getNodeQName(domElement);
log.error(errorMsg);
throw new UnmarshallingException(errorMsg);
} else {
if (log.isTraceEnabled()) {
log.trace("No builder was registered for {} but the default builder {} was available, using it.",
XMLHelper.getNodeQName(domElement), xmlObjectBuilder.getClass().getName());
}
}
}
return xmlObjectBuilder.buildObject(domElement);
}
示例16
/**
* Constructor.
*
* @param newSignableObject the SAMLObject this reference refers to
*/
public SAMLObjectContentReference(SignableSAMLObject newSignableObject) {
signableObject = newSignableObject;
transforms = new LazyList<String>();
// Set defaults
if (Configuration.getGlobalSecurityConfiguration() != null ) {
digestAlgorithm = Configuration.getGlobalSecurityConfiguration().getSignatureReferenceDigestMethod();
}
if (digestAlgorithm == null) {
digestAlgorithm = SignatureConstants.ALGO_ID_DIGEST_SHA1;
}
transforms.add(SignatureConstants.TRANSFORM_ENVELOPED_SIGNATURE);
transforms.add(SignatureConstants.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
}
示例17
/**
* Gets the signature algorithm URI to use with the given signing credential.
*
* @param credential the credential that will be used to sign the message
* @param config the SecurityConfiguration to use (may be null)
*
* @return signature algorithm to use with the given signing credential
*
* @throws MessageEncodingException thrown if the algorithm URI could not be derived from the supplied credential
*/
protected String getSignatureAlgorithmURI(Credential credential, SecurityConfiguration config)
throws MessageEncodingException {
SecurityConfiguration secConfig;
if (config != null) {
secConfig = config;
} else {
secConfig = Configuration.getGlobalSecurityConfiguration();
}
String signAlgo = secConfig.getSignatureAlgorithmURI(credential);
if (signAlgo == null) {
throw new MessageEncodingException("The signing credential's algorithm URI could not be derived");
}
return signAlgo;
}
示例18
/**
* Gets the signature algorithm URI to use with the given signing credential.
*
* @param credential the credential that will be used to sign the message
* @param config the SecurityConfiguration to use (may be null)
*
* @return signature algorithm to use with the given signing credential
*
* @throws MessageEncodingException thrown if the algorithm URI could not be derived from the supplied credential
*/
protected String getSignatureAlgorithmURI(Credential credential, SecurityConfiguration config)
throws MessageEncodingException {
SecurityConfiguration secConfig;
if (config != null) {
secConfig = config;
} else {
secConfig = Configuration.getGlobalSecurityConfiguration();
}
String signAlgo = secConfig.getSignatureAlgorithmURI(credential);
if (signAlgo == null) {
throw new MessageEncodingException("The signing credential's algorithm URI could not be derived");
}
return signAlgo;
}
示例19
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException {
ContactPerson person = (ContactPerson) samlObject;
if (person.getType() != null) {
domElement.setAttributeNS(null, ContactPerson.CONTACT_TYPE_ATTRIB_NAME, person.getType().toString());
}
Attr attribute;
for (Entry<QName, String> entry : person.getUnknownAttributes().entrySet()) {
attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
attribute.setValue(entry.getValue());
domElement.setAttributeNodeNS(attribute);
if (Configuration.isIDAttribute(entry.getKey())
|| person.getUnknownAttributes().isIDAttribute(entry.getKey())) {
attribute.getOwnerElement().setIdAttributeNode(attribute, true);
}
}
}
示例20
public Signature getDigitalSignature(KeyStore.PrivateKeyEntry keystoreEntry) {
Signature signature = (Signature) Configuration.getBuilderFactory().getBuilder(Signature.DEFAULT_ELEMENT_NAME)
.buildObject(Signature.DEFAULT_ELEMENT_NAME);
Credential signingCredential = initializeCredentialsFromKeystore(keystoreEntry);
signature.setSigningCredential(signingCredential);
signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1);
SecurityConfiguration secConfig = Configuration.getGlobalSecurityConfiguration();
try {
SecurityHelper.prepareSignatureParams(signature, signingCredential, secConfig, null);
} catch (org.opensaml.xml.security.SecurityException ex) {
LOG.error("Error composing artifact resolution request: Failed to generate digital signature");
throw new IllegalArgumentException("Couldn't compose artifact resolution request", ex);
}
return signature;
}
示例21
/** Constructor. */
@SuppressWarnings("unchecked")
public SOAP11Encoder() {
super();
XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory.getBuilder(Envelope.DEFAULT_ELEMENT_NAME);
bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory.getBuilder(Body.DEFAULT_ELEMENT_NAME);
}
示例22
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
Body body = (Body) xmlObject;
Attr attribute;
for (Entry<QName, String> entry : body.getUnknownAttributes().entrySet()) {
attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
attribute.setValue(entry.getValue());
domElement.setAttributeNodeNS(attribute);
if (Configuration.isIDAttribute(entry.getKey())
|| body.getUnknownAttributes().isIDAttribute(entry.getKey())) {
attribute.getOwnerElement().setIdAttributeNode(attribute, true);
}
}
}
示例23
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
Envelope envelope = (Envelope) xmlObject;
Attr attribute;
for (Entry<QName, String> entry : envelope.getUnknownAttributes().entrySet()) {
attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
attribute.setValue(entry.getValue());
domElement.setAttributeNodeNS(attribute);
if (Configuration.isIDAttribute(entry.getKey())
|| envelope.getUnknownAttributes().isIDAttribute(entry.getKey())) {
attribute.getOwnerElement().setIdAttributeNode(attribute, true);
}
}
}
示例24
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
Header header = (Header) xmlObject;
Attr attribute;
for (Entry<QName, String> entry : header.getUnknownAttributes().entrySet()) {
attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
attribute.setValue(entry.getValue());
domElement.setAttributeNodeNS(attribute);
if (Configuration.isIDAttribute(entry.getKey())
|| header.getUnknownAttributes().isIDAttribute(entry.getKey())) {
attribute.getOwnerElement().setIdAttributeNode(attribute, true);
}
}
}
示例25
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
Detail detail = (Detail) xmlObject;
Attr attribute;
for (Entry<QName, String> entry : detail.getUnknownAttributes().entrySet()) {
attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
attribute.setValue(entry.getValue());
domElement.setAttributeNodeNS(attribute);
if (Configuration.isIDAttribute(entry.getKey())
|| detail.getUnknownAttributes().isIDAttribute(entry.getKey())) {
attribute.getOwnerElement().setIdAttributeNode(attribute, true);
}
}
}
示例26
/**
* Add a header to the SOAP 1.1 Envelope.
*
* @param envelope the SOAP 1.1 envelope to process
* @param headerBlock the header to add
*/
public static void addSOAP11HeaderBlock(Envelope envelope, XMLObject headerBlock) {
Header envelopeHeader = envelope.getHeader();
if (envelopeHeader == null) {
envelopeHeader = (Header) Configuration.getBuilderFactory().getBuilder(Header.DEFAULT_ELEMENT_NAME)
.buildObject(Header.DEFAULT_ELEMENT_NAME);
envelope.setHeader(envelopeHeader);
}
envelopeHeader.getUnknownXMLObjects().add(headerBlock);
}
示例27
/**
* Compare the supplied public and private keys, and determine if they correspond to the same key pair.
*
* @param pubKey the public key
* @param privKey the private key
* @return true if the public and private are from the same key pair, false if not
* @throws SecurityException if the keys can not be evaluated, or if the key algorithm is unsupported or unknown
*/
public static boolean matchKeyPair(PublicKey pubKey, PrivateKey privKey) throws SecurityException {
Logger log = getLogger();
// This approach attempts to match the keys by signing and then validating some known data.
if (pubKey == null || privKey == null) {
throw new SecurityException("Either public or private key was null");
}
// Need to dynamically determine the JCA signature algorithm ID to use from the key algorithm.
// Don't currently have a direct mapping, so have to map to XML Signature algorithm URI first,
// then map that to JCA algorithm ID.
SecurityConfiguration secConfig = Configuration.getGlobalSecurityConfiguration();
if (secConfig == null) {
throw new SecurityException("Global security configuration was null, could not resolve signing algorithm");
}
String algoURI = secConfig.getSignatureAlgorithmURI(privKey.getAlgorithm());
if (algoURI == null) {
throw new SecurityException("Can't determine algorithm URI from key algorithm: " + privKey.getAlgorithm());
}
String jcaAlgoID = getAlgorithmIDFromURI(algoURI);
if (jcaAlgoID == null) {
throw new SecurityException("Can't determine JCA algorithm ID from algorithm URI: " + algoURI);
}
if (log.isDebugEnabled()) {
log.debug("Attempting to match key pair containing key algorithms public '{}' private '{}', "
+ "using JCA signature algorithm '{}'", new Object[] { pubKey.getAlgorithm(),
privKey.getAlgorithm(), jcaAlgoID, });
}
byte[] data = "This is the data to sign".getBytes();
byte[] signature = SigningUtil.sign(privKey, jcaAlgoID, data);
return SigningUtil.verify(pubKey, jcaAlgoID, signature, data);
}
示例28
/**
* Constructor.
*
* @param newOptions the options to be used by the generator
*/
protected X509KeyInfoGenerator(X509Options newOptions) {
super(newOptions);
options = newOptions;
keyInfoBuilder =
(KeyInfoBuilder) Configuration.getBuilderFactory().getBuilder(KeyInfo.DEFAULT_ELEMENT_NAME);
x509DataBuilder =
(X509DataBuilder) Configuration.getBuilderFactory().getBuilder(X509Data.DEFAULT_ELEMENT_NAME);
}
示例29
/**
* Get a KeyInfo marshaller.
*
* @return a KeyInfo marshaller
* @throws SecurityException thrown if there is an error obtaining the marshaller from the configuration
*/
private Marshaller getMarshaller() throws SecurityException {
if (keyInfoMarshaller != null) {
return keyInfoMarshaller;
}
keyInfoMarshaller = Configuration.getMarshallerFactory().getMarshaller(KeyInfo.DEFAULT_ELEMENT_NAME);
if (keyInfoMarshaller == null) {
throw new SecurityException("Could not obtain KeyInfo marshaller from the configuration");
}
return keyInfoMarshaller;
}
示例30
/**
* Get a KeyInfo unmarshaller.
*
* @return a KeyInfo unmarshaller
* @throws SecurityException thrown if there is an error obtaining the unmarshaller from the configuration
*/
private Unmarshaller getUnmarshaller() throws SecurityException {
if (keyInfoUnmarshaller != null) {
return keyInfoUnmarshaller;
}
keyInfoUnmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(KeyInfo.DEFAULT_ELEMENT_NAME);
if (keyInfoUnmarshaller == null) {
throw new SecurityException("Could not obtain KeyInfo unmarshaller from the configuration");
}
return keyInfoUnmarshaller;
}