Class OAuthServer
- java.lang.Object
-
- com.sodius.oslc.server.oauth.OAuthServer
-
public abstract 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:
OAuthFilter
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
OAuthServer(ServletContext context)
Creates a new instance of the specified servlet context.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected abstract org.eclipse.lyo.server.oauth.core.consumer.ConsumerStore
createConsumerStore(ServletContext context)
Creates the store that manages the registered OAuth consumers.protected abstract FriendStore
createFriendStore(ServletContext context)
Creates the store that manages the registered OAuth friends.protected abstract OAuthHandler
createOAuthHandler(HttpServletRequest request)
Creates a handler to manage user authorization to access remote OSLC applications.OslcClientFactory
getClientFactory(OAuthIdentity identity)
Returns a factory to create anOslcClient
for the given user identity.OslcClientFactory
getClientFactory(HttpServletRequest request)
Returns a factory to create anOslcClient
associated to the specified request.org.eclipse.lyo.server.oauth.core.consumer.ConsumerStore
getConsumerStore()
Returns the store controlling the OAuth consumers registered for this server.FriendProvider
getFriendProvider()
Returns a provider of friends, used to instantiate OAuth OSLC clients.FriendStore
getFriendStore()
Returns the store controlling the OAuth friends registered for this server.static OAuthServer
getInstance()
Returns the singleton instance configured.static OAuthServer
getInstance(ServletContext context)
Deprecated.use getInstance(), the servlet context does not bring value herestatic void
setInstance(OAuthServer oauthServer)
Replaces the current server instance with the given one.void
validateAdministratorAccess(HttpServletRequest request)
Verifies the user performing the request is an administrator.
-
-
-
Constructor Detail
-
OAuthServer
protected OAuthServer(ServletContext context)
Creates a new instance of the specified servlet context.- Parameters:
context
- the servlet context.
-
-
Method Detail
-
getInstance
public static OAuthServer getInstance()
Returns the singleton instance configured. This method can safely be called onceOAuthFilter
has been initialized orsetInstance(OAuthServer)
was called.- Returns:
- the singleton OAuth Server.
- Throws:
WebApplicationException
- if OAuthServer was not initialized- Since:
- 3.8.0
-
getInstance
@Deprecated(since="3.8.0", forRemoval=false) public static OAuthServer getInstance(ServletContext context)
Deprecated.use getInstance(), the servlet context does not bring value hereReturns the singleton instance configured for the specified servlet context. This method can safely be called onceOAuthFilter
has been initialized orsetInstance(OAuthServer)
was called.- Parameters:
context
- the servlet context.- Returns:
- the singleton OAuth Server.
- Throws:
WebApplicationException
- if OAuthServer was not initialized by OAuthFilter
-
setInstance
public static void setInstance(OAuthServer oauthServer)
Replaces the current server instance with the given one.This initialization is performed by the
OAuthFilter
. This method shall be called explicitly only in the event the initialization is to perform beforeOAuthFilter
is even executed.- 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.
-
createFriendStore
protected abstract FriendStore createFriendStore(ServletContext context)
Creates the store that manages the registered OAuth friends.- Parameters:
context
- the servlet context.- Returns:
- the created 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:
OAuthStore
-
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.
-
createConsumerStore
protected abstract org.eclipse.lyo.server.oauth.core.consumer.ConsumerStore createConsumerStore(ServletContext context)
Creates the store that manages the registered OAuth consumers.- Parameters:
context
- the servlet context.- Returns:
- the created store.
-
getClientFactory
public OslcClientFactory getClientFactory(HttpServletRequest request)
Returns a factory to create anOslcClient
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:
getFriendProvider()
,createOAuthHandler(HttpServletRequest)
-
getClientFactory
public OslcClientFactory getClientFactory(OAuthIdentity identity)
Returns a factory to create anOslcClient
for the given user identity. This factory can be used when no HTTP incoming request is known. If a request is accessible, prefer usinggetClientFactory(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
-
createOAuthHandler
protected abstract OAuthHandler createOAuthHandler(HttpServletRequest request)
Creates a handler to manage user authorization to access remote OSLC applications. The handler is used by the OSLC client factory provided by this server instance to access remote applications.Subclasses are recommended to create a
RedirectOAuthHandler
instance.- Parameters:
request
- the servlet request- Returns:
- a
OAuthHandler
to manage user authorization to access remote OSLC applications. - See Also:
getClientFactory(HttpServletRequest)
,RedirectOAuthHandler
-
validateAdministratorAccess
public void validateAdministratorAccess(HttpServletRequest request)
Verifies the user performing the request is an administrator. Throws aWebApplicationException
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.
-
-