How to Reset Captcha with the API for a User

C
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.
April 11, 2017

We Have a request in our JIRA service desk portal for users to reset thier Captcha when they have locked themselves out of the tool.   (this typically happens when account passwords have changed and automation has not been updated).  To day this is manual process that we are looking to automate.    

We would like to create a script for allowing users to reset thier capcha for JIRA, Confluence and Bitbucket.  does anyone know if this is possible via the API Calls?  I could not find the API calls on developer.atlassian.com

 

2 answers

2 votes
Jonny Carter
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.
April 11, 2017

 

 

This may seem an odd question, but if you're going to let users disable their own CAPTCHA, why not just turn it off?

 

That said, I'm pretty sure that you can use the LoginManager for this.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager

def loginManager = ComponentAccessor.getComponent(LoginManager)
loginManager.resetFailedLoginCount(user)

You'll need to set the user variable according to some logic -- obviously you don't want to get the logged in user! You could get the user via the userManager, like...

 

def user = ComponentAccessor.userManager.getUserByName("username")

How to set the username string will depend on the context you're working in (REST Endpoint, Workflow Function, etc.).

C
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.
April 12, 2017

Since we use an identity provider, the user does not have access to the Atalssian login screens and need an alternative method to reset captcha. 

 

therefore, we want to create an automated script to reset captcha that a  unloack a user when a ticket is submittd. 

 

Abyakta Lenka June 15, 2017

I tried the above code but its seems its throwing error.

 

This is what tried:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager
def user = ComponentAccessor.userManager.getUserByName("wtuscan")
def loginManager = ComponentAccessor.getComponent(LoginManager)
loginManager.resetFailedLoginCount(user)

Result:

Error
No signature of method: com.atlassian.jira.security.login.LoginManagerImpl.resetFailedLoginCount() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser) values: [wtuscan(wtuscan)] Possible solutions: resetFailedLoginCount(com.atlassian.crowd.embedded.api.User)


groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.security.login.LoginManagerImpl.resetFailedLoginCount() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser) values: [wtuscan(wtuscan)]
Possible solutions: resetFailedLoginCount(com.atlassian.crowd.embedded.api.User)
 at Script18.run(Script18.groovy:5)
Ray Widaman July 12, 2017

I am trying to figure this out as well, were you able to resolve these errors?

Thanos Batagiannis [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.
July 17, 2017

Hey guys, 

In which version of JIRA you are ? Jonny's answer is the right way in JIRa 7. 

From your error Abyakta ot seems you are in a JIRA v6.* 

regards, Thanos. 

Abyakta Lenka November 21, 2017

yes i am trying in Jira 6

0 votes
Joe Jadamec November 10, 2021

Thanks Jonny, this worked in Jira 8.13 in scriptrunner. 

Add usernames to the list of strings.
loop checks each user and resets failed count if > 0.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager
import com.atlassian.jira.bc.security.login.LoginInfoImpl
def loginManager = ComponentAccessor.getComponent(LoginManager)
List<String> users = ["username1", "username2", "username3"]

users.each{ val ->
  def user = ComponentAccessor.userManager.getUserByName(val)
  if (user != null){
    def userLoginInfo = loginManager.getLoginInfo(val)
    if(userLoginInfo.getCurrentFailedLoginCount() > 0) {
      log.info("reseting failed count for " + val)
      loginManager.resetFailedLoginCount(user)
    }
  }
}



Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events