Permissions for UserAccessor (how enable or disable a confluence user)

Deleted user June 4, 2012

Since there is no deactivate(user) method provided in by the UserManager I would like to deactivate and reactivate users by utilizing the UserAccessor.deactivate method. But the method fails caused by an InsufficientPrivilegeException:

[See nested exception: com.atlassian.confluence.core.InsufficientPrivilegeException: User [Anonymous] does not have the required privileges.]

The question is, where can I find some docmentation which tells me how to setup a specific user when calling this method?

Thanks in advance,

Lars Kleen

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Deleted user June 10, 2012

I could set the property by utilizing the DiabledUserManager

atlassian-plugin.xml

<component key="disabledUserManager" class="com.atlassian.confluence.user.crowd.CrowdDisabledUserManager">
        <interface>com.atlassian.confluence.user.DisabledUserManager</interface>
    </component>

    <component key="crowdService" class="com.atlassian.crowd.embedded.api.CrowdService">
        <interface>com.atlassian.crowd.embedded.api.CrowdService</interface>
    </component>

    <component-import key="transactionTemplate" name="Hibernate Transaction Template" interface="com.atlassian.sal.api.transaction.TransactionTemplate">
        <description>Component that provides a hibernate transaction</description>
    </component-import>

code:

public class ActivateUserCallback implements TransactionCallback<UserNotActivatedException> {

    private final String userName;
    private final CrowdService crowdService;
    private final DisabledUserManager disabledUserManager;

    public ActivateUserCallback(String userName, CrowdService crowdService, DisabledUserManager disabledUserManager) {
        this.userName = userName;
        this.crowdService = crowdService;
        this.disabledUserManager = disabledUserManager;
    }

    @Override
    public UserNotActivatedException doInTransaction() {
        com.atlassian.crowd.embedded.api.User user = null;
        try {
            user = crowdService.getUser(userName);
            if(user == null) {
                return new UserNotActivatedException("user == null");
            }
            disabledUserManager.enableUser(user);
        } catch (UserNotFoundException e) {
            return new UserNotActivatedException(e);
        }
        return null;
    }
}

1 vote
Royce Wong
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 17, 2015

Per Joseph Clark in this thread, https://answers.atlassian.com/questions/61246/how-can-i-edit-the-email-adress-of-a-confluence-user

If you're calling some admin-protected code from within a scheduled task, you can just set the identify of the job to be an admin user by calling AuthenticatedUserThreadLocal.setUser

 

1 vote
Ebe July 30, 2013

Hi Jobin, Lars,

Have you guys resolved the issue? I am facing similar issue while trying to add a user to new group. I am using useraccessor.addMembership method, but getting "User [Anonymous] does not have the required privileges."

How can you solve this issue using DisabledUserManager?

0 votes
Sathish Venkat February 6, 2015

Using GroupManager will not check the Authentication.

This should work

protected GroupManager getGroupManager() {
  	return (GroupManager) ContainerManager.getComponent("groupManager");
 }
 
 
Group defaultGroup = getUserAccessor().getGroup("confluence-users"); 
GroupManager grpManager = getGroupManager(); 
if (grpManager != null && defaultGroup != null) {
	grpManager.addMembership(defaultGroup, newUser);
}
0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 4, 2012

You should be a Confluence Administrator when calling this method.

https://confluence.atlassian.com/display/DOC/Removing+or+Deactivating+a+User

The permissions are same whether it is done via APIs or via the user interface.

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 4, 2012

I am guessing it looks at the current logged in user, who is using the plugin.

Deleted user June 4, 2012

I guess there is no user. It is a job module which is triggered by a trigger module

https://developer.atlassian.com/display/CONFDEV/Trigger+Module

Deleted user June 4, 2012

The plugin does not require any kind of login when utilizing a UserManager or GroupManager to modify users and groups. However the UserAccessor does not provide a method for user authentication.

While thinking about the problem ... the plugin should be ultilized for Confluence and Jira so it would require to setup different service users just for deactivating and reactivating users. This is a workaround I would like to avoid. So I'm just searching for an alternative which does not require user authentication.

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 4, 2012

makes sense now why it is being treated as an Anonymous user!

Deleted user June 4, 2012

hmm, yes it does. Maybe it is just impossible to set this property with the UserAccessor, I'll try it with CrowdDisabledUserManager ...

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 4, 2012
Ebe July 30, 2013

Hi Jobin, Lars,

Have you guys resolved the issue? I am facing similar issue while trying to add a user to new group. I am using useraccessor.addMembership method, but getting "User [Anonymous] does not have the required privileges."

How can you solve this issue using DisabledUserManager?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events