Problem to get About Me information from User details after Confluence 7 update

Hello experts!

I have a problem which started with Confluence 7 upgrade. Something has been changed and depreciated that previously perfectly worked code doesn’t work anymore.

That was used to get also About Me field information visible in a nice way. Originally code was taken from internet with a small tuning.

Here everything else is ok (macro prints profile picture and basic information) but parameter for line

#set($pi = $personalInformationManager.getOrCreatePersonalInformation($user))

doesn’t work. It used to be user earlier but now either username, user object or key doesn’t work. Variable $pi stays empty. Somewhere it was mentioned that using username isn’t supported anymore, but instead to use user object. That didn’t work either - or I did it wrong somehow.

I already changed getPersonalInformation to getOrCreatePersonalInformation as former was depreciated based on some documentation. But that didn’t help.

Somewhere was mentioned some accountId which will replace username, but I cannot spot it anywhere and cannot get it. All I got from variables are

$user is: ConfluenceUserImpl {name=‘xxxxx’, key=2c90659044c655310144c6559c38077a}

$key will be like “2c90659044c655310144c6559c38077a”

$u was just plain username

None of those work as a parameter anymore.

I’m out of ideas.

Can someone help me? Thanks.

Here’s code:

## @param Username:title=Username(s). If more than one, separate by comma|type=string|required=true

#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
#set($userDetailsManager = $containerContext.getComponent('userDetailsManager'))
#set($personalInformationManager = $containerContext.getComponent('personalInformationManager'))
#set($wikiStyleRenderer = $containerContext.getComponent('wikiStyleRenderer'))

#if($paramUsername=="")
  #set($paramUsername = $action.remoteUser)
#end

#set($all = $paramUsername.split(","))

#foreach ($u in $all)

  #set($user = "")
  #set($user = $userAccessor.getUserByName($u))
  #set($key = "")
  #set($key = $user.getKey())

  #if($user!="")

    #set($pi = $personalInformationManager.getOrCreatePersonalInformation($user))

    #set($renderedAboutMe = $wikiStyleRenderer.convertWikiToXHtml($pi.toPageContext(), $pi.getBodyAsString()))

    <div class="upp-profile-macro profile-minimal">
      <div class="upp-basic-user-container">
        <div class="uppuserlogo">
          <ac:macro ac:name="profile-picture"><ac:parameter ac:name="User">$user.name</ac:parameter></ac:macro>
        </div>
        <div class="upp-basic-userdata">
          <div class="uppusername">
            <h4 title="$user.fullName" class="profile-username">
            <a href="/conflu/display/~$user.name" class="url fn confluence-userlink" data-username="$user.name">
            $user.fullName</a></h4>
          </div>
          <div class="uppusermail">
            <a href="mailto:$user.email" title="Send Email to $user.fullName">$user.email</a>
          </div>
        </div>
        <div class="upp-clear">
          $renderedAboutMe
        </div>
      </div>
    </div>
  #end
#end

As a reference original user macro code comes from here:

Another note. I use User Profiles plugin, therefore HTML code might not work. Remove all HTML and just leave only:

          $renderedAboutMe

Hello!

No comments? Alright. I verified my earlier macro by installing vanilla Confluence 6.15.10 to my computer. No plugins, no customization, no nothing. Just Confluence out of the box.

  • Added a new User macro
## @param Username:title=Username(s). If more than one, separate by comma|type=string|required=true

#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
#set($userDetailsManager = $containerContext.getComponent('userDetailsManager'))
#set($personalInformationManager = $containerContext.getComponent('personalInformationManager'))
#set($wikiStyleRenderer = $containerContext.getComponent('wikiStyleRenderer'))

#if($paramUsername=="")
  #set($paramUsername = "admin")
#end

#set($all = $paramUsername.split(","))

#foreach ($u in $all)

  #set($user = "")
  #set($user = $userAccessor.getUserByName($u))

  #if($user!="")

    #set($pi = $personalInformationManager.getPersonalInformation($user))
 
    #set($renderedAboutMe = $wikiStyleRenderer.convertWikiToXHtml($pi.toPageContext(), $pi.getBodyAsString()))

    <div class="upp-profile-macro profile-minimal">
      <div class="upp-basic-user-container">
        <div class="uppuserlogo">
          <ac:macro ac:name="profile-picture"><ac:parameter ac:name="User">$user.name</ac:parameter></ac:macro>
        </div>
        <div class="upp-basic-userdata">
          <div class="uppusername">
            <h4 title="$user.fullName" class="profile-username">
            <a href="/conflu/display/~$user.name" class="url fn confluence-userlink" data-username="$user.name">
            $user.fullName</a></h4>
          </div>
          <div class="uppusermail">
            <a href="mailto:$user.email" title="Send Email to $user.fullName">$user.email</a>
          </div>
        </div>
        <div class="upp-clear">
          $renderedAboutMe
        </div>
      </div>
    </div>
  #end
#end

(continues in next post as new users cannot attach more than 1 image!)

(continues)

  • Added macro to page
    aboutme_page2

And everything is fine! Showing rendered About Me.

But not working in Confluence 7.

1 Like

I found the same problem and it’s indeed really frustrating seing user macros stop working with no alternative provided.

Regards

This error is due to security constrains being more tight then in Confluence 6.
I had similar problem with my macros.
The root cause is that “.class.forName” doesn’t work anymore because it’s restricted in velocity.properties (conflunce/WEB-INF/classes).
On your own risk you can enable some packages there & everything will start working again…

Best
JP

In CONFHOME\confluence\WEB-INF\classes\velocity.properties

change the following lines:

introspector.restrict.packages = java.lang.reflect,\

to

introspector.restrict.packages = \

And

introspector.restrict.classes = java.lang.Class,
java.lang.ClassLoader,\

to

introspector.restrict.classes = \

I tested with your original macro code: Works like a charm. Thanks for the macro…

Best
JP

Hello all

I highly recommend to not mess with the restrictions put on velocity’s introspector. They were added for a valid reason.

That said, I do understand the frustration of having user macros suddenly not working if they are consuming specific undesirable code patterns.
We will be looking into alternatives.

Hasnae R.

2 Likes

We’re facing similar problems when trying to access user details like phone number and location. Is there any update on the availability of the UserDetailsManager in user macros?

Hello all,

I’ve created a Suggestion ticket in our ecosystem to keep track of this so that we can collect some feedback on how does this change impacts your organization as well as your use cases in order to help the development team work on an alternative based on [our policy|https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html]:

Please feel free to Vote on the ticket above and share your feedback with us!