Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:55:10+00:00 2026-05-27T22:55:10+00:00

I am working on a grails application for the first time and I now

  • 0

I am working on a grails application for the first time and I now want to protect some pages to be viewed only by admins, and give some permissions to other users.

I am using Apache Shiro plugin for grails.

My sample code in the bootstrap looks like this

class BootStrap {

def init = { servletContext ->
    def adminRole

    if(ShiroRole.findByName("Admin".isEmpty())){
        adminRole = new ShiroRole(name: "Administrator")
        adminRole.addToPermissions("*:*")
        adminRole.addToPermissions("admin")

        adminRole.save()

// ‘user’ now has all administrator rights
}

    if (ShiroUser.findAllByUsername("user").isEmpty()) {
        def user = new ShiroUser(username: "user", passwordHash: new Sha256Hash("pass").toHex())
        user.addToPermissions("*:*")
        user.addToRoles(adminRole)

        user.save()

    }

    if (ShiroUser.findAllByUsername("Guest").isEmpty()) {
        def user = new ShiroUser(username: "Guest", passwordHash: new Sha256Hash("pass").toHex())
        user.addToPermissions("inventory:*")
        user.save()
    }


}
def destroy = {
}

}

My ShiroSecurityFilters looks like

class ShiroSecurityFilters {
def filters = {
    all(uri: "/**") {
        before = {
            // Ignore direct views (e.g. the default main index page).
            if (!controllerName) return true

            // Access control by convention.
            accessControl()

        }
    }
}

}

I wanted to give to “Guest” access to inventory scaffold only. However in my application once the user “Guest” logged in its able to access other controllers butI don’t want that to happen. I appreciate your help.

If there is an better of using Shiro role, access control and/or permissions, please let me know about it.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:55:10+00:00Added an answer on May 27, 2026 at 10:55 pm

    OK. let’s see…

    there is a typo right at the start:

    "Admin".isEmpty()
    

    will always be false… and I guess you have no role “false” defined…

    And you are looking for “Admin” but create “Administrator”…

    Do a

    adminRole.save(flush:true, failOnError:true)
    

    instead of adminRole.save(). This will make sure that the object is really saved.

    The role Administrator already has all permissions ("*:*") and "admin" is not a typical shiro permission, so you can drop this line… (adminRole.addToPermissions("admin"))

    If you do a

    user.addToRoles(adminRole)
    

    you don’t need to add the "*:*"permission. The role is already enough.

    I’ve now created a test project, installed shiro, did a create-auth-controller, a create-wildcard-realm and a create-filters ShiroSecurity.

    Activate logging for BootStrap and Shiro-Realm by adding following two lines to the log4j config in Config.groovy:

    debug   'grails.app.conf.BootStrap'
    debug   'grails.app.realm'
    

    Here is my BootStrap.groovy: (the interesting part)

    def init = { servletContext ->
        def adminRole
    
        if(ShiroRole.findByName("Administrator")==null){
            adminRole = new ShiroRole(name: "Administrator")
            adminRole.addToPermissions("*:*")
            adminRole.save(flush:true, failOnError:true)
            log.debug adminRole.dump()
        }
        println ShiroUser.findAllByUsername("user").dump()
        log.debug "="*80
        if (ShiroUser.findAllByUsername("user").isEmpty()) {
            def user = new ShiroUser(username: "user", passwordHash: new Sha256Hash("pass").toHex())
            user.addToRoles(adminRole)
            user.save(flush:true, failOnError:true)
            log.debug user.dump()
        }
    
        if (ShiroUser.findAllByUsername("Guest").isEmpty()) {
            def user = new ShiroUser(username: "Guest", passwordHash: new Sha256Hash("pass").toHex())
            user.addToPermissions("inventory:*")
            user.save(flush:true, failOnError:true)
            log.debug user.dump()
        }
    
    }
    

    and my ShiroSecurityFilters.groovy:

    def filters = {
        all(controller:'*', action:'*') {
            before = {
            // Ignore direct views (e.g. the default main index page).
            if (!controllerName) return true
    
            // Access control by convention.
            accessControl()
    
            }
        }
    }
    

    and it works…

    As you can see, my SecurityFilters are based on controller and action… just my preference…

    But I guess your problem was only based on the wrong bootstrap. Logging is very useful when you work with shiro…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still working on my first Grails application. This time, my problem is to
Hi am just started working on grails.. developed my first application in grails can
I'm working on a Grails project and I want to write some data from
I am taking my first steps with Ajax while working on a Grails application.
I'm working on a Grails application and I need to display some reports and
I have been working on the project where application is using grails 1.2.2.... Now
I'm working on a Grails application. There is a domain class participant - within
I am working on a web application (using Grails) which will generate a gift
I'm working now together with others in a grails project. I have to write
We have an application in Grails 2.0 that we have working when we run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.