Upgrade to grails 2.3.5 : validator exception - grails

Since the upgrade to grails 2.3.5, a strange behaviour of the hibernate plugin (moved from version 3.6.10.6 to 3.6.10.7) results in a bean error at runtime:
14-01-22 16:22:54,064 ERROR [GrailsContextLoader] - Error initializing the application: Error creating bean with name 'xxx.xxxx.StatisticsValidator': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.codehaus.groovy.grails.orm.hibernate.validation.HibernateDomainClassValidator.setProxyHandler(org.codehaus.groovy.grails.support.proxy.ProxyHandler); nested exception is java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.determineCommonAncestor(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Class;
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.xxx.xxxx.StatisticsValidator': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.codehaus.groovy.grails.orm.hibernate.validation.HibernateDomainClassValidator.setProxyHandler(org.codehaus.groovy.grails.support.proxy.ProxyHandler); nested exception is java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.determineCommonAncestor(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Class;
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.codehaus.groovy.grails.orm.hibernate.validation.HibernateDomainClassValidator.setProxyHandler(org.codehaus.groovy.grails.support.proxy.ProxyHandler); nested exception is java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.determineCommonAncestor(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Class;
Here is the Statistics domain class which is concerned, even if nothing has been changed since grails 2.3.4:
class Statistics implements Serializable {
static belongsTo = [profile: Profile]
Profile profile
String email
String dbkey
String clientCode
String affiliatesNbr
String freeStorageBonus
String freeUsersBonus
String storageUsed
String storageAvailable
String quotaUsersCurrent
String quotaUsersAvailable
String comments
Date processedDate
static constraints = {
profile unique: true, nullable: false, blank: false
email email: true, maxSize: 80, nullable: false, blank: false
dbkey maxSize: 80, nullable: false, blank: false
clientCode maxSize: 40, nullable: false, blank: false
affiliatesNbr maxSize: 40, nullable: true, blank: true
freeStorageBonus maxSize: 40, nullable: true, blank: true
freeUsersBonus maxSize: 40, nullable: true, blank: true
storageUsed maxSize: 40, nullable: true, blank: true
storageAvailable maxSize: 40, nullable: true, blank: true
quotaUsersCurrent maxSize: 40, nullable: true, blank: true
quotaUsersAvailable maxSize: 40, nullable: true, blank: true
comments maxSize: 180, nullable: true, blank: true
processedDate nullable: true, blank: true
}
Below the list of plugins used:
plugins {
build ":tomcat:7.0.50"
runtime ":hibernate:3.6.10.7"
runtime ":database-migration:1.3.8"
runtime ":resources:1.2.1"
runtime ":jquery:1.8.3" //jquery:1.10.2
compile ":scaffolding:2.0.1"
compile ":cache:1.1.1"
compile ":bean-fields:1.0"
compile ":csv:0.3.1"
compile ":famfamfam:1.0.1"
compile ":form-helper:0.2.8"
compile ":google-chart:0.5.2"
compile ":google-visualization:0.6.2"
compile ":jcaptcha:1.2.1"
compile ":jdbc-pool:7.0.47"
compile ":jquery-ui:1.8.24"
compile ":navigation:1.3.2"
compile ":quartz:1.0.1" //1.0.1
compile ":richui:0.8"
compile ":spring-security-core:2.0-RC2"
compile ":webflow:2.0.8.1"
compile ":rendering:0.4.4"
compile ":modernizr:2.7.1.1"
compile ":spring-security-acl:2.0-RC1"
compile ":pdf-viewer:0.1"
compile ":taggable:1.0.1"
compile ":executor:0.3"
compile ":gmetrics:0.3.1"
compile ":lesscss-resources:1.3.3"
compile ":pretty-size:0.2"
compile ":mysql-connectorj:5.1.22.1"
compile ":font-awesome-resources:4.0.3.0"
compile ":aws-sdk:1.6.12"
compile ":aws:1.6.7.5"
}

Related

Constraint "display: false" not working Grails 5

According to the documentation:
http://docs.grails.org/latest/ref/Constraints/Usage.html
a display: constraint should control whether a property is displayed in views.
Example:
static constraints = {
username(nullable: false, blank: false, unique: true)
password(nullable: false, blank: false, password: true)
firstname(nullable: true, blank: true)
surname(nullable: true, blank: true)
mail(nullable: true, blank: true)
lastLogged(nullable: true, blank: true, display: false)
}
Looking at the code above, last logged column should not be present in the view, however the column is still there.
Environment Information: grails 5
Can someone give me a hint why the constraint is not working as it should?
Thanks in advance.

Jasypt not encrypting in Grails 2.5.4

I wanted to use encryption to encrypt user data in Grails 2.5.4 application. I followed the instructions on downloading configuring the 1.3.1 version of plugin.
Updated my Java Security JCE files in JDK 1.8 (both in JDK jre and standalone JRE directories).
I found some posts here which were similar and applied the fixes like the
lower case i in configFIlePath.
def configFilePath = System.getenv('ENCRYPTION_CONFIG_LOCATION') ?: "file:${userHome}"
configFilePath += "/.jasypt.groovy"
grails.config.locations = [configFilePath]
I also tried with configuration inside the Config.groovy
jasypt {
algorithm = "PBEWITHSHA256AND256BITAES-CBC-BC"
providerName = "BC"
password = "test"
keyObtentionIterations = 1000
}
My domain object is defined as follows:
package com.xyz
import java.util.Date;
import com.bloomhealthco.jasypt.*
class UserProfile {
String firstName
String lastName
Date dateOfBirth
// USATT membership information
long usattID
Date expirationDate
// contact information
String email
String phone
String streetAddress
String city
String state
String zipCode
String country
String gender
String club
// no reference to SecUser
static belongsTo = SecUser
static hasMany = [tournamentEntries: TournamentEntry]
static constraints = {
firstName blank: false, maxSize: 384, type: GormEncryptedStringType
lastName blank: false, maxSize: 384, type: GormEncryptedStringType
dateOfBirth blank: false
gender blank: false, type: GormEncryptedStringType
email blank: false, maxSize: 384, type: GormEncryptedStringType
phone blank: false, maxSize: 384, type: GormEncryptedStringType
streetAddress blank: false, maxSize: 384, type: GormEncryptedStringType
city blank: false, maxSize: 384, type: GormEncryptedStringType
state blank: false, type: GormEncryptedStringType
zipCode blank: false, type: GormEncryptedStringType
country blank: false, maxSize: 384, type: GormEncryptedStringType
expirationDate nullable: true
}
}
No matter what I try the data in my Domain object is not getting encrypted as far as I can tell by viewing it via Grails dbconsole application.
I turned on debug logging but don't see any logs from jasypt.
I suspect the main issue is the use of type within your constraints and not within mapping as the documentation explains.
I'd recommend you change you constraints to look like this:
static constraints = {
firstName blank: false, maxSize: 384
lastName blank: false, maxSize: 384
dateOfBirth blank: false
gender blank: false
email blank: false, maxSize: 384
phone blank: false, maxSize: 384
streetAddress blank: false, maxSize: 384
city blank: false, maxSize: 384
state blank: false
zipCode blank: false
country blank: false, maxSize: 384
expirationDate nullable: true
}
And add mappings just after the constraints like this:
static mapping = {
firstName type: GormEncryptedStringType
lastName type: GormEncryptedStringType
gender blank: false, type: GormEncryptedStringType
email type: GormEncryptedStringType
phone type: GormEncryptedStringType
streetAddress type: GormEncryptedStringType
city type: GormEncryptedStringType
state type: GormEncryptedStringType
zipCode blank: false, type: GormEncryptedStringType
country type: GormEncryptedStringType
}

Jaydata web api with OData provider -- provider fallback failed error

I'm developing an application with jaydata, OData and web api. Source code is given below:
$(document).ready(function () {
$data.Entity.extend('$org.types.Student', {
Name: { type: 'Edm.String', nullable: false, required: true, maxLength: 40 },
Id: { key: true, type: 'Edm.Int32', nullable: false, computed: false, required: true },
Gender: { type: 'Edm.String', nullable: false, required: true, maxLength: 40 },
Age: { type: 'Edm.Int32', nullable: false, required: true, maxLength: 40 }
});
$data.EntityContext.extend("$org.types.OrgContext", {
Students: { type: $data.EntitySet, elementType: $org.types.Student },
});
var context = new $org.types.OrgContext({ name: 'OData', oDataServiceHost: '/api/students' });
context.onReady(function () {
console.log('context initialized.');
});
});
In above JavaScript code, I defined an entity named Student. In context.onReady() method, I'm getting the following error:
Provider fallback failed! jaydata.min.js:100
Any idea, how I could get rid of this error??
As per suggested solution, I tried to change the key from required to computed. But sadly its still giving the same error. Modified code is given below.
$(document).ready(function () {
$data.Entity.extend('Student', {
Id: { key: true, type: 'int', computed: true },
Name: { type: 'string', required: true}
});
$data.EntityContext.extend("$org.types.OrgContext", {
Students: { type: $data.EntitySet, elementType: Student },
});
var context = new $org.types.OrgContext({
name: 'OData',
oDataServiceHost: '/api/students'
});
context.onReady(function () {
console.log('context initialized.');
});
});
I thinks the issue is with Odata provider because I tried the same code with indexdb provider and its working properly.
The issue is caused by the value oDataServiceHost parameter. You should configure it with the service host, not with a particular collection of the service. I don't know if the provider name is case-sensitive or not, but 'oData' is 100% sure.
For WebAPI + OData endpoints the configuration should look like this:
var context = new $org.types.OrgContext({
name: 'oData',
oDataServiceHost: '/odata'
});

Grails - creation of inheritor domain class

I have created two domain classes like below:
Component:
class Component {
String name;
Integer orderOfComponent;
Boolean limitedAccess;
Date dateCreated;
String alignment;
String type;
static belongsTo = [subpage: Subpage]
static constraints = {
name nullable: false, blank: false;
orderOfComponent nullable:false, blank: false;
limitedAccess nullable: true, blank: true;
alignment nullable: true, blank: true, inList: ["left", "right", "center", ""];
type nullable: false, blank: false, inList: ["text", "image", "document", "html"];
subpage nullable: false, blank: false;
}
}
Text:
class Text extends Component {
String text;
String color;
String additionalStyle;
String textType;
String link;
static constraints = {
text nullable: true, blank: true;
color nullable: true, blank: true;
additionalStyle nullable: true, blank: true;
textType nullable: true, blank: true, inList: ["p", "h1", "h2", "h3", ""];
link nullable: true, blank: true;
}
}
Everything is fine when I create instance of Component class:
new Component(name: "component" + i, orderOfComponent: i, limitedAccess: new Boolean(false), alignment: "right", type: "text", subpage: Subpage.get(1)).save(flush:true, failOnError:true);
But I get Error when I try to do similar for Text class:
new Text(name: "componentText",
orderOfComponent: 0,
limitedAccess: new Boolean(false),
alignment: "right",
type: "text",
subpage: Subpage.get(1),
text: "asdasdasdasd",
color: "#0F0C0A",
additionalStyle: "",
textType: "p",
link: "http://google.pl").save(flush:true, failOnError:true);
Error:
Error 2014-01-28 02:27:10,453 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Validation Error(s) occurred during save():
- Field error in object 'adminpanel.component.Text' on field 'type': rejected value [null]; (...)
And also very similar "Message".
Does someone know why I cannot create an instance of the Text class or how to use constructor of inheritor class properly? Thanks in advance.

Issue with uninstalling spring-security-ldap plugin

I have a frustrating situation I cannot understand. I am developing an application using the Grails framework (Version: 3.4.0.RELEASE). I used the spring-security-core(1.2.7.3) and spring-security-ldap(1.0.6) plugins to manage credentials. I uninstall the ldap plugin, and for some reason it causes errors. Now when I try to run the project it gives me java errors for one of my groovy classes, such as "...java:15: ')' expected..." or "...java:15: ';' expected...". Everything ran great until I uninstall the ldap plugin. During compile it says "Compile error during compilation with javac". What's happening here? Let me know if I need to show some other code. And this is during runtime. There are no errors showing. I'm in such a hurry to finish the project that each time I get this problem I just create a new project and it runs fine. Just trying to avoid that as I progress in the project
EDIT:
Console output
| Loading Grails 2.2.4
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application....
| Compiling 21 source files.
| Error Compilation error: startup failed:
Compile error during compilation with javac.
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: ')' expected
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: ';' expected
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: illegal start of expression
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: ';' expected
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: illegal start of expression
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: not a statement
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: not a statement
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: ';' expected
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: cannot find symbol
symbol : class util
location: package java
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: cannot find symbol
symbol : class lang
location: package java
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: cannot find symbol
symbol : constructor User(java.lang.String,java.lang.String,boolean,boolean,boolean,boolean,boolean)
location: class org.springframework.security.core.userdetails.User
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: package security does not exist
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
Note: C:\projects\new portal project\InfinityPortalIntranet\src\java\com\example\ldap\AuthenticateUser.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
12 errors`
EDIT 2:
MyUserDetails.Groovy
package com.example.ldap
import org.springframework.security.core.GrantedAuthority
import org.springframework.security.core.userdetails.User
class MyUserDetails extends User {
// extra instance variables
final String fullname
final String email
final String title
final String firstName
final String lastName
MyUserDetails(String username, String password, boolean enabled, boolean accountNonExpired,
boolean credentialsNonExpired, boolean accountNonLocked,
Collection<GrantedAuthority> authorities,
String fullname, String email, String title, String firstName, String lastName) {
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked,
authorities)
this.fullname = fullname
this.email = email
this.title = title
this.firstName = firstName
this.lastName = lastName
}
}

Resources