1

I setup a new project with the Spring Security core plugin. My goal is a simple login/logout, usermanagement (CRUD) including roles (admin, user). Just the admin should be able to create users, so a registration is not necessary.

I followed this tutorial (docu):

http://grails-plugins.github.io/grails-spring-security-core/guide/tutorials.html#usingControllerAnnotations

Now I have a User, Role and UserRole Domain class and CRUD functionality. Unfortunately the Role management is missing. In the best case the role should be specified by the admin in the "create user process".

Another thing I noticed is that I cant add any other fields to the generated user class. Just adding "String lastName" results in the following error (run-app):

2015-04-22 19:50:57,749 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: No signature of method: test.UserRole.exists() is applicable for argument types: (null, java.lang.Long) values: [null, 1]
Possible solutions: exists(long, long), exists(java.io.Serializable), list(), first(), wait(), last()
Message: No signature of method: test.UserRole.exists() is applicable for argument types: (null, java.lang.Long) values: [null, 1]
Possible solutions: exists(long, long), exists(java.io.Serializable), list(), first(), wait(), last()

Is there an "easy" way to implement the role-management and fix this error?

Should I switch to the Spring Security ui plugin? It seems that this plugin implements a lot of functionality I dont really need.

EDIT: I added a field "role" to the User class to specify the role during the user-creation. Now I should set the connection between User and Role in the UserRole entity. I added the following lines in the UserController.create method:

def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)

      def user = new User(params)
      user.save(flush: true)

      UserRole.create user, adminRole, true

      respond user

But I guess its in the wrong place because I cant get access with a created user to secured URLs

Christian
  • 821
  • 1
  • 11
  • 26
  • Adding `lastName` didn't directly cause that problem - you're just doing it wrong. It looks like what really happened is that you added a new property and the default is not-null, but you didn't provide a value and validation failed, so the instance is null. – Burt Beckwith Apr 22 '15 at 18:21
  • Yeah you're right, that was a completely other mistake! It works fine with nullable: true - So I gave the User a role property to directly set it during the "user-creation-process". Now I have to call smth. like this: UserRole.create testUser, adminRole, true , but where? – Christian Apr 22 '15 at 20:53

0 Answers0