how to code the Url for oracle database in grails dataSource.config - oracle

I'm trying to connect from grails to oracle 10gXE.
All over the net I only find a Url for localhost:
url = "jdbc:oracle:thin:#localhost:1521:XE"
But I need to connect to a host in my local network
I can ping it successfully with ping 192.168.2.128
but
url = "jdbc:oracle:thin:#192.168.2.128:1521:XE"
ends up with:
Error 2014-12-22 14:26:23,612 [localhost-startStop-1] ERROR pool.ConnectionPool - Unable to create initial connections of pool.
Message: E/A-Exception: The Network Adapter could not establish the connection
Line | Method
->> 112 | throwSqlException in oracle.jdbc.driver.DatabaseError
| 146 | throwSqlException in ''
| 255 | throwSqlException in ''
| 387 | logon in oracle.jdbc.driver.T4CConnection
| 414 | <init> . . . . . in oracle.jdbc.driver.PhysicalConnection
| 165 | <init> in oracle.jdbc.driver.T4CConnection
| 35 | getConnection . . in oracle.jdbc.driver.T4CDriverExtension
| 801 | connect in oracle.jdbc.driver.OracleDriver
| 262 | run . . . . . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
peter
Dortmund Germany
ps.
my complete Data source:
dataSource {
pooled = true
driverClassName = "oracle.jdbc.OracleDriver"
dialect = "org.hibernate.dialect.Oracle10gDialect"
username = "peter"
password = "wuffwuff"
}
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop','update'
url = "jdbc:oracle:thin:#192.168.2.128:1521:XE"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:oracle:thin:#192.168.2.128:1521:XE"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:oracle:thin:#192.168.2.128:1521:XE"
username = "peter"
password = "wuffwuff"
}
}
}

Related

Import class PowerShell5 module

I've created some classes, which I would like to split into several files. Unfortunately, the inheritance does not work. My only working solution is:
Using Module "<Path>"
That is not flexible and a nightmare for adjustments.
My test folder structure looks like this:
Project
|
+-- classes
| |
| +-- domain
| | |
| | +---Domain.psm1
| |
| +-- dns
| |
| +--DNS.psm1
|
|
+-- functions
|
+-- test
|
+-- test.ps1
My current approach including classes is mentioned here:
https://info.sapien.com/index.php/scripting/scripting-classes/import-powershell-classes-from-modules
Domain.psm1:
class Domain
{
[string] fullname () {
return "test.local";
}
static [Domain] $instance
static [Domain] GetInstance() {
if ($null -eq [Domain]::instance) {
[Domain]::instance = [Domain]::new()
}
return [Domain]::instance
}
}
DNS.psm1:
# Working:
#using module "C:\Users\test\Desktop\Project\classes\domain\Domain.psm1"
# Not working:
$scriptDir = Join-Path -Path $PSScriptRoot -ChildPath ..\.. -Resolve
$classFile = -join($scriptDir, "\classes\domain\Domain.psm1")
$scriptBody = "using module $classFile"
$script = [ScriptBlock]::Create($scriptBody)
. $script
class DNS : Domain
{
[int] testRecord() {
return 9000;
}
# Init Singleton
static [DNS] $instance
static [DNS] GetInstance() {
if ($null -eq [DNS]::instance)
{
[DNS]::instance = [DNS]::new()
}
return [DNS]::instance
}
}
test.ps1:
$scriptDir = Join-Path -Path $PSScriptRoot -ChildPath ..\.. -Resolve
$classFile = -join($scriptDir, "\classes\dns\DNS.psm1")
# Working:
# Include DNS.psm1
$scriptBody = "using module $classFile"
$script = [ScriptBlock]::Create($scriptBody)
. $script
$task = [DNS]::GetInstance()
$task.testRecord()
$task.fullname()
In my test.ps1 I create an instance of the DNS class which extends the Domain class. Extending Domain fails with:
+ . $script
+ ~~~~~~~~~
+ CategoryInfo : InvalidOperation: (C:\Users\test...\dns\DNS.psm1:String) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Is there an easy way to get this working ?

Grails Login Not Working

