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
Community moderators have prevented the ability to post new answers.
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; } }
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am guessing it looks at the current logged in user, who is using the plugin.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
makes sense now why it is being treated as an Anonymous user!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hmm, yes it does. Maybe it is just impossible to set this property with the UserAccessor, I'll try it with CrowdDisabledUserManager ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.