开发者

how to add users in spring security core

I just added the spring security plugin to my grails application. I have a question about adding users and their associated roles. I am able to do it correctly in the bootstrap but was wondering how to do it in the GSP page. I have a gsp page with the corresponding fields. when submited, it call the save method. my user domain controller extends SecUser. below is the example:

class User extends SecUser {

    String  fname
    String  lname
    Date    dateCreated
    Date    las开发者_JS百科tUpdated

    static constraints = {
        fname       (blank:false)
        lname       (blank:false)
    }
    String toString(){
        fname & " " & lname
    }
}

When the user is saved, it saves only items in the user domain, not the SecUser. Does anyone have an example GSP and controller code to save the all the user data?


I perceive that you have two problems :

  1. How to create a Crud (including gsp) on your User class
  2. How to persist the data on your class and its inherited fields

For the first question: To create GSPs and everything you need to have a CRUD on your User class, I suggest that you use scaffolding. If will take care of all of this for you.

Remove everything from your UserController or create another controller with only the following code:

class UserController {
    static scaffold = User
}

then, navigate to your UserController ({your_app}/user/index) and everything should be there.

If you want to have an actual controller and gsps and modify how they work, use the grails command :grails generate-all your.package.User

For the second question :

Unless there is a problem with your SecUser class (transient fields for example), all fields inherited from SecUser should be saved through a User.save()

Let me know how it goes,

Vincent Giguère


Did you use the included script to generate your User class?

grails s2-quickstart DOMAIN_CLASS_PACKAGE USER_CLASS_NAME ROLE_CLASS_NAME [REQUESTMAP_CLASS_NAME]

eg.

grails s2-quickstart com.yourapp User Authority

When I did that in my grails app, the resulting User class did not extend SecUser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