PKCS11 Wildfly 13 - Digital certificate

0

I'm trying to use the following library: link

To use it, it is necessary to load a digital certificate, in this case, type A1.

When you try to use it with a normal class with a public static void main it works normally. I have a jar of my design that I use all the time.

It turns out that by using the library in a web project <package>war</package> and deploying in Wildfly(versão 13) , when trying to load the certificate: CertificadoService.certificadoPfx(path, pass);

Bursts this Exception:

Caused by: java.lang.NoClassDefFoundError: sun/security/pkcs11/wrapper/PKCS11Exception

Follow class:

@Singleton
public class Worker {

    private AtomicBoolean busy = new AtomicBoolean(false);

    public void work() {
        if (!busy.compareAndSet(false, true)) {
            return;
        }
        try {
            System.out.println("Executing this task at " + new SimpleDateFormat("HH:mm:ss").format(new Date()) + ".");

            String path = "/home/user/certificado.pfx";
            String pass = "4321";


            CertificadoService.certificadoPfx(path, pass);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            busy.set(false);
        }
    }
}
    
asked by anonymous 28.08.2018 / 15:12

1 answer

0

Some JRE classes are not loaded by WildFly by default. Some of these are required by the API to load the digital certificate programmatically.

You then need to force them to be uploaded by the file

jboss-deployment-structure.xml

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <dependencies>
            <system export="true">
                <paths>
                    <path name="sun/security/x509"/>
                    <path name="sun/security/pkcs11"/>
                    <path name="sun/security/pkcs11/wrapper"/>
                </paths>
            </system>
        </dependencies>
    </deployment>
</jboss-deployment-structure>
    
30.08.2018 / 21:25