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

  • Home
  • SEARCH
  • 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 9111787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:35:10+00:00 2026-06-17T03:35:10+00:00

I’m writing Grails application which uses Sprint Security for authentication. I need to display

  • 0

I’m writing Grails application which uses Sprint Security for authentication. I need to display a message to a user, who has been automatically logged off due to inactivity.

My application uses both AJAX requests and direct requests to the controllers. I noticed, that for AJAX requests Sprint Security returns HTTP response with code 401, and I have redefined default URL mapping in such a way:

class UrlMappings {
    static mappings = {
         // ...

         "401" (controller: 'errors', action: 'inactivityLogout')
    }
}

And here is the body of inacticityLogout() method:

def inactivityLogout() {
    log.debug("the user is logged out due to inactivity")
    session.setAttribute('inactivityMessage', "You have been logged out due to inactivity.")
    render(status: 401)
}

Then the LoginController checks if inactivityMessage attribute is set, and displays corresponding message on Login page.

The problem is that this solution works fine for AJAX calls, but doesn’t work when I’m trying to navigate to another page just by clicking direct link in the application. In second case log is empty, so the method inactivityLogout is not called.

Firebug shows that application returns code 302 Moved Temporarily, so I though that this is a reason. But then I noticed that the same code is returned for AJAX calls as well. So, now I have no ideas what is the difference between the AJAX and non-AJAX requests and why the last are not handled by Grails URL mapping engine.

Any ideas, what could be wrong with my current solution? Can this problem be solved in completely different way?

Thanks!

  • 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-17T03:35:11+00:00Added an answer on June 17, 2026 at 3:35 am

    Using jQuery, this is what I do:

    $.ajaxSetup({
       statusCode: {
         401: function () {
           $('#ajaxAuthModal').modal('show');
         }
       }
    });
    

    I have that in a global JS file so that all my ajax requests handle a 401. Then I just show a modal that tells the user they need to login again. The only real difference you would need to achieve what you want is to poll a secure resource via ajax. This would allow the 401 function to trigger when the 401 is returned.

    Most JavaScript libraries like jQuery should have a similar feature to $.ajaxSetup().

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

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I need to clean up various Word 'smart' characters in user input, including but
I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small

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.