Spring Security Core Plugin Creates Odd Table Constraints...

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

Spring Security Core Plugin Creates Odd Table Constraints...

webmediauk
Hey Guys,
I've plugged Spring Security Core into my app and so far I've found it very useful but with one problem.
I already had two user domain object types setup in my app (Advertiser and Publisher) so I used "extends User" to integrate them both into Security Core.
Advertisers and Publishers both have a many to one relationship with another domain class "LeadAlias"
So when I fire up Grails, this has the consequence of creating a join table "users_lead_alias", with 3 columns (advertiser_id, publisher_id and lead_alias_id). advertiser_id and publisher_id have constraints so that they cannot be null which at first look seems fine.
Now in my app whenever I call:

LeadAlias.addToAdvertisers(myAdvertiser) or LeadAlias.addToPublishers(myPublisher)

I get an Hibernate error because in the SQL it's trying to set advertiser_id to some value without publisher_id being set aswell!
I can easily solve this error by removing the NOT NULL constraints on the join table column, then rows can be added individually for advertisers and publishers.

My question is this: is there a way for me to configure Spring Security Core to remove the constraints on the join table without having to do this manually after table creation? Or have I set something up incorrectly for the table to be created in this way in the first place?
Many Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Spring Security Core Plugin Creates Odd Table Constraints...

burtbeckwith
Hibernate subclassing kicks in when domain classes extend others, so that's what you're seeing. You could change it from subclassing/is-a to a has-a where Advertiser and Publisher add a "User user" field.

If it makes things easier security-wise you can also write your own security user lookup; see section "11 Custom UserDetailsService" in the docs: http://grails-plugins.github.com/grails-spring-security-core/docs/manual/

Burt

> Hey Guys,
> I've plugged Spring Security Core into my app and so far I've found it very
> useful but with one problem.
> I already had two user domain object types setup in my app (Advertiser and
> Publisher) so I used "extends User" to integrate them both into Security
> Core.
> Advertisers and Publishers both have a many to one relationship with another
> domain class "LeadAlias"
> So when I fire up Grails, this has the consequence of creating a join table
> "users_lead_alias", with 3 columns (advertiser_id, publisher_id and
> lead_alias_id). advertiser_id and publisher_id have constraints so that they
> cannot be null which at first look seems fine.
> Now in my app whenever I call:
>
> LeadAlias.addToAdvertisers(myAdvertiser) or
> LeadAlias.addToPublishers(myPublisher)
>
> I get an Hibernate error because in the SQL it's trying to set advertiser_id
> to some value without publisher_id being set aswell!
> I can easily solve this error by removing the NOT NULL constraints on the
> join table column, then rows can be added individually for advertisers and
> publishers.
>
> My question is this: is there a way for me to configure Spring Security Core
> to remove the constraints on the join table without having to do this
> manually after table creation? Or have I set something up incorrectly for
> the table to be created in this way in the first place?
> Many Thanks
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Spring-Security-Core-Plugin-Creates-Odd-Table-Constraints-tp4185559p4185559.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email