本文整理汇总了Java中org.opensaml.xml.Configuration类的典型用法代码示例。如果您正苦于以下问题:Java Configuration类的具体用法?Java Configuration怎么用?Java Configuration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Configuration类属于org.opensaml.xml包,在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: marshallMessage
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* 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: logDecodedMessage
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* 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: createRequestEntity
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* 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: getKeyInfoGenerator
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* 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: buildX509IssuerSerial
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* 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: addPublicKey
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* 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);
}
示例7: buildRSAKeyValue
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* 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;
}
示例8: buildDSAKeyValue
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* 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;
}
示例9: Decrypter
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* 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;
}
示例10: checkAndMarshall
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* 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);
}
}
}
示例11: Encrypter
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* Constructor.
*
*/
public Encrypter() {
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
encryptedDataUnmarshaller = unmarshallerFactory.getUnmarshaller(EncryptedData.DEFAULT_ELEMENT_NAME);
encryptedKeyUnmarshaller = unmarshallerFactory.getUnmarshaller(EncryptedKey.DEFAULT_ELEMENT_NAME);
XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
keyInfoBuilder = (XMLSignatureBuilder<KeyInfo>) builderFactory.getBuilder(KeyInfo.DEFAULT_ELEMENT_NAME);
jcaProviderName = null;
}
示例12: marshallAttributes
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/** {@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: put
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/** {@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
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* 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: buildXMLObject
import org.opensaml.xml.Configuration; //导入依赖的package包/类
/**
* 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);
}