Skip to content

Instantly share code, notes, and snippets.

View sergiomichels's full-sized avatar

Sérgio Michels sergiomichels

View GitHub Profile
@sergiomichels
sergiomichels / Config.groovy
Created November 15, 2012 12:51
Joda Time Plugin, user types
'user-type' type: org.jadira.usertype.dateandtime.joda.PersistentDateMidnight, class: org.joda.time.DateMidnight
'user-type' type: org.jadira.usertype.dateandtime.joda.PersistentDateTime, class: org.joda.time.DateTime
'user-type' type: org.jadira.usertype.dateandtime.joda.PersistentDateTimeZoneAsString, class: org.joda.time.DateTimeZone
'user-type' type: org.jadira.usertype.dateandtime.joda.PersistentDurationAsString, class: org.joda.time.Duration
'user-type' type: org.jadira.usertype.dateandtime.joda.PersistentInstantAsMillisLong, class: org.joda.time.Instant
'user-type' type: org.jadira.usertype.dateandtime.joda.PersistentInterval, class: org.joda.time.Interval
'user-type' type: org.jadira.usertype.dateandtime.joda.PersistentLocalDate, class: org.joda.time.LocalDate
'user-type' type: org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime, class: org.joda.time.LocalDateTime
'user-type' type: org.jadira.usertype.dateandtime.joda.PersistentLocalTime, class: org.joda.time.LocalTime
'user-type' type: org.j
@sergiomichels
sergiomichels / CustomUserDetailsService.groovy
Created November 9, 2012 23:21
Grails - Custom UserDetailsService
import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUserDetailsService
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.core.userdetails.UsernameNotFoundException
import User
class CustomUserDetailsService implements GrailsUserDetailsService {
//this creates a List of GrantedAuthorityImpl
MyAuthoritiesBuilder myAuthoritiesBuilder
@sergiomichels
sergiomichels / Config.groovy
Created November 9, 2012 22:56
How to make spring security ldap optional, and not validate in the database when activated.
//activate or deactivate the plugin
grails.plugins.springsecurity.ldap.active=true
if(grails.plugins.springsecurity.ldap.active) {
// specify this when you want to skip attempting to load from db and only use LDAP
grails.plugins.springsecurity.providerNames = ['ldapAuthProvider', 'anonymousAuthenticationProvider']
}
@sergiomichels
sergiomichels / PasswordChangeCommand.groovy
Created October 16, 2012 02:04
Command Object for control of password change
package com.wordpress.sergiosmind.command
import grails.validation.Validateable;
import groovy.transform.ToString;
@Validateable
@ToString
class PasswordChangeCommand {
//dependency injection for SpringSecurityService
def springSecurityService
@sergiomichels
sergiomichels / DeletesSolution.groovy
Created October 15, 2012 19:48
Groovy Sql & ORA-00903 - Solution
def sql = new Sql(dataSource)
def tables =["myTable1", "myTable2"]
tables.each {tab ->
sql.execute("truncate table ${tab}".toString()) //works!
}
@sergiomichels
sergiomichels / Deletes.groovy
Created October 15, 2012 19:41
Groovy Sql & ORA-00903
def sql = new Sql(dataSource)
def tables =["myTable1", "myTable2"]
tables.each {tab ->
sql.execute("truncate table ${tab}") //ORA-00903 here
}
@sergiomichels
sergiomichels / MyGroovyClass.groovy
Created October 4, 2012 22:24
Load domain class in groovy class
//this will throw ClassNotFoundException
Class clazz = Class.forName(className)
//but this will load the class with success
Class clazz = Class.forName(className, true, Thread.currentThread().contextClassLoader)
@sergiomichels
sergiomichels / CompositeDomainClass.groovy
Created October 4, 2012 03:15
Adjusts in CompositeDomainClass to make it work
class CompositeDomainClass implements Serializable {
//this is part of the pk
MyOtherDomainClass otherDomainClass
//other fields here...
//and we try to map this
static mapping {
table 'composite_table'
//id composite: ['id','otherDomainClass'], column: 'my_code_field'
id composite: ['id','otherDomainClass']
columns {
@sergiomichels
sergiomichels / CompositeDomainClass.groovy
Created October 4, 2012 03:12
Example of using composite primary key
class CompositeDomainClass implements Serializable {
//this is part of the pk
MyOtherDomainClass otherDomainClass
//other fields here...
//and we try to map this
static mapping {
table 'composite_table'
id composite: ['id','otherDomainClass'], column: 'my_code_field'
otherDomainClass(column: 'other_table_id')
}
@sergiomichels
sergiomichels / MyExtendedTagLib.groovy
Created October 4, 2012 02:52
TagLib that overwrite tag and call original
class MyExtendedTagLib {
static namespace = "my"
def grailsApplication
def input = {attrs, body ->
//some custom logic that changes attrs here...
//get the original TagLib, must be the complete path
def myTagLib = grailsApplication.mainContext.getBean("packages.MyTagLib")