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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:36:15+00:00 2026-05-13T13:36:15+00:00

I have secured my Grails app using the ACEGI plugin and am using annotations

  • 0

I have secured my Grails app using the ACEGI plugin and am using annotations on my controller methods to prompt the user to login.

My app has a static HTML front page with a login link on it which redirects to the login/auth page. On a successful login I want to load my own custom page for the authenticated user, called person/mainpage.

In my LoginController there is the following code…

def index = {
    if (isLoggedIn()) {
        redirect uri: '/'
    }
    else {
        redirect action: auth, params: params
    }
}

/**
 * Show the login page.
 */
def auth = {

    nocache response

    if (isLoggedIn()) {
        redirect uri: '/'
        return
    }

    String view
    String postUrl
    def config = authenticateService.securityConfig.security
    if (config.useOpenId) {
        view = 'openIdAuth'
        postUrl = "${request.contextPath}/login/openIdAuthenticate"
    }
    else if (config.useFacebook) {
        view = 'facebookAuth'
        postUrl = "${request.contextPath}${config.facebook.filterProcessesUrl}"
    }
    else {
        view = 'auth'
        postUrl = "${request.contextPath}${config.filterProcessesUrl}"
    }

    render view: view, model: [postUrl: postUrl]
}

This redirects the successful login back to the main page of the application (/), which is not what I want. Googling for a little while I found that I could define a default target for my authentication in securityconfig.groovy like this..

defaultTargetUrl = "/person/mainpage"

My question is how to identify which user logged in when I land on my mainpage action in my PersonController?

At first I changed my index action in LoginController to redirect to my page like this…

def index = {
    if (isLoggedIn()) {
        redirect controller: person, action: mainpage, params: params 
    }
    else {
        redirect action: auth, params: params
    }
}

but the id of the logged in person does not appear in the params (which I think I am happy about because it seems crazy to be able to pull up pages just by defining a user row ID as a url parameter).

So what’s the right way to do this? Basically I want my person/mainpage action to be able to resolve the currently logged in user.

  • 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-13T13:36:15+00:00Added an answer on May 13, 2026 at 1:36 pm

    You can access the logged in user using authenticateService. To get the user/person domain instance call authenticateService.userDomain() and to just get the Authentication (which has a getUsername() method that might be sufficient) call authenticateService.principal(). If your defaultTargetUrl is “/person/mainpage” then your PersonController’s ‘mainpage’ action would look something like this:

    class PersonController {
    
       def authenticateService
    
       def mainpage = {
          def user = authenticateService.userDomain()
          if (user) {
             log.info "you're logged in as $user.username"
          }
          else {
             log.info "you're not logged in"
          }
          [user: user]
       }
    }
    

    and then you’d have the ‘user’ available in mainpage.gsp to render data from.

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

Sidebar

Related Questions

We're developing an app (using Grails Spring Security (formerly Acegi)) in which we'll have
I have a Grails 1.2 app secured with acegi that I'm monitoring with the
I have a controller like this : @Secured(['ROLE_USER','IS_AUTHENTICATED_FULLY']) def userprofile(){ def user = User.get(springSecurityService.principal.id)
I'm using ASP.NET MVC 2 and have a login page that is secured via
How is it possible to get app.user from unsecure area? So I have secured
I have an MVC site, secured using [Authorize] attributes, but have an issue on
I have a web application and would want it to be secured using a
I'm using Spring Security in Grails to restrict access to my controllers. I have
I have secured a folder on my website using Windows authentication. I created a
I have an open-source code for a secured login portal written on the asp.net

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.