org.apache.xml.security.Init.init()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(492)

本文整理了Java中org.apache.xml.security.Init.init()方法的一些代码示例,展示了Init.init()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Init.init()方法的具体详情如下:
包路径:org.apache.xml.security.Init
类名称:Init
方法名:init

Init.init介绍

[英]Method init
[中]方法初始化

代码示例

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Initialize the xml signing environment and the bouncycastle provider
 */
protected static synchronized void initXmlProvider() {
  if (isInitialized) {
    return;
  }
  isInitialized = true;
  try {
    Init.init();
    RelationshipTransformService.registerDsigProvider();
    CryptoFunctions.registerBouncyCastle();
  } catch (Exception e) {
    throw new RuntimeException("Xml & BouncyCastle-Provider initialization failed", e);
  }
}

代码示例来源:origin: org.apache.santuario/xmlsec

private DOMURIDereferencer() {
  // need to call org.apache.xml.security.Init.init()
  // before calling any apache security code
  Init.init();
}

代码示例来源:origin: io.apigee.opensaml/xmltooling

/** Constructor. */
public SignatureMarshaller() {
  if (!Init.isInitialized()) {
    log.debug("Initializing XML security library");
    Init.init();
  }
}

代码示例来源:origin: io.apigee.opensaml/xmltooling

/** Constructor. */
public SignatureUnmarshaller() {
  if (!Init.isInitialized()) {
    log.debug("Initializing XML security library");
    Init.init();
  }
}

代码示例来源:origin: org.apache.rampart/rampart-trust

public void init(ConfigurationContext configContext, AxisModule module)
    throws AxisFault {
  // Set up OpenSAML to use a DOM aware Axiom implementation
  // Axiom Parser pool is also set within the RampartSAMLBootstrap class.
  try {
    RampartSAMLBootstrap.bootstrap();
    // Initialize XML security
    org.apache.xml.security.Init.init();
  } catch (ConfigurationException ex) {
    throw new AxisFault("Failed to bootstrap OpenSAML", ex);
  }
}

代码示例来源:origin: org.opensaml/xmltooling

/** Constructor. */
public SignatureUnmarshaller() {
  if (!Init.isInitialized()) {
    log.debug("Initializing XML security library");
    Init.init();
  }
}

代码示例来源:origin: org.opensaml/xmltooling

/** Constructor. */
public SignatureMarshaller() {
  if (!Init.isInitialized()) {
    log.debug("Initializing XML security library");
    Init.init();
  }
}

代码示例来源:origin: org.openrdf.sesame/sesame-rio-testsuite

public CanonXMLValueFactory()
  throws InvalidCanonicalizerException, ParserConfigurationException
{
  org.apache.xml.security.Init.init();
  c14n = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
}

代码示例来源:origin: org.opensaml/opensaml

/**
 * Initializes the Apache XMLSecurity libary.
 * 
 * @throws ConfigurationException thrown is there is a problem initializing the library
 */
protected static void initializeXMLSecurity() throws ConfigurationException {
  Logger log = getLogger();
  String lineBreakPropName = "org.apache.xml.security.ignoreLineBreaks";
  // Don't override if it was set explicitly
  if (System.getProperty(lineBreakPropName) == null) {
    System.setProperty(lineBreakPropName, "true");
  }
  if (!Init.isInitialized()) {
    log.debug("Initializing Apache XMLSecurity library");
    Init.init();
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * Initialize the xml signing environment and the bouncycastle provider
 */
protected static synchronized void initXmlProvider() {
  if (isInitialized) {
    return;
  }
  isInitialized = true;
  try {
    Init.init();
    RelationshipTransformService.registerDsigProvider();
    CryptoFunctions.registerBouncyCastle();
  } catch (Exception e) {
    throw new RuntimeException("Xml & BouncyCastle-Provider initialization failed", e);
  }
}

代码示例来源:origin: com.ebmwebsourcing.easyviper.environment/easyviper.environment.test

public static String getXMLSHA1Sign(InputStream inputStream, boolean ommitComments)
    throws Exception {
  // Create a canonicalizer
  org.apache.xml.security.Init.init();
  Canonicalizer canonicalizer = null;
  if (ommitComments) {
    canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS);
  } else {
    canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS);
  }
  // Prettify the given xml input stream to remove unnecessary spaces and
  // tabs
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  XMLPrettyPrinter.prettify(inputStream, byteArrayOutputStream);
  byte[] bytes = byteArrayOutputStream.toByteArray();
  // Canonicalize the prettified xml stream
  byte[] canonBytes = canonicalizer.canonicalize(bytes);
  // Generate the SHA1 hash
  MessageDigest hash = MessageDigest.getInstance("SHA1");
  String hashString = new String(hash.digest(canonBytes));
  return hashString;
}

