Custom UserDetails class throws MappingException

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom UserDetails class throws MappingException

emiles
Created custom UserDetails domain class and UserDetailsService class according to docs. Worked fine with version 1.3.7. Upgraded to 2.0.0, then 2.0.1, and it threw the following exception with each upgrade. No code changes, just performed upgrades. Thanks in advance. Exception: | Loading Grails 2.0.1 | Configuring classpath. | Environment set to development..... | Packaging Grails application..... | Compiling 2 source files..... | Running Grails application Configuring Spring Security UI ... ... finished configuring Spring Security UI Configuring Spring Security Core ... ... finished configuring Spring Security Core 2012-03-08 01:30:46,364 [ERROR] context.GrailsContextLoader: Error executing bootstraps: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: identifier mapping has wrong number of columns: com.toolcrib.UserDetails type: object org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: identifier mapping has wrong number of columns: com.toolcrib.UserDetails type: object at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: identifier mapping has wrong number of columns: com.toolcrib.UserDetails type: object ... 5 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: identifier mapping has wrong number of columns: com.toolcrib.UserDetails type: object ... 5 more Caused by: org.hibernate.MappingException: identifier mapping has wrong number of columns: com.toolcrib.UserDetails type: object ... 5 more UserDetails class: package com.toolcrib import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser import org.springframework.security.core.GrantedAuthority class UserDetails extends GrailsUser { String fullName static constraints = { } static mapping = { table 'user_details' } UserDetails(String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities, long id, String fullName) { super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities, id) this.fullName = fullName } }
Reply | Threaded
Open this post in threaded view
|

Re: Custom UserDetails class throws MappingException

emiles
More readable version of the first post!

Created custom UserDetails domain class and UserDetailsService class according to docs. Worked fine with version 1.3.7. Upgraded to 2.0.0, then 2.0.1, and it threw the following exception with each upgrade. No code changes, just performed upgrades.

Thanks in advance.


Exception:

| Loading Grails 2.0.1
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Compiling 2 source files.....
| Running Grails application

Configuring Spring Security UI ...
... finished configuring Spring Security UI


Configuring Spring Security Core ...
... finished configuring Spring Security Core

2012-03-08 01:30:46,364 [ERROR] context.GrailsContextLoader: Error executing bootstraps: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: identifier mapping has wrong number of columns: com.toolcrib.UserDetails type: object
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: identifier mapping has wrong number of columns: com.toolcrib.UserDetails type: object
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: identifier mapping has wrong number of columns: com.toolcrib.UserDetails type: object
        ... 5 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: identifier mapping has wrong number of columns: com.toolcrib.UserDetails type: object
        ... 5 more
Caused by: org.hibernate.MappingException: identifier mapping has wrong number of columns: com.toolcrib.UserDetails type: object
        ... 5 more


UserDetails class:

package com.toolcrib

import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser
import org.springframework.security.core.GrantedAuthority

class UserDetails extends GrailsUser {

        String fullName

    static constraints = {
    }

        static mapping = {
                table 'user_details'
        }

