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 8942689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:34:35+00:00 2026-06-15T11:34:35+00:00

I have a Grails 2.1.1 application which runs fine, at least until I try

  • 0

I have a Grails 2.1.1 application which runs fine, at least until I try to define a filter for all Controller to redirect to the index.gsp if user is not set in the session variable…

what ever I try, I’m not able to redirect to “/index”, nor render “/index” when starting the server – if I remove the filter and redirect to “/index” from my AuthenticationController on false parameters, all works like charm…

so, here’s what I have so far:

class AuthenticationFilters {
  all(controller:'*', action'*') {
    before = {
      def user = (User) session.getValue("user")
      if(user == null || !user.loginState) {
        redirect(controller: 'authentication', action: 'index')
        return false
      }
    }
  }
}

class AuthenticationController {
  def authenticationService

  def index = {
    render(view: '/index')
  }

  def login(LoginCommand cmd) {
    if(cmd.hasErrors()) {
      redirect(action: index)
      return
    }
  }
  ....
}

now, if I comment out the all Filters definition, everything works well. I got the page (index.gsp) shown on start up and if the LoginCommand has errors, I’m redirected to the index.gsp page without any problems.
if I now comment in the all Filters definition, I get a 404.

I tried:
Grails: Redirect to index.gsp that is not in any controller
Upgrade to Grails 2.0: /index.gsp not found
Grails: what are the main issues (and his solutions) when deploying in weblogic?

but I didn’t had any luck…

I’m developing on Intellij IDEA 11.1.4 Premium (evaluation)


EDIT: I tried to get the User object from the session property in my AuthenticationFilters class, surrounded by a try/catch block and now facing the problem that obviously the session property is not available? why?

try {
        def user = (User) session.getValue("user")
        if((user == null || !user.loginState)) {
            ...
        }
    } catch(Exception e) {
        println("... couldn't get user from session! ${e.getMessage()}")
    }

console output:

... couldn't get user from session! No such property: session for class: grailstest001.AuthenticationFilters

any suggestions on this?

  • 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-06-15T11:34:37+00:00Added an answer on June 15, 2026 at 11:34 am

    So, just to add my experience here to close this question as solved and for further usage for other users:

    to check if the user is entering the page for the first time, you could easily do this by checking for the controllerName field. It should be null or "" (empty String) if the user was not referred to the site by any controller.

    Also, I’m not using any Database within my application for authentication because all of this issuses are backended by an API. So I created a UserService.groovy class which is acting as a SessionScopedBean and I store all my user related infos within this class.

    So, your filter definition could look like:

    class MyFilters {
      def filters = {
        before = {
          if(!controllerName || controllerName.equals("")) {
            redirect(controller:'home',action:'index')
          }
          if(!applicationContext.userService?.getUser() || !applicationContext.userService?.getUser.isLoggedIn) {
            redirect(controller:'auth',action:'login')
          }
        }
      }
    }
    

    Otherwise, if you don’t want to redirect the user which ‘freshly’ entered your page from within your Filters.groovy class, you could use the UrlMappings.groovy class to do so. Just map your / (root) index to the page you want:

    class UrlMappings {
      static mappings = {
        "/"(controller:'mycontroller',action:'myaction') // change it to your liking
        "/$controller/$action?/$id?" {
          constraints {
            // apply constraints here
          }
        }
        "500"(view:'/error')
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Grails application I have two filters which protect all my controllers for
I have inherited a Grails app, which uses the Acegi 0.5.3 plugin. The application
I have a groovy/grails application that needs to serve images It works fine on
I have a basic Grails 2 application which I setup along with the SpringSecurityCore
I have build a grails application, which on login redirects users to different URLs
I have a grails(2.0.3) application that has a jar dependency on another project which
I have grails application on heroku. I use MongoSessionManager which allows, to share session
We have a web application (Grails) which we are going to sell licenses for
In our application which is based on grails 2.0.4 we have overwritten the grails
I have developed a grails/groovy application for a legacy database which has user maintenance

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.