Search code examples
magnolia

Get username in magnolia


I am using the following command to get the username in a custom magnolia class:String userName = MgnlContext.getInstance().getJCRSession("website").getUserID(); Instead of getting the name of the user who is signed on in magnolia when the command was triggered I am getting admin for the value. How can I get the real user name - the one who signed on to magnolia?


Solution

  • Actually to get current user, what you want is to either inject MgnlContext or get it via MgnlContext.getInstance() call.
    Once you have context, you call ctx.getUser().getName() to get current user name.