Last active
August 29, 2015 14:19
-
-
Save aadrian/5316d97a15b7b0ffe24a to your computer and use it in GitHub Desktop.
Grails Roles init and check at startup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// config | |
class BootStrap { | |
def init = { servletContext -> | |
def adminRole = Role.findByAuthority('ROLE_ADMIN')?: new Role(authority: 'ROLE_ADMIN').save(failOnError: true) | |
def userRole = Role.findByAuthority('ROLE_USER')?: new Role(authority: 'ROLE_USER').save(failOnError: true) | |
// admin user. | |
def admin = User.findByUsername('admin@domain.com')?: new User(username: 'admin@domain.com',password: 'password', enabled: true).save(failOnError: true) | |
UserRole.create admin, adminRole, true | |
UserRole.create admin, userRole, true | |
// simple user. | |
def user = User.findByUsername('user@domain.com')?: new User(username: 'user@domain.com',password: 'password', enabled: true).save(failOnError: true) | |
UserRole.create user, userRole, true | |
} | |
// .... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment