ulisesbocchio / jasypt-spring-boot

Jasypt integration for Spring boot
MIT License
2.87k stars 514 forks source link

versions 3.0.4 and 3.0.5 throw java.lang.NoClassDefFoundError: ch/qos/logback/core/util/ContextUtil #347

Open dbnex14 opened 1 year ago

dbnex14 commented 1 year ago

I am using spring-boot-starter-parent version 2.7.6

Same issue described below happens with jasypt-spring-boot-starter dependency 3.0.4 and 3.0.5 OpenJdk11

Added in pom.xml of my Spring Boot app

        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>3.0.5</version>
        </dependency>

Added plugin:

<build>
   <plugins>
        ....

    <plugin>
         <groupId>com.github.ulisesbocchio</groupId>
         <artifactId>jasypt-maven-plugin</artifactId>
         <version>3.0.5</version>
    </plugin>
   </plugins>

Annotated my spring boot class

@EnableEncryptableProperties
@SpringBootApplication
public class MyApiApplication {
    public static void main(String[] args) {...}
}

Issuing: mvn jasypt:encrypt-value -Djasypt.encryptor.password=mysecret -Djasypt.plugin.value=valuetoencrypt

Exception in thread "SpringApplicationShutdownHook" java.lang.NoClassDefFoundError: ch/qos/logback/core/util/ContextUtil at ch.qos.logback.core.FileAppender.stop(FileAppender.java:146) at ch.qos.logback.core.rolling.RollingFileAppender.stop(RollingFileAppender.java:149) at ch.qos.logback.core.spi.AppenderAttachableImpl.detachAndStopAllAppenders(AppenderAttachableImpl.java:107) at ch.qos.logback.classic.Logger.detachAndStopAllAppenders(Logger.java:206) at ch.qos.logback.classic.Logger.recursiveReset(Logger.java:331) at ch.qos.logback.classic.LoggerContext.reset(LoggerContext.java:223) at ch.qos.logback.classic.LoggerContext.stop(LoggerContext.java:348) at org.springframework.boot.logging.logback.LogbackLoggingSystem.lambda$getShutdownHandler$0(LogbackLoggingSystem.java:284) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.boot.SpringApplicationShutdownHook.run(SpringApplicationShutdownHook.java:116) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.util.ContextUtil at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50) at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)

The full output of the command above is:

