Karl,

I have discovered another issue with the JIRA authority connection.
org.apache.manifoldcf.authorities.authorities.jira.JiraSession.checkUserExists() function, makes use of the JIRA “/user/search” API, with a maxResults = 1, unfortunately the search does wild card matching on multiple user attributes e.g. emailAddress, displayName etc. So if the username parameter is a substring of any of these attributes then there is no guarantee that the first result will be the desired user and the userName.equals(value) will fail.

I propose that the checkUserExists() function make use of the JIRA “user” API rather than the “user/search” API.
I have implemented the following in my environment to fix my current issue in org.apache.manifoldcf.authorities.authorities.jira.JiraSession….

  /** Check if user exists.
  */
  public boolean checkUserExists(String userName) throws IOException, ResponseException, ManifoldCFException {
    JiraUserQueryResults qr = new JiraUserQueryResults();
    getRest("user?username="+URLEncoder.encode(userName)+"&maxResults=1&startAt=0", qr);
    List<String> values = new ArrayList<String>();
    qr.getNames(values);
    if (values.size() == 0)
      return false;
    for (String value : values) {
      if (userName.equals(value))
        return true;
    }
    return false;
  }
The above change requires the following update to org.apache.manifoldcf.authorities.authorities.jira.JiraUserQueryResults….

  public void getNames(List<String> nameBuffer) {
    if (object instanceof JSONArray) {
      JSONArray users = (JSONArray)object;
      for (Object user : users) {
        addName(user, nameBuffer);
      }
    } else {
      addName(object, nameBuffer);
    }
  }

  private void addName(Object object, List<String> nameBuffer) {
   if (object instanceof JSONObject) {
     JSONObject jo = (JSONObject)object;
     nameBuffer.add(jo.get(KEY_NAME).toString());
   }
  }

BTW, I have noticed that org.apache.manifoldcf.authorities.authorities.jira.JiraSession.getRepositoryInfo() function, has a JIRA API call similar to the below issue "user/search?username=&maxResults=1&startAt=0" that may need to be updated to "user/search?username=%27%27&maxResults=1&startAt=0", as it will currently not return any results.
Regards
Damien Collis
Team Leader – Systems Integration
Link Group

•   Level 4, 1A Homebush Bay Drive, Rhodes NSW 2138
• Email: [EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>
• Ph: +61 2 8571 5616

From: Damien Collis [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 6 February 2018 10:33 AM
To: [EMAIL PROTECTED]
Subject: RE: How to extract JIRA authorities

Karl,

The patch was successful, I now see “allow_token_document” fields being passed to SOLR.
Regards
Damien Collis
Team Leader – Systems Integration
Link Group

•   Level 4, 1A Homebush Bay Drive, Rhodes NSW 2138
• Email: [EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>
• Ph: +61 2 8571 5616

From: Karl Wright [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 6 February 2018 1:16 AM
To: [EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>
Subject: Re: How to extract JIRA authorities

Patch attached, and fix committed to trunk.  Please let me know if it works for you.  Thanks!!

Karl
On Mon, Feb 5, 2018 at 9:11 AM, Karl Wright <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>> wrote:
I created CONNECTORS-1493 and will attach a patch shortly.

Karl
On Mon, Feb 5, 2018 at 9:09 AM, Karl Wright <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>> wrote:
What this is supposed to be doing is grabbing all the users that are associated with the given issue.

Clearly then the first query is bogus and that's why it's not working.

It sounds like all that is needed is to add two single quotes to the query.  I'm happy to add this to the code, if you'd like to create a ticket, and then you can see if it fixes the problem.

Karl
On Sun, Feb 4, 2018 at 9:15 PM, Damien Collis <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>> wrote:
Karl,

The jira documentation states:  Username - the username filter, no users returned if left blank
So, I have run a couple of tests against my JIRA server, and it looks like single quotes are required in the request, e.g. username=’’ (username=%27%27)

Here are the results of my tests...
Request 1 (Returns nothing)
http://jira/rest/api/latest/user/viewissue/search?username=&issueKey=REQ-9999&maxResults=1000&startAt=0<https://urldefense.proofpoint.com/v2/url?u=http-3A__jira_rest_api_latest_user_viewissue_search-3Fusername-3D-26issueKey-3DREQ-2D9999-26maxResults-3D1000-26startAt-3D0&d=DwMFaQ&c=EyrAshB9xIzcegaT9SDe6g&r=Gn5yxeb6W9ERepUyEmssft7I4Tobgyxsu0tR69ePkS8&m=gNuOkz5uz22-KjhqZuBbMEo56ecKpKk2fAQi2o2Wc_4&s=1M3h_krHqwB4VDVO3f7FMOJ6BgGY2pTQxomZhP-ut74&e=>
Response 1
[]

Request 2 (Returns only the username matching the request)
http://jira/rest/api/latest/user/viewissue/search?username=FredFlintstone&issueKey=REQ-9999&maxResults=1000&startAt=0<https://urldefense.proofpoint.com/v2/url?u=http-3A__jira_rest_api_latest_user_viewissue_search-3Fusername-3DFredFlintstone-26issueKey-3DREQ-2D9999-26maxResults-3D1000-26startAt-3D0&d=DwMFaQ&c=EyrAshB9xIzcegaT9SDe6g&r=Gn5yxeb6W9ERepUyEmssft7I4Tobgyxsu0tR69ePkS8&m=gNuOkz5uz22-KjhqZuBbMEo56ecKpKk2fAQi2o2Wc_4&s=WJxRFsOpMWHXGHvE-3wd7nWmt6Q7U_pwC2Svkr9w6To&e=>
Response 2
[{"self":"http://jira.apac.linkgroup.corp/rest/api/2/user?username=FredFlintstone<https://urldefense.proofpoint.com/v2/url?u=http-3A__jira.apac.linkgroup.corp_rest_api_2_user-3Fusername-3DFredFlintstone&d=DwMFaQ&c=EyrAshB9xIzcegaT9SDe6g&r=Gn5yxeb6W9ERepUyEmssft7I4Tobgyxsu0tR69ePkS8&m=gNuOkz5uz22-KjhqZuBbMEo56ecKpKk2fAQi2o2Wc_4&s=xDHVwusBmrHGyBx4jMFFPpa_Yb02bAtFaEbHB8p6JqE&e=>","key":"FredFlintstone","name":"FredFlintstone","emailAddress":"[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>","avatarUrls":{"48x48":"http://jira.apac.linkgroup.corp/secure/useravatar?ownerId=FredFlintstone&avatarId=14201<https://urldefense.proofpoint.com/v
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB