本文整理汇总了Java中org.opensaml.xml.io.UnmarshallerFactory类的典型用法代码示例。如果您正苦于以下问题:Java UnmarshallerFactory类的具体用法?Java UnmarshallerFactory怎么用?Java UnmarshallerFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnmarshallerFactory类属于org.opensaml.xml.io包,在下文中一共展示了UnmarshallerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unmarshall
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
/**
* Constructing the SAML or XACML Objects from a String
*
* @param xmlString Decoded SAML or XACML String
* @return SAML or XACML Object
* @throws org.wso2.carbon.identity.base.IdentityException
*/
public static XMLObject unmarshall(String xmlString) throws IdentityException {
try {
DocumentBuilderFactory documentBuilderFactory = getSecuredDocumentBuilderFactory();
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = docBuilder.parse(new ByteArrayInputStream(xmlString.trim().getBytes(Charsets.UTF_8)));
Element element = document.getDocumentElement();
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
return unmarshaller.unmarshall(element);
} catch (ParserConfigurationException | UnmarshallingException | SAXException | IOException e) {
String message = "Error in constructing XML Object from the encoded String";
throw IdentityException.error(message, e);
}
}
示例2: Encrypter
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的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;
}
示例3: unmarshall
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
/**
* Constructing the SAML or XACML Objects from a String
*
* @param xmlString Decoded SAML or XACML String
* @return SAML or XACML Object
* @throws org.wso2.carbon.identity.entitlement.EntitlementException
*/
public XMLObject unmarshall(String xmlString) throws EntitlementException {
try {
doBootstrap();
DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory();
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = docBuilder.parse(new ByteArrayInputStream(xmlString.trim().getBytes()));
Element element = document.getDocumentElement();
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
return unmarshaller.unmarshall(element);
} catch (Exception e) {
log.error("Error in constructing XML(SAML or XACML) Object from the encoded String", e);
throw new EntitlementException("Error in constructing XML(SAML or XACML) from the encoded String ", e);
}
}
示例4: unmarshall
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
/**
* Constructing the SAML or XACML Objects from a String
*
* @param xmlString Decoded SAML or XACML String
* @return SAML or XACML Object
* @throws org.wso2.carbon.identity.entitlement.EntitlementException
*/
public XMLObject unmarshall(String xmlString) throws EntitlementException {
try {
doBootstrap();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setExpandEntityReferences(false);
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
SecurityManager securityManager = new SecurityManager();
securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT);
documentBuilderFactory.setAttribute(SECURITY_MANAGER_PROPERTY, securityManager);
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
docBuilder.setEntityResolver(new CarbonEntityResolver());
Document document = docBuilder.parse(new ByteArrayInputStream(xmlString.trim().getBytes()));
Element element = document.getDocumentElement();
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
return unmarshaller.unmarshall(element);
} catch (Exception e) {
log.error("Error in constructing XML(SAML or XACML) Object from the encoded String", e);
throw new EntitlementException("Error in constructing XML(SAML or XACML) from the encoded String ", e);
}
}
示例5: unmarshall
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
/**
* Constructing the SAML or XACML Objects from a String
*
* @param xmlString Decoded SAML or XACML String
* @return SAML or XACML Object
* @throws org.wso2.carbon.identity.base.IdentityException
*/
public static XMLObject unmarshall(String xmlString) throws IdentityException {
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setExpandEntityReferences(false);
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
org.apache.xerces.util.SecurityManager securityManager = new SecurityManager();
securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT);
documentBuilderFactory.setAttribute(SECURITY_MANAGER_PROPERTY, securityManager);
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
docBuilder.setEntityResolver(new CarbonEntityResolver());
Document document = docBuilder.parse(new ByteArrayInputStream(xmlString.trim().getBytes(Charsets.UTF_8)));
Element element = document.getDocumentElement();
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
return unmarshaller.unmarshall(element);
} catch (ParserConfigurationException | UnmarshallingException | SAXException | IOException e) {
String message = "Error in constructing XML Object from the encoded String";
throw IdentityException.error(message, e);
}
}
示例6: setUp
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
/** {@inheritDoc} */
protected void setUp(){
OrganizationBuilder orgBuilder = (OrganizationBuilder) Configuration.getBuilderFactory().getBuilder(Organization.TYPE_NAME);
organization = orgBuilder.buildObject();
OrganizationNameBuilder orgNameBuilder = (OrganizationNameBuilder) Configuration.getBuilderFactory().getBuilder(OrganizationName.DEFAULT_ELEMENT_NAME);
OrganizationName newOrgName = orgNameBuilder.buildObject();
newOrgName.setName(new LocalizedString("OrgFullName", "en"));
organization.getOrganizationNames().add(newOrgName);
OrganizationDisplayNameBuilder orgDisplayNameBuilder = (OrganizationDisplayNameBuilder) Configuration.getBuilderFactory().getBuilder(OrganizationDisplayName.DEFAULT_ELEMENT_NAME);
OrganizationDisplayName newOrgDisplayName = orgDisplayNameBuilder.buildObject();
newOrgDisplayName.setName(new LocalizedString("OrgDisplayName", "en"));
organization.getDisplayNames().add(newOrgDisplayName);
OrganizationURLBuilder orgURLBuilder = (OrganizationURLBuilder) Configuration.getBuilderFactory().getBuilder(OrganizationURL.DEFAULT_ELEMENT_NAME);
OrganizationURL newOrgURL = orgURLBuilder.buildObject();
newOrgURL.setURL(new LocalizedString("http://org.url.edu", "en"));
organization.getURLs().add(newOrgURL);
MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory();
orgMarshaller = marshallerFactory.getMarshaller(organization);
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
orgUnmarshaller = unmarshallerFactory.getUnmarshaller(organization.getElementQName());
}
示例7: unmarshall
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
/**
* Constructing the XMLObject Object from a String
*
* @param authReqStr
* @return Corresponding XMLObject which is a SAML2 object
* @throws Exception
*/
public static XMLObject unmarshall(String authReqStr) throws Exception {
try {
doBootstrap();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = docBuilder.parse(new ByteArrayInputStream(authReqStr.trim().getBytes()));
Element element = document.getDocumentElement();
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
return unmarshaller.unmarshall(element);
} catch (Exception e) {
throw new Exception("Error in constructing AuthRequest from " +
"the encoded String ", e);
}
}
示例8: buildOpenSamlXmlObjectFromResource
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
/**
* Read a Ressource File.
*
* @param resourceFile
* @return the string representation of the file
* @throws IOException
* @throws SecurityException
* @throws MessageDecodingException
*/
public static XMLObject buildOpenSamlXmlObjectFromResource(final Resource resourceFile)
throws Exception {
// Parse XML file
BasicParserPool ppMgr = new BasicParserPool();
ppMgr.setNamespaceAware(true);
Document inCommonMDDoc = ppMgr.parse(resourceFile.getInputStream());
Element rootElement = inCommonMDDoc.getDocumentElement();
// Get apropriate unmarshaller
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(rootElement);
// Unmarshall using the document root element, an EntitiesDescriptor in this case
XMLObject xmlObject = unmarshaller.unmarshall(rootElement);
Assert.assertNotNull("Unable to read test SAML XML file !", xmlObject);
return xmlObject;
}
示例9: parseSamlObject
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
public static XMLObject parseSamlObject(String xmlInput)
throws XMLParserException, UnmarshallingException {
LOGGER.entering(SamlTool.class.getName(), "parseSamlObject", xmlInput);
StringReader reader = new StringReader(xmlInput);
// Parse metadata file
Document inCommonMDDoc = basicParserPool.parse(reader);
Element metadataRoot = inCommonMDDoc.getDocumentElement();
// Get apropriate unmarshaller
UnmarshallerFactory unmarshallerFactory = Configuration
.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory
.getUnmarshaller(metadataRoot);
// Unmarshall using the document root element, an EntitiesDescriptor in
// this case
XMLObject result = unmarshaller.unmarshall(metadataRoot);
LOGGER.exiting(SamlTool.class.getName(), "parseSamlObject", result);
return result;
}
示例10: setUp
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
Document doc = documentBuilderFactory.newDocumentBuilder().parse(OIORequest.class.getResourceAsStream("request.xml"));
Configuration.getBuilderFactory();
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(doc.getDocumentElement());
request = (RequestAbstractType) unmarshaller.unmarshall(doc.getDocumentElement());
request.getIssuer().setValue("IssuerValue");
}
示例11: unmarshall
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
/**
* Constructing the XMLObject Object from a String
*
* @param authReqStr
* @return Corresponding XMLObject which is a SAML2 object
* @throws SAML2SSOUIAuthenticatorException
*/
public static XMLObject unmarshall(String authReqStr) throws SAML2SSOUIAuthenticatorException {
try {
doBootstrap();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setExpandEntityReferences(false);
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
SecurityManager securityManager = new SecurityManager();
securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT);
documentBuilderFactory.setAttribute(SECURITY_MANAGER_PROPERTY, securityManager);
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
docBuilder.setEntityResolver(new CarbonEntityResolver());
Document document = docBuilder.parse(new ByteArrayInputStream(authReqStr.trim()
.getBytes()));
Element element = document.getDocumentElement();
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
return unmarshaller.unmarshall(element);
} catch (Exception e) {
log.error("Error in constructing AuthRequest from the encoded String", e);
throw new SAML2SSOUIAuthenticatorException("Error in constructing AuthRequest from "
+ "the encoded String ", e);
}
}
示例12: unmarshall
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
/**
* Constructing the SAML or XACML Objects from a String
*
* @param xmlString Decoded SAML or XACML String
* @return SAML or XACML Object
* @throws EntitlementProxyException
*/
private XMLObject unmarshall(String xmlString) throws EntitlementProxyException {
try {
doBootstrap();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setExpandEntityReferences(false);
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
SecurityManager securityManager = new SecurityManager();
securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT);
documentBuilderFactory.setAttribute(SECURITY_MANAGER_PROPERTY, securityManager);
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
docBuilder.setEntityResolver(new CarbonEntityResolver());
Document document = docBuilder.parse(new ByteArrayInputStream(xmlString.trim().getBytes(Charset.forName
("UTF-8"))));
Element element = document.getDocumentElement();
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
return unmarshaller.unmarshall(element);
} catch (Exception e) {
log.error("Error in constructing XML(SAML or XACML) Object from the encoded String", e);
throw new EntitlementProxyException(
"Error in constructing XML(SAML or XACML) from the encoded String", e);
}
}
示例13: parseTokenFromString
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
/**
* parseTokenFromString converts a raw wresult and extracts it into an assertion.
*
* @param wresult the raw token returned by the IdP
* @return an assertion
*/
public static Assertion parseTokenFromString(final String wresult) {
try (final InputStream in = new ByteArrayInputStream(wresult.getBytes("UTF-8"))) {
final BasicParserPool parserPool = new BasicParserPool();
parserPool.setNamespaceAware(true);
final Document document = parserPool.parse(in);
final Element metadataRoot = document.getDocumentElement();
final UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
final Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(metadataRoot);
final RequestSecurityTokenResponseImpl rsToken = (RequestSecurityTokenResponseImpl) unmarshaller.unmarshall(metadataRoot);
//Get our SAML token
final List<RequestedSecurityToken> rst = rsToken.getRequestedSecurityToken();
final AssertionImpl assertion = (AssertionImpl) rst.get(0).getSecurityTokens().get(0);
if (assertion == null) {
LOGGER.debug("parseTokenFromString: assertion null");
} else {
LOGGER.debug("parseTokenFromString: {}", assertion);
}
return assertion;
} catch (final Exception ex) {
LOGGER.warn(ex.getMessage());
return null;
}
}
示例14: decodeSAMLResponse
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
public static Response decodeSAMLResponse(String responseMessage)
throws ConfigurationException, ParserConfigurationException,
SAXException, IOException, UnmarshallingException {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
byte[] base64DecodedResponse = Base64.decode(responseMessage);
Document document = docBuilder.parse(new ByteArrayInputStream(base64DecodedResponse));
Element element = document.getDocumentElement();
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
return (Response) unmarshaller.unmarshall(element);
}
示例15: convertToSAMLResponse
import org.opensaml.xml.io.UnmarshallerFactory; //导入依赖的package包/类
/**
* Convert w3c element to a SAML response
* @param element
* @return
*/
public org.opensaml.saml2.core.Response convertToSAMLResponse(org.w3c.dom.Element element) {
org.opensaml.saml2.core.Response samlResponse = null;
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
if(unmarshaller == null) {
raiseSamlValidationError("Invalid SAML Response", null);
}
XMLObject responseXmlObj = null;
try {
responseXmlObj = unmarshaller.unmarshall(element);
} catch (UnmarshallingException e) {
raiseSamlValidationError("Error unmarshalling response from IdP", null);
}
if (responseXmlObj instanceof org.opensaml.saml2.core.Response) {
samlResponse = (org.opensaml.saml2.core.Response) responseXmlObj;
} else {
raiseSamlValidationError("Response is in an improper format", null);
}
return samlResponse;
}