代码示例来源:origin: com.ebmwebsourcing.easycommons/easycommons.xml

public static String getXMLSHA1Sign(InputStream inputStream, boolean ommitComments)
    throws Exception {
  // Create a canonicalizer
  org.apache.xml.security.Init.init();
  Canonicalizer canonicalizer = null;
  if (ommitComments) {
    canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS);
  } else {
    canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS);
  }
  // Prettify the given xml input stream to remove unnecessary spaces and
  // tabs
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  XMLPrettyPrinter.prettify(inputStream, byteArrayOutputStream);
  byte[] bytes = byteArrayOutputStream.toByteArray();
  // Canonicalize the prettified xml stream
  byte[] canonBytes = canonicalizer.canonicalize(bytes);
  // Generate the SHA1 hash
  MessageDigest hash = MessageDigest.getInstance("SHA1");
  String hashString = new String(hash.digest(canonBytes));
  return hashString;
}

代码示例来源:origin: org.wso2.carbon.identity.metadata.saml2/org.wso2.carbon.identity.outbound.metadata.saml2

public void signMetadata(EntityDescriptor baseDescriptor) throws MetadataException {
  // Add key descriptors for each element in base descriptor.
  List<RoleDescriptor> roleDescriptors = baseDescriptor.getRoleDescriptors();
  if (roleDescriptors.size() > 0) {
    for (RoleDescriptor roleDesc : roleDescriptors) {
      roleDesc.getKeyDescriptors().add(createKeyDescriptor());
    }
  }
  if (log.isDebugEnabled()) {
    log.debug("Key Descriptors set for all the role descriptor types");
  }
  // Remove namespace of Signature element
  try {
    org.apache.xml.security.utils.ElementProxy.setDefaultPrefix(ConfigElements.XMLSIGNATURE_NS, "");
  } catch (XMLSecurityException e) {
    throw new MetadataException("Unable to set default prefix for signature element", e);
  }
  org.apache.xml.security.Init.init();
}
/**

代码示例来源:origin: luisgoncalves/xades4j

static void initXMLSec()
  {
    org.apache.xml.security.Init.init();
    try
    {
      ElementProxy.setDefaultPrefix(Constants.SignatureSpecNS, "ds");
      ElementProxy.setDefaultPrefix(QualifyingProperty.XADES_XMLNS, "xades");
      ElementProxy.setDefaultPrefix(QualifyingProperty.XADESV141_XMLNS, "xades141");
    } catch (XMLSecurityException ex)
    {
    }
  }
}

代码示例来源:origin: holodeck-b2b/Holodeck-B2B

/**
 * Converts a {@link Document} representation of the SOAP Envelope into a Axiom representation.
 *
 * @param document The standard DOM representation of the SOAP Envelope
 * @return An {@link SOAPEnvelope} object containing the Axiom representation of the SOAP envelope, or <br>
 * <code>null</code> if the conversion fails
 */
public static SOAPEnvelope convertDOMSOAPEnvToAxiom(final Document document) {
  try {
    // If no security action is performed the Santuario may not have been initialized which causes the
    // XMLUtils.outputDOM to fail
    if (!org.apache.xml.security.Init.isInitialized())
      org.apache.xml.security.Init.init();
    // The call of the Document.normalizeDocument() method is to fix the exception described here:
    // http://apache-xml-project.6118.n7.nabble.com/Undeclared-namespace-prefix-quot-ds-quot-error-td36346.html
    document.normalizeDocument();
    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    XMLUtils.outputDOM(document.getDocumentElement(), os, true);
    final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray());
    final SOAPModelBuilder stAXSOAPModelBuilder = OMXMLBuilderFactory.createSOAPModelBuilder(bais, null);
    final SOAPEnvelope env = stAXSOAPModelBuilder.getSOAPEnvelope();
    env.build();
    return env;
  } catch (final Exception e) {
    // If anything goes wrong converting the document, just return null
    return null;
  }
}

