Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JAVA API to sync external directories

Scott Selberg
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 7, 2017

Hi,  

I've noticed a few people who want a REST method to trigger an external user directory sync.  The primary use case, and the one for my company, is we sometime know when a change has been made that we want JIRA or Confluence to pickup and don't want to set a very quick auto-sync interval and don't want to wait for a really long one.

I wrote a rest service for Confluence that performed the task, and I'm trying to port it to JIRA.   Here's the java portion I use for Confluence.

package com.keysight.confluence.support.rest;

import java.util.Map;
import java.util.List;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.atlassian.plugins.rest.common.security.AnonymousAllowed;
import com.atlassian.crowd.manager.directory.DirectoryManager;
import com.atlassian.crowd.embedded.api.Directory;
import com.atlassian.crowd.manager.directory.SynchronisationMode;

@Path("/directory")
public class ADRestService
{
   private final DirectoryManager directoryManager;

   public ADRestService( DirectoryManager directoryManager)
   {
       this.directoryManager      = directoryManager;
   }

   @GET
   @AnonymousAllowed
   @Path("sync")
   public Response syncAllDirectories( ){
      String response = "<p>Syncing</p>";

      List directories = directoryManager.findAllDirectories();
      for( Directory directory : directoryManager.findAllDirectories() ){
         try{ 
            if( directoryManager.isSynchronisable( directory.getId() ) 
            && !directoryManager.isSynchronising( directory.getId() )){
               directoryManager.synchroniseCache( directory.getId(), SynchronisationMode.INCREMENTAL );
            }
         } catch( Exception e ){
            // com.atlassian.crowd.exception.DirectoryInstantiationException
            // com.atlassian.crowd.exception.OperationFailedException
         }
      }

      return Response.ok( new RestResponse( response ) ).build();
   }
}

In porting this to JIRA, I've discovered that I need to enable the jira-core artifact in the pom.xml otherwise it can't find the DirectoryManager.  The comment in the pom created by Atlassian indicates that I should be doing this using methods in the jira-api.  Does anybody know what those may be?

        <!-- Add dependency on jira-core if you want access to JIRA implementation classes as well as the sanctioned API. -->
        <!-- This is not normally recommended, but may be required eg when migrating a plugin originally developed against JIRA 4.x -->
        <!--
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-core</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
        -->
 

 

2 answers

0 votes
fayaz jira
Contributor
March 15, 2019

@Scott Selberg @Ana Retamal 


please let me know about this java api to sync external directories.

Thanks

0 votes
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 13, 2017

Hi Scott!

This kind of questions will get a better and faster answer if you post them in our Developer Community. There you'll find developers, product experts and vendors that will be able to help you with your question :)

Cheers,

Ana

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events