Jira data center addOn(plugin using Java) which act as a Application user to assign issues to the users

Hi,

My requirement is - Jira data center addOn(plugin using Java) which act as a Application user to assign issues to the users.
How the application user will be created through programmatically or through XML configuration(atlassian-plugin.xml).
How to assign the permissions(Issue Assignable) to that application user?

Did anyone have any idea on this?

Thank you,
Mahesh

Hi Mahesh!
To create an application user programmatically in Jira and assign permissions, you can follow these steps:

Creating an Application User Programmatically

You can use the UserService to create a new user programmatically. Here’s an example:

import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.user.util.UserService;

// Get the UserService component
UserService userService = ComponentAccessor.getComponent(UserService.class);
UserManager userManager = ComponentAccessor.getComponent(UserManager.class);

// Create a new user
ApplicationUser newUser = userService.newUserBuilder("newUser", "newUser@example.com", "New User")
    .emailAddress("newUser@example.com")
    .name("New User")
    .build();

// Validate and update the user
UserService.UpdateUserValidationResult validationResult = userService.validateUpdateUser(newUser);
if (validationResult.isValid()) {
    userService.updateUser(validationResult);
}

Assigning Permissions

To assign the “Issue Assignable” permission to the application user, you can use the PermissionHelper. Here’s an example:

import com.atlassian.jira.security.roles.Permissions;
import com.atlassian.jira.security.roles.PermissionsHelper;

PermissionsHelper permissionsHelper = ComponentAccessor.getComponent(PermissionsHelper.class);
permissionsHelper.assignPermission("Assignable User", newUser, "jira-software-users");

XML Configuration (atlassian-plugin.xml)

Alternatively, you can define the user and permissions in your atlassian-plugin.xml file:

<atlassian-plugin key="com.example.myplugin" version="1.0">
    <plugin-descriptor>
        <component plugin="com.atlassian.plugins.rest.module" key="OsgiResourceConfig">
            <resource key="myResource" path="/myresource" method="GET" handler="com.example.myplugin.MyResourceHandler"/>
        </component>
    </plugin-descriptor>
    <user>
        <name>newUser</name>
        <email>newUser@example.com</email>
        <displayName>New User</displayName>
        <applicationKeys>
            <key>jira-software</key>
        </applicationKeys>
    </user>
    <permissions>
        <permission>
            <key>Assignable User</key>
            <group>jira-software-users</group>
        </permission>
    </permissions>
</atlassian-plugin>

These examples should help you get started with creating an application user and assigning the necessary permissions. If you have any more questions or need further assistance, feel free to ask!

Best regards
Daniel