I am using Grails 2.4 with spring security
compile "org.grails.plugins:spring-security-core:2.0.0"
The following is my bootstrap.groovy
import com.aarestu.grailstest.Role
import com.aarestu.grailstest.User
import com.aarestu.grailstest.UserRole
class BootStrap {
def init = { servletContext ->
def user = new User(usernmae: 'user', password: 'user').save(flush: true, failOnError: true)
def userSecond = new User(usernmae: 'user2', password: 'user').save(flush: true, failOnError: true)
def admin = new User(usernmae: 'admin', password: 'admin').save(flush: true, failOnError: true)
def userRole = new Role(authority: 'ROLE_USER').save(flush: true, failOnError: true)
def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true, failOnError: true)
new UserRole(user: user, role: userRole).save(flush: true, failOnError: true)
new UserRole(user: admin, role: adminRole).save(flush: true, failOnError: true)
}
def destroy = {
}
}
It created 2 entries into the table Role but none of the others.
I then manually created a user in the database and when I try to login with the user it simply doesnt work even though I can view it in the database.
If the
failOnError:true
Is not included then it runs ok but I cannot login, if it is included I get the error included at the very end
I also accounted for the double encoding by modifying my USER controller to include the following
boolean beforeInsertRunOnce = false
boolean beforeUpdateRunOnce = false
Set<Role> getAuthorities() {
UserRole.findAllByUser(this)*.role
}
def beforeInsert() {
if (! beforeInsertRunOnce) {
beforeInsertRunOnce = true
encodePassword()
}
}
def afterInsert() {
beforeInsertRunOnce = false
}
def beforeUpdate() {
if (isDirty('password') && ! beforeUpdateRunOnce ) {
beforeUpdateRunOnce = true
encodePassword()
}
}
def afterUpdate() {
beforeUpdateRunOnce = false
}
Error
Error |
2016-02-09 11:42:58,434 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the application: Validation Error(s) occurred during save():
- Field error in object 'com.aarestu.grailstest.User' on field 'username': rejected value [null]; codes [com.aarestu.grailstest.User.username.nullable.error.com.aarestu.grailstest.User.username,com.aarestu.grailstest.User.username.nullable.error.username,com .aarestu.grailstest.User.username.nullable.error.java.lang.String,com.aarestu .grailstest.User.username.nullable.error,user.username.nullable.error.com.aar estu.grailstest.User.username,user.username.nullable.error.username,user.user name.nullable.error.java.lang.String,user.username.nullable.error,com.aarestu .grailstest.User.username.nullable.com.aarestu.grailstest.User.username,com.aarestu.grailstest.User.username.nullable.username,com.aarestu.grailstest.User.username.nullable.java.lang.String,com.aarestu.grailstest.User.username.nullable,user.username.nullable.com.aarestu.grailstest.User.username,user.username.nullable.username,user.username.nullable.java.lang.String,user.username.nullable,nullable.com.aarestu.grailstest.User.username,nullable.username,nullable.java.lang.String,nullable]; arguments [username,class com.aarestu.grailstest.User]; default message [Property [{0}] of class [{1}] cannot be null]
Message: Validation Error(s) occurred during save():
- Field error in object 'com.aarestu.grailstest.User' on field 'username': rejected value [null]; codes [com.aarestu.grailstest.User.username.nullable.error.com.aarestu.grailstest.User.username,com.aarestu.grailstest.User.username.nullable.error.username,com .aarestu.grailstest.User.username.nullable.error.java.lang.String,com.aarestu .grailstest.User.username.nullable.error,user.username.nullable.error.com.aarestu.grailstest.User.username,user.username.nullable.error.username,user.username.nullable.error.java.lang.String,user.username.nullable.error,com.aarestu .grailstest.User.username.nullable.com.aarestu.grailstest.User.username,com.aarestu.grailstest.User.username.nullable.username,com.aarestu.grailstest.User .username.nullable.java.lang.String,com.aarestu.grailstest.User.username.nullable,user.username.nullable.com.aarestu.grailstest.User.username,user.username.nullable.username,user.username.nullable.java.lang.String,user.username.nullable,nullable.com.aarestu.grailstest.User.username,nullable.username,nullable.java.lang.String,nullable]; arguments [username,class com.aarestu.grailstest.User]; default message [Property [{0}] of class [{1}] cannot be null]
Line | Method
->> 9 | doCall in BootStrap$_closure1
| 327 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 320 | executeForEnvironment . . . . . in ''
| 296 | executeForCurrentEnvironment in ''
| 266 | run . . . . . . . . . . . . . . in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Error |
Forked Grails VM exited with error
Any help or point in the right direction would be much appreciated
The bootsrap.groovy code was wrong
This following needs to be changed from
def user = new User(usernmae: 'user', password: 'user').save(flush: true, failOnError: true)
def admin = new User(usernmae: 'admin', password: 'admin').save(flush: true, failOnError: true)
Role(user: user, role: userRole).save(flush: true, failOnError: true)
new UserRole(user: admin, role: adminRole).save(flush: true, failOnError: true)
to
def user = new User(username: 'user', password: 'password', enabled: true).save()
def admin = new User(username: 'admin', password: 'password', enabled: true).save()
UserRole.create user, roleUser
UserRole.create admin, roleUser
UserRole.create admin, roleAdmin, true

