Login User within Plugin (Jira 7)

Is it possible to login a user within a plugin?

 

i am developing a scheduler-plugin that runs every X minutes and this plugin create or updates issues. but i always get an error if i do not set the permissions (of the projects) to ANY

Error:

Errors: {pid=Anonymous users do not have permission to create issues in this project. Please try logging in first.}

1 answer

In order to log-in a user, the user must somehow provide his credentials - this is not possible in a background job such as a job, executed by the plugin scheduler. What you can do is use a "system" user to create the user - some user in JIRA which has been configured by the administrator in a configuration UI of your plugin and can be used when creating issues. You don't actually need the user password for your job to create issues on behalf of this user - you only need the ApplicationUser instance retrieved using the UserManager service.

I am doing exactly what you described but getting the same error. It seems even if i set the user explicitly on the issueinputparameters, the issue creation service simply ignores it. Do you have an idea what's causing this?

Please share your code so I can take a look.

This is it:

ApplicationUser user = userManager.getUserByName("admin");
            
            IssueInputParameters params = issueService.newIssueInputParameters().setProjectId(10000L).setIssueTypeId("issuetypeId")
                    .setSummary("summary").setAssigneeId("assigneuser").setDescription("Please enter description");
            
            CreateValidationResult result = issueService.validateCreate(user, params);
            
            if(result.isValid()){
                
                IssueResult createResult = issueService.create(user, result);
                if (!createResult.isValid())
                {
                    Issue createdIssue = createResult.getIssue();
                    
                }
            }

I tried even injecting login service and logging in as admin before the above code:

LoginResult res = loginService.authenticate(user, "1234");

 

Thank you!

When you execute the above code (which seems correct) do you see the same error as in the original post? Are you sure there is an active user with the name admin?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,375 views 0 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you