mvn jasypt:encrypt-value -Djasypt.encryptor.password=ackornack -Djasypt.plugin.value=dino [INFO] Scanning for projects... [INFO] [INFO] ----------------------< io.dino.myapi:myapi >---------------------- [INFO] Building myapi 0.0.1-SNAPSHOT [INFO] --------------------------------[ war ]--------------------------------- [INFO] [INFO] --- jasypt-maven-plugin:3.0.5:encrypt-value (default-cli) @ myapi --- [INFO] Starting MavenCli v3.6.2 using Java 11 on MyComputer with PID 11960 (C:\Maven\apache-maven-3.6.2\bin..\lib\maven-embedder-3.6.2.jar started by DINO in C:\Dev\intelliJUltimateDev\myapi) [INFO] The following 1 profile is active: "dev" [INFO] Post-processing PropertySource instances [INFO] Skipping PropertySource configurationProperties [class org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource [INFO] Converting PropertySource systemProperties [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper [INFO] Converting PropertySource systemEnvironment [org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource] to EncryptableSystemEnvironmentPropertySourceWrapper [INFO] Converting PropertySource random [org.springframework.boot.env.RandomValuePropertySource] to EncryptablePropertySourceWrapper [INFO] Converting PropertySource Config resource 'file [src\main\resources\application-dev.properties]' via location 'optional:file:./src/main/resources/' [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper [INFO] Converting PropertySource Config resource 'file [src\main\resources\application.properties]' via location 'optional:file:./src/main/resources/' [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper [INFO] Converting PropertySource defaultProperties [org.springframework.boot.DefaultPropertiesPropertySource] to EncryptableMapPropertySourceWrapper [INFO] Started MavenCli in 1.709 seconds (JVM running for 5.333) [INFO] Active Profiles: dev [INFO] Encrypting value dino [INFO] String Encryptor custom Bean not found with name 'jasyptStringEncryptor'. Initializing Default String Encryptor [INFO] Encryptor config not found for property jasypt.encryptor.algorithm, using default value: PBEWITHHMACSHA512ANDAES_256 [INFO] Encryptor config not found for property jasypt.encryptor.key-obtention-iterations, using default value: 1000 [INFO] Encryptor config not found for property jasypt.encryptor.pool-size, using default value: 1 [INFO] Encryptor config not found for property jasypt.encryptor.provider-name, using default value: null [INFO] Encryptor config not found for property jasypt.encryptor.provider-class-name, using default value: null [INFO] Encryptor config not found for property jasypt.encryptor.salt-generator-classname, using default value: org.jasypt.salt.RandomSaltGenerator [INFO] Encryptor config not found for property jasypt.encryptor.iv-generator-classname, using default value: org.jasypt.iv.RandomIvGenerator [INFO] Encryptor config not found for property jasypt.encryptor.string-output-type, using default value: base64 [INFO] ENC(XRrHC3eQTPUkKgyV4e4LzeBLzHEok...) [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.977 s [INFO] Finished at: 2023-01-29T15:43:44-08:00 [INFO] ------------------------------------------------------------------------ [WARNING] The requested profile "sbx" could not be activated because it does not exist. Exception in thread "SpringApplicationShutdownHook" java.lang.NoClassDefFoundError: ch/qos/logback/core/util/ContextUtil at ch.qos.logback.core.FileAppender.stop(FileAppender.java:146) at ch.qos.logback.core.rolling.RollingFileAppender.stop(RollingFileAppender.java:149) at ch.qos.logback.core.spi.AppenderAttachableImpl.detachAndStopAllAppenders(AppenderAttachableImpl.java:107) at ch.qos.logback.classic.Logger.detachAndStopAllAppenders(Logger.java:206) at ch.qos.logback.classic.Logger.recursiveReset(Logger.java:331) at ch.qos.logback.classic.LoggerContext.reset(LoggerContext.java:223) at ch.qos.logback.classic.LoggerContext.stop(LoggerContext.java:348) at org.springframework.boot.logging.logback.LogbackLoggingSystem.lambda$getShutdownHandler$0(LogbackLoggingSystem.java:284) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.boot.SpringApplicationShutdownHook.run(SpringApplicationShutdownHook.java:116) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.util.ContextUtil at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50) at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)

As you can see, the value is encrypted, but then the error happens

LiamAttardcol commented 1 year ago

Hi did you resolve the issue?

melkhazen commented 1 year ago

any updates on this issue?

pwils025 commented 9 months ago

Any update on this issue?

This is related to the plugin. Rolling back to version 3.0.3 of the plugin doesn't throw this exception but version 3.0.4 and 3.0.5 do. com.github.ulisesbocchio:jasypt-maven-plugin:3.0.3

dbnex14 commented 8 months ago

I decided to move on and not use jasypt at all

AsrafulAsif commented 7 months ago

I decided to move on and not use jasypt at all

then what should you use ?

ulisesbocchio commented 7 months ago

It looks like you have a version mismatch between logback core and spring. Or you don’t have logback core at all in the classpath

dbnex14 commented 7 months ago

I decided to move on and not use jasypt at all

then what should you use ?

In our case, developers deploy apps to their local container. Infrastructure deploys to their Ava devs have no visibility to infrastructure containers. For that reason, we use nothing sunce credentials used on our local containers are test credentials and are different from the ones used by infrastructure teams. So as long as we have same keys, the values app uses are unimportant. As a container we use OpenLiberty but that is unimportant. So, I have my local, in jar application.yml with key/value settings so uses ifrun in embedded tomcat. I do the same application.yml file in the root of my local OpenLiberty root or root/config directory ABS spring will auto pick it up from there and override in jar application.yml (or properties). This overwrites application.yml in jar. Infrastructure team does the same but change sensitive credentials etc to values only they know hence no need for this library. So, I might have password =test but infrastructure can have password =xyz4583fh for example and developers don’t know it. Google for ConfigurationProperties annotation in spring boot for this if you are not familiar. It explains how to externalizer your properties which is what I explained above. Hope that helps.

AsrafulAsif commented 7 months ago

can you provide some articles regarding the solution, It really helps for us who need ??

dbnex14 commented 7 months ago

can you provide some articles regarding the solution, It really helps for us who need ??

can you provide some articles regarding the solution, It really helps for us who need ??

Yes, Google for ConfigurationProperties . As I explained above, that will help you

AsrafulAsif commented 7 months ago

thanks man!!