        UserDetails(String username, String password, boolean enabled,
                boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked,
                Collection<GrantedAuthority> authorities, long id, String fullName) {
               
                super(username, password, enabled, accountNonExpired, credentialsNonExpired,
                        accountNonLocked, authorities, id)

                this.fullName = fullName
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: Custom UserDetails class throws MappingException

Burt Beckwith
Administrator
UserDetails should not be a domain class, just a regular class in src/groovy. This is just a simple data class that's stored in the HTTP session and contains data retrieved during login, typically from the database (e.g. from the User, Role, and UserRole classes).

Burt

On Wednesday, March 07, 2012 10:45:07 PM emiles [via Grails Plugins] wrote:

>
> More readable version of the first post!
>
> Created custom UserDetails domain class and UserDetailsService class
> according to docs. Worked fine with version 1.3.7. Upgraded to 2.0.0, then
> 2.0.1, and it threw the following exception with each upgrade. No code
> changes, just performed upgrades.
>
> Thanks in advance.
>
>
> Exception:
>
> | Loading Grails 2.0.1
> | Configuring classpath.
> | Environment set to development.....
> | Packaging Grails application.....
> | Compiling 2 source files.....
> | Running Grails application
>
> Configuring Spring Security UI ...
> ... finished configuring Spring Security UI
>
>
> Configuring Spring Security Core ...
> ... finished configuring Spring Security Core
>
> 2012-03-08 01:30:46,364 [ERROR] context.GrailsContextLoader: Error executing
> bootstraps: Error creating bean with name 'transactionManagerPostProcessor':
> Initialization of bean failed; nested exception is
> org.springframework.beans.factory.BeanCreationException: Error creating bean
> with name 'transactionManager': Cannot resolve reference to bean
> 'sessionFactory' while setting bean property 'sessionFactory'; nested
> exception is org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'sessionFactory': Invocation of init method failed;
> nested exception is org.hibernate.MappingException: identifier mapping has
> wrong number of columns: com.toolcrib.UserDetails type: object
> org.springframework.beans.factory.BeanCreationException: Error creating bean
> with name 'transactionManagerPostProcessor': Initialization of bean failed;
> nested exception is org.springframework.beans.factory.BeanCreationException:
> Error creating bean with name 'transactionManager': Cannot resolve reference
> to bean 'sessionFactory' while setting bean property 'sessionFactory';
> nested exception is org.springframework.beans.factory.BeanCreationException:
> Error creating bean with name 'sessionFactory': Invocation of init method
> failed; nested exception is org.hibernate.MappingException: identifier
> mapping has wrong number of columns: com.toolcrib.UserDetails type: object
> at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
> at java.util.concurrent.FutureTask.run(FutureTask.java:138)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> at java.lang.Thread.run(Thread.java:662)
> Caused by: org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'transactionManager': Cannot resolve reference to
> bean 'sessionFactory' while setting bean property 'sessionFactory'; nested
> exception is org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'sessionFactory': Invocation of init method failed;
> nested exception is org.hibernate.MappingException: identifier mapping has
> wrong number of columns: com.toolcrib.UserDetails type: object
> ... 5 more
> Caused by: org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'sessionFactory': Invocation of init method failed;
> nested exception is org.hibernate.MappingException: identifier mapping has
> wrong number of columns: com.toolcrib.UserDetails type: object
> ... 5 more
> Caused by: org.hibernate.MappingException: identifier mapping has wrong
> number of columns: com.toolcrib.UserDetails type: object
> ... 5 more
>
>
> UserDetails class:
>
> package com.toolcrib
>
> import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser
> import org.springframework.security.core.GrantedAuthority
>
> class UserDetails extends GrailsUser {
>
> String fullName
>
>     static constraints = {
>     }
>
> static mapping = {
> table 'user_details'
> }
>
> UserDetails(String username, String password, boolean enabled,
> boolean accountNonExpired, boolean credentialsNonExpired, boolean
> accountNonLocked,
> Collection<GrantedAuthority> authorities, long id, String fullName) {
>
> super(username, password, enabled, accountNonExpired,
> credentialsNonExpired,
> accountNonLocked, authorities, id)
>
> this.fullName = fullName
> }
> }
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://grails-plugins.847840.n3.nabble.com/Custom-UserDetails-class-throws-MappingException-tp3808965p3808969.html
> To start a new topic under Grails Plugins, email [hidden email]
> To unsubscribe from Grails Plugins, visit
Reply | Threaded
Open this post in threaded view
|

Re: Custom UserDetails class throws MappingException

Walter
Burt,

I have been racking my brains and reading everything I  can find about the security plugin and the UserDetails object, but I cannot figure out how to retrieve the UserDetails object after my customUserDetailsService creates it. You say it is stored in the session, but how do I pull it out of the session?

Thanks,
Walter
Reply | Threaded
Open this post in threaded view
|

Re: Custom UserDetails class throws MappingException

Burt Beckwith
Administrator

 

See http://grails-plugins.github.com/grails-spring-security-core/docs/manual/guide/6%20Helper%20Classes.html#6.2%20SpringSecurityService

 

Burt

 


On July 26, 2012 at 1:38 AM "Walter [via Grails Plugins]" <[hidden email]> wrote:

>
>
> Burt,
>
> I have been racking my brains and reading everything I  can find about the
> security plugin and the UserDetails object, but I cannot figure out how to
> retrieve the UserDetails object after my customUserDetailsService creates
> it. You say it is stored in the session, but how do I pull it out of the
> session?
>
> Thanks,
> Walter
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://grails-plugins.847840.n3.nabble.com/Custom-UserDetails-class-throws-MappingException-tp3808965p4024969.html
> To start a new topic under Grails Plugins, email [hidden email]
> To unsubscribe from Grails Plugins, visit
Reply | Threaded
Open this post in threaded view
|

Re: Custom UserDetails class throws MappingException

chuck
This post was updated on .
In reply to this post by Burt Beckwith
Hey Burt! Thanks for this post!  I was pulling my hair out.

Do you think you could add that to the documentation at http://grails-plugins.github.com/grails-spring-security-core/docs/manual/guide/11%20Custom%20UserDetailsService.html?  I just assumed that the class should be a domain and the service should live in grails-app/services :(

Spring Security Core plugin is great, though!  It saved me soooo much work!
Reply | Threaded
Open this post in threaded view
|

Re: Custom UserDetails class throws MappingException

Jason
I made the same wrong assumption that a custom UserDetails implementation should be a domain class. Thinking about it now, it makes perfect sense that it isn't since a custom UserDetails class is a composite of security-specific properties (i.e., username) and domain-specific properties (i.e., firstName), and doesn't have any persistent properties of its own. This was a helpful post...