Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to Reset Captcha with the API for a User

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

 

 

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.).

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. 

 

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)

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

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. 

yes i am trying in Jira 6

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
Community showcase
Published in Jira Service Management

Next level incident management in Jira Service Management

Hello Atlassian Community! We’re thrilled to announce some exciting changes to incident management in Jira Service Management Cloud, in order to give your teams extra muscle during incidents, and ...

1,544 views 20 12
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you