BouncyCastle and Scala Configuration File with Grails
Recently, I finish a task about bouncy castle and scala jar dependencies with configuration file. Certainly, I met some problem. So I made a note here.
1. BouncyCastle Security Provider
First, I need to made some changes to my files under JAVA_HOME to enable the security provider.
Here is the JAVA_HOME directory in my MAC pro.
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
And I need to download bcprov-jdk16-1.46.jar and copy it to my directory
$JAVA_HOME/lib/ext
Then I need to edit the security file here.
$JAVA_HOME/lib/security/java.security
Adding the follow lines:
security.provider.11=org.bouncycastle.jce.provider.BouncyCastleProvider
2. Version Conflict
But I still get some error messages as follow:
Error Message 1:
Exception while try to send push notifications at user time:
java.lang.IllegalArgumentException: org.bouncycastle.jce.provider.symmetric
at java.lang.ClassLoader.definePackage(ClassLoader.java:1451)
at java.net.URLClassLoader.definePackage(URLClassLoader.java:348)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:249)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
alternatively, sometimes error message is as follow:
Error Message 2:
java.lang.IllegalArgumentException: org.bouncycastle.jcajce.provider.symmetric
at java.lang.ClassLoader.definePackage(ClassLoader.java:1451)
at java.net.URLClassLoader.definePackage(URLClassLoader.java:348)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:249)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at org.codehaus.groovy.tools.RootLoader.oldFindClass(RootLoader.java:152)
at org.codehaus.groovy.tools.RootLoader.loadClass(RootLoader.java:124)
at org.codehaus.groovy.grails.cli.support.GrailsRootLoader.loadClass(GrailsRootLoader.java:43)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.bouncycastle.jce.provider.BouncyCastleProvider.loadAlgorithms(Unknown Source)
at org.bouncycastle.jce.provider.BouncyCastleProvider.setup(Unknown Source)
at org.bouncycastle.jce.provider.BouncyCastleProvider.access$000(Unknown Source)
Solution:
I google for a while, but still I can not find any useful answer. So I begin to read the source codes of bouncy castle. I found that it should be version conflict. Since the package name changes from version 1.5 to 1.6. The version information are as follow:
1.5
org/bouncycastle/jcajce/provider/symmetric/
1.6
org/bouncycastle/jce/provider/symmetric/
And I got 2 different version of jars under my war/WEB-INF/lib directory. They are installed from the ivy plugin.
/Users/carl/.ivy2/cache/org.bouncycastle/bcprov-jdk15on
/Users/carl/.ivy2/cache/org.bouncycastle/bcprov-jdk16
So my solution is to exclude them in my war packages. Since I am using grails in this project. I will do like this.
In the BuildConfig.groovy file, put something like this under dependencies as follow:
…snip…
dependencies {
runtime('com.sillycat:projectname_api_2.10:0.1.6'){
excludes([ group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '147'],
[ group: 'org.bouncycastle', name: 'bcprov-jdk16', version: '1.46'])
}
}
That fix the problem.
3. Publish my Scala jar to Local Maven
>sbt publish-local
This will publish the jar package to ivy local directory.
Change the build.sbt as follow:
publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository"))
>sbt publish
This will publish the jar package to maven local directory.
4. Grails Running Configuration
The reference.conf is inside the jar package, sometimes, we need to overwrite some items in that, so we try to create a file named application.conf and run the command as follow:
>export GRAILS_OPTS="-Dconfig.file=/Users/carl/project/conf/application.conf -Xms256m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=512m"
>grails run-app
And one more tip, if you grails ORM tells you that
013-07-17 16:45:00,369 [pool-1-thread-41] ERROR org.hibernate.LazyInitializationException - could not initialize proxy - no Sessionex org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at Skipped non-Digby elements.(:35)
Make sure you place (lazy: false) in the object property.
References:
BouncyCastle and Scala Configuration File with Grails
最新推荐文章于 2022-03-09 14:35:56 发布
本文详细介绍了在使用Grails项目时遇到BouncyCastle安全提供者与Scala依赖冲突的问题,并通过排除特定版本的jar包解决了错误。同时,文章还指导如何将Scala jar包发布到本地Maven仓库,并调整Grails运行配置以避免LazyInitializationException错误。
3万+

被折叠的 条评论
为什么被折叠?