How to rasie the log level for logs stored in elk stack

Is it possible to raise the log level for logs stored on ELK stack? Now I found all log levels are stored on my elk stack, I only want those warning anf error logs are stored in the stack, how to do that?
I think you're looking for the logstash drop filter, which lets you filter out logs based on some criteria, in your case debug, info and the like. From the docs, a filter might look like:
filter {
if [loglevel] == "debug" {
drop { }
}
}
https://www.elastic.co/guide/en/logstash/current/plugins-filters-drop.html
Also, your question looks similar to this one:
Logstash drop filter for event
If you have a log file test.log like below:
DEBUG | 2008-09-06 10:51:44,817 | DefaultBeanDefinitionDocumentReader.java | 86 | Loading bean definitions
WARN | 2008-09-06 10:51:44,848 | AbstractBeanDefinitionReader.java | 185 | Loaded 5 bean definitions from location pattern [samContext.xml]
INFO | 2008-09-06 10:51:44,848 | XmlBeanDefinitionReader.java | 323 | Loading XML bean definitions from class path resource [tmfContext.xml]
DEBUG | 2008-09-06 10:51:44,848 | DefaultDocumentLoader.java | 72 | Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
ERROR | 2008-09-06 10:51:44,848 | BeansDtdResolver.java | 72 | Found beans DTD [http://www.springframework.org/dtd/spring-beans.dtd] in classpath: spring-beans.dtd
ERROR | 2008-09-06 10:51:44,864 | DefaultBeanDefinitionDocumentReader.java | 86 | Loading bean definitions
DEBUG | 2008-09-06 10:51:45,458 | AbstractAutowireCapableBeanFactory.java | 411 | Finished creating instance of bean 'MS-SQL'
You can define an if conditional on the message you want to keep and drop others:
input {
file {
path => "/your/path/test.log"
sincedb_path => "/your/path/test.idx"
start_position => "beginning"
}
}
filter {
if [message] =~ "WARN" or [message] =~ "ERROR" {
} else {
drop {}
}
}
output {
stdout {
codec => rubydebug
}
}
Then, your result will look like:
{
"message" => "WARN | 2008-09-06 10:51:44,848 | AbstractBeanDefinitionReader.java | 185 | Loaded 5 bean definitions from location pattern [samContext.xml]",
"#version" => "1",
"#timestamp" => "2015-09-17T18:30:24.897Z",
"host" => "MacBook-Pro-de-Alain.local",
"path" => "/Users/Alain/Workspace/elk/logstash-1.5.4/config/filter/test.log"
}
{
"message" => "ERROR | 2008-09-06 10:51:44,848 | BeansDtdResolver.java | 72 | Found beans DTD [http://www.springframework.org/dtd/spring-beans.dtd] in classpath: spring-beans.dtd",
"#version" => "1",
"#timestamp" => "2015-09-17T18:30:24.898Z",
"host" => "MacBook-Pro-de-Alain.local",
"path" => "/Users/Alain/Workspace/elk/logstash-1.5.4/config/filter/test.log"
}
{
"message" => "ERROR | 2008-09-06 10:51:44,864 | DefaultBeanDefinitionDocumentReader.java | 86 | Loading bean definitions",
"#version" => "1",
"#timestamp" => "2015-09-17T18:30:24.899Z",
"host" => "MacBook-Pro-de-Alain.local",
"path" => "/Users/Alain/Workspace/elk/logstash-1.5.4/config/filter/test.log"
}
Regards,
Alain

Grails plugin returning invalid stream header error

I have a Grails app that uses a plugin I have created. Both use Spring-security-core plugin.
My plugin has a domain class, controller and views. Data to display is selected from a line drawn on a map. The data returned is displayed in a list at the bottom of the browser window. I have created a link on one of the fields that is supposed to show the selected record.
When I click this link, however I get the following error:
| Error 2014-05-27 16:14:11,415 [http-bio-8082-exec-6] ERROR errors.GrailsExceptionResolver - StreamCorruptedException occurred when processing request: [GET] /test/bridge/show/661
invalid stream header: 8401FE00. Stacktrace follows:
Message: invalid stream header: 8401FE00
Line | Method
->> 802 | readStreamHeader in java.io.ObjectInputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 299 | <init> in ''
| 55 | show . . . . . . in RIMS.bridge.BridgeController
| 195 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter . . . . in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 49 | doFilter . . . . in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
| 82 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 1145 | runWorker . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . . . . in java.lang.Thread
The code that fails is where I attempt to get the data with the ID in the following action:
#Secured(["hasRole('ROLE_MAP_USER')"])
def show(Long id) {
println "ID: ${id}"
def princObj = springSecurityService?.principal
log.debug "User: ${princObj}"
def bridgeInstance = RIMS.bridge.Bridge.get(id)
if (!bridgeInstance) {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'bridge.label', default: 'Bridge'), id])
redirect(action: "list")
return
}
render(plugin: "nhvr", view:"show", model: [bridgeInstance: bridgeInstance])
}
The returned user, retured at log.debug "User: ${princObj}" is correct and has the required role.
I am not sure how to proceed. Can anyone suggest what to try?
Here is the code for the Bridge class:
package RIMS.bridge
class Bridge {
String bridgeNo
String roadNo
BigDecimal linkNo
BigDecimal chng
String travelDirectionCode
BigDecimal northing
BigDecimal easting
String overUnderCode
Date dateActive
Date dateArchived
String tranUser
Date tranDateTime
String tranType
Serializable obj
String cwayCode
String constructed
static hasMany = [
bridgeClearances: BridgeClearance,
bridgeCulverts: BridgeCulvert,
bridgeDimensions: BridgeDimension,
bridgeDrawings: BridgeDrawing,
bridgeDucts: BridgeDuct,
bridgeHydraulics: BridgeHydraulic,
bridgeMaintenances: BridgeMaintenance,
bridgeMiscellaneouses: BridgeMiscellaneous,
bridgeParts: BridgePart,
bridgeServices: BridgeService,
bridgeSpans: BridgeSpan,
bridgeSubstructures: BridgeSubstructure,
bridgeSuperstructures: BridgeSuperstructure]
static mapping = {
id generator: "assigned"
version false
}
static constraints = {
bridgeNo maxSize: 10
roadNo nullable: true, maxSize: 5
linkNo nullable: true
chng nullable: true
travelDirectionCode maxSize: 10
northing nullable: true
easting nullable: true
overUnderCode maxSize: 10
dateArchived nullable: true
tranUser maxSize: 30
tranType maxSize: 6
obj nullable: true
cwayCode nullable: true, maxSize: 4
constructed nullable: true, maxSize: 3
}
def locateByBridgeNo(String bridgeNo){
println "locating by no: ${bridgeNo}"
withCriteria{
eq('bridgeNo', bridgeNo)
}
}
static listActiveBridges(){
withCriteria(){
isNull('dateArchived')
}
}
static listBridgesByBridgeNo(String bridgeNo){
withCriteria(){
eq('bridgeNo', bridgeNo)
}
}
String toString(){
return "${bridgeNo} Road: ${roadNo}, Link: ${linkNo}, chainage: ${chng}"
}
}