代码示例来源:origin: net.shibboleth.metadata/aggregator-pipeline

/** {@inheritDoc} */
  @Override protected void doInitialize() throws ComponentInitializationException {
    super.doInitialize();

    if (verificationKey == null) {
      throw new ComponentInitializationException("Unable to initialize " + getId()
          + ", no verification key was specified");
    }

    validator = new XMLSignatureValidator(verificationKey,
        blacklistedDigests, blacklistedSignatureMethods, permittingEmptyReferences);

    if (!Init.isInitialized()) {
      Init.init();
    }
  }
}

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.sso.agent

/**
 * Sign the SAML AuthnRequest message
 *
 * @param logoutRequest
 * @param signatureAlgorithm
 * @param cred
 * @return
 * @throws SSOAgentException
 */
public static LogoutRequest setSignature(LogoutRequest logoutRequest, String signatureAlgorithm,
                     X509Credential cred) throws SSOAgentException {
  try {
    Signature signature = setSignatureRaw(signatureAlgorithm,cred);
    logoutRequest.setSignature(signature);
    List<Signature> signatureList = new ArrayList<Signature>();
    signatureList.add(signature);
    // Marshall and Sign
    MarshallerFactory marshallerFactory =
        org.opensaml.xml.Configuration.getMarshallerFactory();
    Marshaller marshaller = marshallerFactory.getMarshaller(logoutRequest);
    marshaller.marshall(logoutRequest);
    org.apache.xml.security.Init.init();
    Signer.signObjects(signatureList);
    return logoutRequest;
  } catch (Exception e) {
    throw new SSOAgentException("Error while signing the Logout Request message", e);
  }
}

代码示例来源:origin: org.wso2.carbon.identity.agent.sso.java/org.wso2.carbon.identity.sso.agent

/**
 * Add signature to any singable XML object.
 * @param xmlObject Singable xml object.
 * @param signatureAlgorithm Signature algorithm to be used.
 * @param cred X509 Credentials.
 * @param <T> Singable XML object with signature.
 * @return Singable XML object with signature.
 * @throws SSOAgentException If error occurred.
 */
public static <T extends SignableXMLObject> T setSignatureValue(T xmlObject, String signatureAlgorithm,
                                X509Credential cred)
    throws SSOAgentException {
  try {
    Signature signature = setSignatureRaw(signatureAlgorithm, cred);
    xmlObject.setSignature(signature);
    List<Signature> signatureList = new ArrayList<>();
    signatureList.add(signature);
    // Marshall and Sign
    MarshallerFactory marshallerFactory =
        org.opensaml.xml.Configuration.getMarshallerFactory();
    Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
    marshaller.marshall(xmlObject);
    org.apache.xml.security.Init.init();
    Signer.signObjects(signatureList);
    return xmlObject;
  } catch (Exception e) {
    throw new SSOAgentException("Error while signing the SAML Request message", e);
  }
}

代码示例来源:origin: org.wso2.appserver/appserver-webapp-security

Init.init();

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.sso.agent

/**
 * Sign the SAML AuthnRequest message
 *
 * @param authnRequest
 * @param signatureAlgorithm
 * @param cred
 * @return
 * @throws org.wso2.carbon.identity.sso.agent.SSOAgentException
 */
public static AuthnRequest setSignature(AuthnRequest authnRequest, String signatureAlgorithm,
                  X509Credential cred) throws SSOAgentException {
  doBootstrap();
  try {
    Signature signature = setSignatureRaw(signatureAlgorithm,cred);
    authnRequest.setSignature(signature);
    List<Signature> signatureList = new ArrayList<Signature>();
    signatureList.add(signature);
    // Marshall and Sign
    MarshallerFactory marshallerFactory =
        org.opensaml.xml.Configuration.getMarshallerFactory();
    Marshaller marshaller = marshallerFactory.getMarshaller(authnRequest);
    marshaller.marshall(authnRequest);
    org.apache.xml.security.Init.init();
    Signer.signObjects(signatureList);
    return authnRequest;
  } catch (Exception e) {
    throw new SSOAgentException("Error while signing the SAML Request message", e);
  }
}

相关文章