Search in sources :

Example 1 with DummyProvider

use of org.jboss.as.test.integration.deployment.jcedeployment.provider.DummyProvider in project wildfly by wildfly.

the class ControllerServlet method init.

public void init(ServletConfig config) throws ServletException {
    try {
        final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        try (InputStream in = Files.newInputStream(Paths.get("target/jcetest.keystore"))) {
            keyStore.load(in, "password".toCharArray());
        }
        final X509Certificate testCertificate = (X509Certificate) keyStore.getCertificate("test");
        assert testCertificate != null;
        // the three musketeers who are guarding the crown are hardcoded in jse.jar (JarVerifier)
        // sun.security.validator.SimpleValidator
        final Object validator = get("javax.crypto.JarVerifier", "providerValidator", Object.class);
        get(validator, "trustedX500Principals", Map.class).put(testCertificate.getIssuerX500Principal(), Arrays.asList(testCertificate));
    } catch (ClassNotFoundException e) {
        throw new ServletException("This requires being run on Oracle JDK 7.", e);
    } catch (Exception e) {
        throw new ServletException("Cannot install the certificate to the validator.", e);
    }
    java.security.Security.addProvider(new DummyProvider());
}
Also used : ServletException(javax.servlet.ServletException) DummyProvider(org.jboss.as.test.integration.deployment.jcedeployment.provider.DummyProvider) InputStream(java.io.InputStream) KeyStore(java.security.KeyStore) Map(java.util.Map) X509Certificate(java.security.cert.X509Certificate) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 2 with DummyProvider

use of org.jboss.as.test.integration.deployment.jcedeployment.provider.DummyProvider in project wildfly by wildfly.

the class JCETestCase method deployment.

@Deployment
public static Archive<?> deployment() throws Exception {
    final JavaArchive jce = ShrinkWrap.create(JavaArchive.class, "jcetest.jar").addPackage(DummyProvider.class.getPackage());
    final File jceJar = new File("target/jcetest.jar");
    jce.as(ZipExporter.class).exportTo(jceJar, true);
    final File signedJceJar = new File("target/jcetestsigned.jar");
    JavaArchive signedJce;
    if (isJCETestable()) {
        // see genkey-jcetest-keystore in pom.xml for the keystore creation
        final JarSignerUtil signer = new JarSignerUtil(new File("target/jcetest.keystore"), "password", "password", /* alias */
        "test");
        signer.sign(jceJar, signedJceJar);
        signer.verify(signedJceJar);
        signedJce = ShrinkWrap.create(ZipImporter.class, "jcetestsigned.jar").importFrom(signedJceJar).as(JavaArchive.class);
    } else {
        log.trace("skipping the test since it can run on Oracle JDK only");
        signedJce = jce;
    }
    final WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war").addClasses(ControllerServlet.class);
    final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "jcetest.ear").addAsLibrary(signedJce).addAsModule(war).addAsManifestResource(JCETestCase.class.getPackage(), "jboss-deployment-structure.xml", "jboss-deployment-structure.xml");
    // ControllerServlet and DummyProvider need the following perms for their "dirty" game
    ear.addAsManifestResource(createPermissionsXmlAsset(new FilePermission("target/jcetest.keystore", "read"), new RuntimePermission("accessDeclaredMembers"), new ReflectPermission("suppressAccessChecks"), new RuntimePermission("accessClassInPackage.sun.security.validator"), new SecurityPermission("putProviderProperty.DP"), new SecurityPermission("insertProvider"), new RuntimePermission("getProtectionDomain")), "permissions.xml");
    return ear;
}
Also used : EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) DummyProvider(org.jboss.as.test.integration.deployment.jcedeployment.provider.DummyProvider) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) FilePermission(java.io.FilePermission) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) ZipImporter(org.jboss.shrinkwrap.api.importer.ZipImporter) ReflectPermission(java.lang.reflect.ReflectPermission) File(java.io.File) SecurityPermission(java.security.SecurityPermission) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Aggregations

DummyProvider (org.jboss.as.test.integration.deployment.jcedeployment.provider.DummyProvider)2 File (java.io.File)1 FilePermission (java.io.FilePermission)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ReflectPermission (java.lang.reflect.ReflectPermission)1 KeyStore (java.security.KeyStore)1 SecurityPermission (java.security.SecurityPermission)1 X509Certificate (java.security.cert.X509Certificate)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 Deployment (org.jboss.arquillian.container.test.api.Deployment)1 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)1 ZipImporter (org.jboss.shrinkwrap.api.importer.ZipImporter)1 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)1 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)1 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)1