I am trying to apply Jasypt plugin in my application to encrypt fields of my table.
here's my code below.
DOMAIN CLASS
import com.bloomhealthco.jasypt.GormEncryptedStringType;
class TestForm {
String name
String age
String gender
static mapping = {
name type: GormEncryptedStringType
age type: GormEncryptedStringType
gender type: GormEncryptedStringType
}
static constraints = {
}
}
BUILDCONFIG
plugins {
// plugins for the build system only
build ":tomcat:7.0.52.1"
// plugins for the compile step
compile ":scaffolding:2.0.2"
compile ':cache:1.1.1'
compile ":jasypt-encryption:1.2.1"
// plugins needed at runtime but not for compilation
runtime ":hibernate:3.6.10.9" //or ":hibernate4:4.3.4"
}
CONFIG
//Database encryption configuration
Jasypt {
algorithm = "PBEWITHSHA256AND256BITAES-CBC-BC"
providerName = "BC"
password = "c3kr37"
keyObtentionIterations = 1000
}
all those i have done in my application, This also successfully downloads jasypt plugin. but when i try to save record it show the following error
Error 500: Internal Server Error
URI:
/grailsTest/testForm/save
Class:
org.jasypt.exceptions.EncryptionInitializationException
Message:
No string encryptor registered for hibernate with name "gormEncryptor"
Hope for the right direction to use this plugin, Thanks in advance.
Related
I am trying to get dependency resolution to work in Grails 2.2 from a custom repository which has username password.
I have tried adding the following in my BuildConfig.groovy
grails.project.dependency.resolver = "maven"
grails.project.ivy.authentication = {
repositories {
mavenRepo('https://maven.companyname.com/repository/repository-name') {
auth([
username: 'myusername',
password: 'mypassword'
])
}
}
}
But I get error like
Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.ConfigSlurper$_parse_closure5.auth() is applicable for argument types: (java.util.LinkedHashMap) values:
I tried looking at https://grails.github.io/grails2-doc/2.2.0/guide/single.html#dependencyRepositories but it does not tell me more information. It does say that I need to put the credentials in settings.groovy but is that absolutely necessary? I tried putting the credentials inside mavenRepo closure but that did not work. Any ideas?
Grails 2 - quite some time ago…
This way it is working here.
BuildConfig.groovy:
…
grails.project.dependency.resolver = "ivy"
grails.project.dependency.resolution = {
repositories {
mavenRepo "https://repo.example.com/myrepo"
}
…
~/.grails/settings.groovy:
…
grails.project.ivy.authentication = {
credentials {
realm = "My Realm"
host = "repo.example.com"
username = "user"
password = "secret"
}
}
…
Using Jms plugin for grails and add dependencies for ActiveMQ worked perfect. No problems.
Now I want to go beyond and perform some customization and fine tuning to make ActiveMQ behaves as I need, so I need to configure the broker instance.
e.g. I want to use JDBC storage.
How is possible to do that with grails and the vm embedded broker?
I've actually followed the reference documentation for the JMS grails plugin ... I add jms plugin and activemq dependencies and place this on resources:
jmsConnectionFactory(SingleConnectionFactory) {
targetConnectionFactory = { ActiveMQConnectionFactory cf ->
//brokerURL = 'vm://localhost'
brokerURL = 'tcp://localhost:61616?jms.useAsyncSend=true'
}
}
As I've said this is fine ... but I need more tuning here, so I've tried to go adding this in the resources, so I can access the broker to fine tuning:
/* Establish the broker */
amq.broker(useJmx: false, persistent: true) {
amq.transportConnectors() {
amq.transportConnector(uri: "tcp://localhost:61616")
}
}
amqConnectionFactory(ActiveMQConnectionFactory) {
brokerURL = "vm://localhost"
}
jmsConnectionFactory(SingleConnectionFactory) {
targetConnectionFactory = ref(amqConnectionFactory)
}
But I start to have dependency problems like:
2015-03-18 13:44:14 - spring.RuntimeSpringConfigUtilities [RuntimeConfiguration] Unable to load beans from resources.groovy
org.springframework.beans.FatalBeanException: NamespaceHandler class [org.apache.xbean.spring.context.v2.XBeanNamespaceHandler] for namespace [http://activemq.apache.org/schema/core] not found; nested exception is java.lang.ClassNotFoundException: org.apache.xbean.spring.context.v2.XBeanNamespaceHandler
So I start adding dependencies:
compile 'org.apache.activemq:activemq-spring:5.7.0'
compile 'org.springframework:spring-beans:4.1.1.RELEASE'
compile 'org.apache.xbean:xbean-spring:4.1'
But still have problems:
java.lang.NoClassDefFoundError: org/springframework/core/OrderComparator$OrderSourceProvider
At this point I get the feeling that I am doing something wrong since I see too much complexity.
Is there a best way to do this?
In order to be able to configure ActiveMQ you'll need:
Dependencies:
compile 'org.apache.activemq:activemq-core:5.7.0'
compile 'org.apache.activemq:activemq-spring:5.7.0'
compile 'org.springframework:spring-beans:4.0.6.RELEASE'
compile 'org.apache.xbean:xbean-spring:4.1'
Resources.groovy:
xmlns amq:"http://activemq.apache.org/schema/core"
...
/* Establish the broker */
amq.broker(useJmx: false, persistent: true) {
amq.transportConnectors() {
amq.transportConnector(uri: "tcp://localhost:61616")
}
//HERE YOU CAN CONFIGURE BROKER
}
amqConnectionFactory(ActiveMQConnectionFactory) {
brokerURL = "vm://localhost"
}
jmsConnectionFactory(SingleConnectionFactory) {
targetConnectionFactory = ref(amqConnectionFactory)
}
The above answer of Rafael is very useful just a small change you need to do if you are working with Grails 3.2.+ it took me few hrs to figure it out.
Depedencies (add them in build.gradle)
compile 'org.grails.plugins:jms:2.0.0.RC2'
compile 'org.apache.activemq:activemq-core:5.7.0'
compile 'org.apache.activemq:activemq-spring:5.14.5'
compile 'org.apache.xbean:xbean-spring:4.1'
Resources.groovy (should look something like)
import org.apache.activemq.ActiveMQConnectionFactory
import org.springframework.jms.connection.SingleConnectionFactory
beans = {
....
xmlns amq:"http://activemq.apache.org/schema/core"
amq.broker(useJmx: false, persistent: true) {
amq.transportConnectors() {
amq.'transportConnector'(uri: "tcp://localhost:61616")
// optional if you want to do something with mqtt
amq.'transportConnector'(uri:'mqtt://0.0.0.0:61612')
}
}
jmsConnectionFactory(SingleConnectionFactory) {
targetConnectionFactory = { ActiveMQConnectionFactory cf ->
brokerURL = 'vm://localhost'
}
}
...
}
I had in the old Config.groovy:
grails.gorm.default.mapping = {
id generator = 'identity'
// send only the dirty fields to the database for updating
dynamicUpdate = true
dynamicInsert = true
}
So I put this in the additionally application.groovy, but it won't be respected any more. All updates are full, sending all fields to the database, even the not changed ones.
I tried to translate this in application.yml:
grails:
gorm:
default:
mapping:
id generator: "identity"
dynamicUpdate: true
dynamicInsert: true
... but still without luck.
With Grails 3.1.10, it works in application.groovy:
dataSource {
//....
}
grails.gorm.default.mapping = {
uuid index:'idx_uuid', type: org.hibernate.type.UUIDCharType, length: 36, defaultValue: null
batchSize 15000
}
but had no sucess either while putting it in application.yml
I am using Grails version 2.2.4 and I have installed kickstart plugin as compile ":kickstart-with-bootstrap:0.9.6".
BuildConfig.groovy
plugins {
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.8.3"
runtime ":resources:1.1.6"
compile ":kickstart-with-bootstrap:0.9.6"
build ":tomcat:$grailsVersion"
runtime ":database-migration:1.3.2"
compile ':cache:1.0.1'
}
I found "KickstartFilters.groovy" filter with following directory structure
plugin
-> kickstart-with-bootstrap:0.9.6
-> conf
-> kickstart
-> KickstartFilters.groovy
my "KickstartFilters.groovy" file contains following information
package kickstart
class KickstartFilters {
def filters = {
all() {
before = {
// Small "logging" filter for controller & actions
log.info(!params.controller ? '/: ' + params : params.controller +"."+(params.action ?: "index")+": "+params)
}
after = {
}
afterView = {
}
}
}
}
while log.info are printed in logs at that time if password is passed as params then password information are visible on log so how can I prevent only password Information?
I have a work around for this...
https://github.com/joergrech/KickstartWithBootstrap/issues/84
Basically create your filter under conf/kickstart/YourAppFilters.groovy
package kickstart
class YourAppFilters extends KickstartFilters {
def filters = {
kickstartLogger() {
before = {
// Small "logging" filter for controller & actions
if (log.infoEnabled) {
if (!params.controller.equals('chat')) {
if (!params.password ) {
log.info(!params.controller ? '/: ' + params : params.controller +"."+(params.action ?: "index")+": "+params)
}else{
log.info (params.controller+","+params.action+":"+params?.username)
}
}
}
}
}
}
}
Now under conf/spring/resources.groovy under beans add:
yourAppFilters(KickstartFilters)
This should now override kickstarts filter
I installed the Grails JMS pluign into my application, but am not receiving any messages. My config is as follows:
In resources.groovy
jmsConnectionFactory(package.OracleAqFactoryBean) {
dataSource = ref("dataSource")
}
In config.groovy
jms {
containers {
standard {
autoStartup = true
connectionFactoryBean = "jmsConnectionFactory"
}
}
}
In my Grails Service:
class MyService {
static exposes = ["jms"]
static destination = "queuename"
static listenerCount = 5
void onMessage(msg) {
// handle message
println "WE GOT A MESSAGE...."
}
}
In Datasource.groovy
dataSource {
driverClassName = "oracle.jdbc.pool.OracleDataSource"
url = "jdbc:oracle:thin:#restofurl"
username = "xxx"
password = "xxxx"
}
We have a connection to the queue working using standard Spring config in a standard Java app, but that spring config does not work if imported in the Grails app, which is why we are trying to use the jms plugin.