Adding UserProfile to User with Grails and Spring Security. Parameter #7 is not set

I'm having trouble extending the Spring Security User class to include a profile class. The profile class is simple and just holds a list of Strings. When I go to run the application, I'm thrown the following error, Parameter 7 is not set:
| Error 2014-03-20 22:33:26,751 [localhost-startStop-1] ERROR util.JDBCExceptionReporter - Parameter "#7" is not set; SQL statement:
insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [90012-173]
| Error 2014-03-20 22:33:26,815 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Hibernate operation: could not insert: [ibm_cd_dashboard.User]; uncategorized SQLException for SQL [insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?)]; SQL state [90012]; error code [90012]; Parameter "#7" is not set; SQL statement:
insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [90012-173]; nested exception is org.h2.jdbc.JdbcSQLException: Parameter "#7" is not set; SQL statement:
insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [90012-173]
Message: Hibernate operation: could not insert: [ibm_cd_dashboard.User]; uncategorized SQLException for SQL [insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?)]; SQL state [90012]; error code [90012]; Parameter "#7" is not set; SQL statement:
insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [90012-173]; nested exception is org.h2.jdbc.JdbcSQLException: Parameter "#7" is not set; SQL statement:
insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [90012-173]
Line | Method
->> 28 | ensureSave in BootStrap
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 14 | doCall in BootStrap$_closure1
| 308 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 301 | executeForEnvironment in ''
| 277 | executeForCurrentEnvironment . . in ''
| 262 | run in java.util.concurrent.FutureTask
| 1145 | runWorker . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run . . . . . . . . . . . . . . in java.lang.Thread
Caused by JdbcSQLException: Parameter "#7" is not set; SQL statement:
insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [90012-173]
->> 331 | getJdbcSQLException in org.h2.message.DbException
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 171 | get in ''
| 148 | get . . . . . . . . . . . . . . in ''
| 80 | checkSet in org.h2.expression.Parameter
| 163 | checkParameters . . . . . . . . in org.h2.command.Prepared
| 78 | update in org.h2.command.CommandContainer
| 235 | executeUpdate . . . . . . . . . in org.h2.command.Command
| 154 | executeUpdateInternal in org.h2.jdbc.JdbcPreparedStatement
| 140 | executeUpdate . . . . . . . . . in ''
| 28 | ensureSave in BootStrap
| 14 | doCall . . . . . . . . . . . . . in BootStrap$_closure1
| 308 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 301 | executeForEnvironment . . . . . in ''
| 277 | executeForCurrentEnvironment in ''
| 262 | run . . . . . . . . . . . . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
| Error 2014-03-20 22:33:27,071 [Thread-13] ERROR hbm2ddl.SchemaExport - schema export unsuccessful
Message: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-173]
Line | Method
->> 331 | getJdbcSQLException in org.h2.message.DbException
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 171 | get in ''
| 148 | get . . . . . . . . in ''
| 137 | get in ''
| 1413 | checkClosed . . . . in org.h2.jdbc.JdbcConnection
| 1388 | checkClosed in ''
| 428 | getAutoCommit . . . in ''
^ 744 | run in java.lang.Thread
User Profile:
class UserProfile {
static hasOne = [user:User]
static belongsTo = User
static constraints = {
}
static mapping = {
}
List<String> projects
}
User is basically the standard spring class:
class User {
transient springSecurityService
static hasOne = [userProfile:UserProfile]
String username
String password
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static transients = ['springSecurityService']
static constraints = {
username blank: false, unique: true
password blank: false
userProfile unique:true, nullable: true
}
static mapping = {
password column: '`password`'
}
Set<Role> getAuthorities() {
UserRole.findAllByUser(this).collect { it.role } as Set
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}
}
Bootstrap:
def init = { servletContext ->
def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
def userRole = new Role(authority: 'ROLE_USER').save(flush: true)
def testUser = new User(username: 'me', password: 'password', userProfile: null)
ensureSave(testUser)
testUser.userProfile = new UserProfile(projects: null, version: null, user: testUser)
ensureSave(testUser)
UserRole.create testUser, adminRole, true
assert User.count() == 1
assert Role.count() == 2
assert UserRole.count() == 1
}
def ensureSave(domainObject) {
if(!domainObject.save(flush:true)) {
throw new Exception("not saved successfully: $domainObject");
}
domainObject
}
Removing the associations between the User and UserProfile class allows the application to run normally. Playing around wiht the code I've also gotten "Parameter #4 is not set". Any help appreciated.
This kind off error usually happens, when you have submitted a null value, for a not-null field. Please check data in your domain objects before save, for null values.
Also please remove static hasOne = [user:User] association from Userprofile. The belongsTo is just fine here.
I was able to successfully resolve this issue using the help of the comments posted by other users. Here is the updated code.
Bootstrap
class BootStrap {
def init = { servletContext ->
def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
def userRole = new Role(authority: 'ROLE_USER').save(flush: true)
def testUser = new User(username: 'me', password: 'password', userProfile: new UserProfile(projects: null, version: null))
testUser.save(flush: true, failOnError: true)
UserRole.create testUser, adminRole, true
assert User.count() == 1
assert Role.count() == 2
assert UserRole.count() == 1
}
def destroy = {
}
}
UserProfile
class UserProfile {
static belongsTo = [user:User]
static constraints = {
}
static mapping = {
}
List<String> projects
}
User Class:
class User {
transient springSecurityService
static hasOne = [userProfile:UserProfile]
String username
String password
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static transients = ['springSecurityService']
static constraints = {
username blank: false, unique: true
password blank: false
userProfile unique:true, nullable: true
}
static mapping = {
password column: '`password`'
}
Set<Role> getAuthorities() {
UserRole.findAllByUser(this).collect { it.role } as Set
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}
}

Resources