Class SyncopeClient

    • Method Detail

      • cleanup

        protected void cleanup()
      • getAddress

        public String getAddress()
        Gives the base address for REST calls.
        Returns:
        the base address for REST calls
      • delegatedBy

        public SyncopeClient delegatedBy​(String delegating)
        Requests to invoke services as delegating user.
        Parameters:
        delegating - delegating username
        Returns:
        this instance, for fluent usage
      • refresh

        public void refresh()
        Attempts to extend the lifespan of the JWT currently in use.
      • logout

        public void logout()
        Invalidates the JWT currently in use.
      • login

        public void login​(AuthenticationHandler handler)
        (Re)initializes the current instance with the authentication capabilities of the provided handler.
        Parameters:
        handler - authentication handler
      • getJWT

        public String getJWT()
        Returns the JWT in used by this instance, passed with the HttpHeaders.AUTHORIZATION header in all requests. It can be null (in case AnonymousAuthenticationHandler was used).
        Returns:
        the JWT in used by this instance
      • getDomain

        public String getDomain()
        Returns the domain configured for this instance, or SyncopeConstants.MASTER_DOMAIN if not set.
        Returns:
        the domain configured for this instance
      • getService

        public <T> T getService​(Class<T> serviceClass)
        Creates an instance of the given service class, with configured content type and authentication.
        Type Parameters:
        T - any service class
        Parameters:
        serviceClass - service class reference
        Returns:
        service instance of the given reference class
      • header

        public static <T> T header​(T service,
                                   String key,
                                   Object... values)
        Sets the given header on the give service instance.
        Type Parameters:
        T - any service class
        Parameters:
        service - service class instance
        key - HTTP header key
        values - HTTP header values
        Returns:
        given service instance, with given header set
      • prefer

        public static <T> T prefer​(T service,
                                   Preference preference)
        Sets the Prefer header on the give service instance.
        Type Parameters:
        T - any service class
        Parameters:
        service - service class instance
        preference - preference to be set via Prefer header
        Returns:
        given service instance, with Prefer header set
      • nullPriorityAsync

        public static <T> T nullPriorityAsync​(T service,
                                              boolean nullPriorityAsync)
        Asks for asynchronous propagation towards external resources with null priority.
        Type Parameters:
        T - any service class
        Parameters:
        service - service class instance
        nullPriorityAsync - whether asynchronous propagation towards external resources with null priority is requested
        Returns:
        service instance of the given reference class, with related header set
      • match

        protected static <T> T match​(T service,
                                     javax.ws.rs.core.EntityTag etag,
                                     boolean ifNot)
        Sets the If-Match or If-None-Match header on the given service instance.
        Type Parameters:
        T - any service class
        Parameters:
        service - service class instance
        etag - ETag value
        ifNot - if true then If-None-Match is set, If-Match otherwise
        Returns:
        given service instance, with If-Match or If-None-Match set
      • ifMatch

        public static <T> T ifMatch​(T service,
                                    javax.ws.rs.core.EntityTag etag)
        Sets the If-Match header on the given service instance.
        Type Parameters:
        T - any service class
        Parameters:
        service - service class instance
        etag - ETag value
        Returns:
        given service instance, with If-Match set
      • ifNoneMatch

        public static <T> T ifNoneMatch​(T service,
                                        javax.ws.rs.core.EntityTag etag)
        Sets the If-None-Match header on the given service instance.
        Type Parameters:
        T - any service class
        Parameters:
        service - service class instance
        etag - ETag value
        Returns:
        given service instance, with If-None-Match set
      • getLatestEntityTag

        public static <T> javax.ws.rs.core.EntityTag getLatestEntityTag​(T service)
        Fetches ETag header value from latest service run (if available).
        Type Parameters:
        T - any service class
        Parameters:
        service - service class instance
        Returns:
        ETag header value from latest service run (if available)
      • batch

        public BatchRequest batch()
        Initiates a new Batch request. The typical operation flow is:
         BatchRequest batchRequest = syncopeClient.batch();
         batchRequest.getService(UserService.class).create(...);
         batchRequest.getService(UserService.class).update(...);
         batchRequest.getService(GroupService.class).update(...);
         batchRequest.getService(GroupService.class).delete(...);
         ...
         BatchResponse batchResponse = batchRequest().commit();
         List<BatchResponseItem> items = batchResponse.getItems()
         
        Returns:
        empty Batch request