Class OAuthServer

java.lang.Object
com.sodius.oslc.server.oauth.OAuthServer
Direct Known Subclasses:
BrokerOAuthServer

public class OAuthServer extends Object
The central place for OAuth capabilities provided on server side.

This class is recommended to be used in conjunction with OAuthFilter.

Since:
1.3.0
See Also:
  • Constructor Details

    • OAuthServer

      public OAuthServer(FriendStore friendStore, org.eclipse.lyo.server.oauth.core.consumer.ConsumerStore consumerStore, OAuthApplication application, Function<HttpServletRequest,OAuthHandler> handlerFactory)
      Creates a new instance of OAuth server.

      The given function is to create a OAuth handler managing user authorization to access remote OSLC applications, used by OSLC client factories created by this instance. The function is recommended to return an instance of RedirectOAuthHandler.

      Parameters:
      friendStore - the friend store, to fetch content from remote OSLC applications
      consumerStore - the consumer store, to control access from remote OSLC applications
      application - the OAuth application controlling user authentication
      handlerFactory - a function to create a OAuthHandler for a given incoming servlet request
      Since:
      4.0.0
      See Also:
  • Method Details

    • getInstance

      public static OAuthServer getInstance()
      Returns the singleton instance.
      Returns:
      the singleton OAuth Server.
      Throws:
      WebApplicationException - if OAuthServer instance is not set
      Since:
      3.8.0
      See Also:
    • setInstance

      public static void setInstance(OAuthServer oauthServer)
      Replaces the current server instance with the given one.
      Parameters:
      oauthServer - the new server instance
      Since:
      3.8.0
    • getFriendStore

      public final FriendStore getFriendStore()
      Returns the store controlling the OAuth friends registered for this server.
      Returns:
      the friend store.
    • getFriendProvider

      public final FriendProvider getFriendProvider()
      Returns a provider of friends, used to instantiate OAuth OSLC clients.
      Returns:
      a provider of friends for OAuth OSLC clients.
      See Also:
    • getConsumerStore

      public final org.eclipse.lyo.server.oauth.core.consumer.ConsumerStore getConsumerStore()
      Returns the store controlling the OAuth consumers registered for this server.
      Returns:
      the consumer store.
    • getApplication

      public final OAuthApplication getApplication()
      Returns the OAuth application.
      Returns:
      the OAuth application
      Since:
      4.0.0
    • getClientFactory

      public OslcClientFactory getClientFactory(HttpServletRequest request)
      Returns a factory to create an OslcClient associated to the specified request.

      The factory is stored in the request attributes, so that it's reused on a successive calls. The factory creates clients that can be safely used in concurrent threads.

      The factory uses the friends configured in the friend store of this server instance. It uses the OAuthHandler provided by this server instance to handle user authorization.

      Parameters:
      request - the servlet request.
      Returns:
      a factory to create OslcClient instances.
      See Also:
    • getClientFactory

      public OslcClientFactory getClientFactory(OAuthIdentity identity)
      Returns a factory to create an OslcClient for the given user identity. This factory can be used when no HTTP incoming request is known. If a request is accessible, prefer using getClientFactory(HttpServletRequest) which provides more features.

      This factory is limited to existing OAuth tokens yet acquired for the given user identity, through getClientFactory(HttpServletRequest) in regular OSLC flows. It implies outgoing requests executed with OSLC clients built with this factory will be rejected with HTTP 401, if there's not yet a valid OAuth token for the given friend application.

      The factory creates clients that can be safely used in concurrent threads.

      Parameters:
      identity - the user identity for which OAuth tokens were acquired
      Returns:
      a factory to create OslcClient instances.
      Since:
      3.8.0
    • validateAdministratorAccess

      public void validateAdministratorAccess(HttpServletRequest request)
      Verifies the user performing the request is an administrator. Throws a WebApplicationException if the current user is not an administrator.
      Parameters:
      request - the request which requires administrator access.
      Throws:
      WebApplicationException - if the current user is not an administrator.