I’m having problems with a project deployment. Here’s the error i get:
01:08:26,780 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/domain-as]] (MSC service thread 1-7) Exception sending context initialized event to listener instance of class pt.ist.anacom.applicationserver.ApplicationServerInitListener: java.lang.NoClassDefFoundError: sun/security/x509/X509CertImpl
at pt.ist.anacom.applicationserver.ApplicationServerInitListener.generateCert(ApplicationServerInitListener.java:86) [classes:]
at pt.ist.anacom.applicationserver.ApplicationServerInitListener.contextInitialized(ApplicationServerInitListener.java:51) [classes:]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [:1.6.0_30]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [:1.6.0_30]
at java.lang.Thread.run(Unknown Source) [:1.6.0_30]
Caused by: java.lang.ClassNotFoundException: sun.security.x509.X509CertImpl from [Module "deployment.domain-as.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:361)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:333)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:310)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:103)
... 10 more
This happened when i added a new function to my code in which i call a function of another class to generate a security certificate. This is the code of the function that makes the call:
public static void generateCert(String name, KeyPair key, int days, String algorithm) throws GeneralSecurityException, IOException{
System.out.println("Starting to generate certificate");
X509Certificate cert = CertificationAuthority.generateCertificate(name, key, days, algorithm);
//return cert;
}
It does make the print, but then the error occurs. The generate certificate is in another class (the CertificationAuthority class) and has the following code:
public static X509Certificate generateCertificate(String dn, KeyPair pair, int days, String algorithm)
throws GeneralSecurityException, IOException
{
PrivateKey privkey = pair.getPrivate();
X509CertInfo info = new X509CertInfo();
//caso haja tempo, tratar isto com long + long
Date from = new Date();
Date to = new Date(from.getTime() + days * 864000001);
CertificateValidity interval = new CertificateValidity(from, to);
BigInteger sn = new BigInteger(64, new SecureRandom());
X500Name owner = new X500Name(dn);
info.set(X509CertInfo.VALIDITY, interval);
info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(sn));
info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(owner));
info.set(X509CertInfo.ISSUER, new CertificateIssuerName(owner));
info.set(X509CertInfo.KEY, new CertificateX509Key(pair.getPublic()));
info.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3));
AlgorithmId algo = new AlgorithmId(AlgorithmId.md5WithRSAEncryption_oid);
info.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algo));
// Sign the cert to identify the algorithm that's used.
X509CertImpl cert = new X509CertImpl(info);
cert.sign(privkey, algorithm);
// Update the algorithm, and resign.
algo = (AlgorithmId)cert.get(X509CertImpl.SIG_ALG);
info.set(CertificateAlgorithmId.NAME + "." + CertificateAlgorithmId.ALGORITHM, algo);
cert = new X509CertImpl(info);
cert.sign(privkey, algorithm);
certificates.add(cert);
return cert;
}
I don’t understand why i’m getting that error. I’m trying to test the functionality of the generateCertificate methdod but i’m not being able to do it because of this error.
Anyone has an idea of what is happening?
JBoss isolates Sun classes away. Have a look at the
sun.jdkmodule, you need to addsun/security/x509as an export there or create your own module that does this.