Class CoreStitchAuth<StitchUserT extends CoreStitchUser>
- java.lang.Object
-
- com.mongodb.stitch.core.auth.internal.CoreStitchAuth<StitchUserT>
-
- Type Parameters:
StitchUserT
- The type of users that will be consumed/produced by this component.
- All Implemented Interfaces:
StitchAuthRequestClient
,Closeable
,AutoCloseable
- Direct Known Subclasses:
StitchAuthImpl
,StitchAuthImpl
public abstract class CoreStitchAuth<StitchUserT extends CoreStitchUser> extends Object implements StitchAuthRequestClient, Closeable
CoreStitchAuth is responsible for authenticating clients as well as acting as a client for authenticated requests. Synchronization in this class happens around theactiveUserAuthInfo
andactiveUser
objects such that access to them is 1. always atomic and 2. queued to prevent excess token refreshes.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CoreStitchAuth(StitchRequestClient requestClient, StitchAuthRoutes authRoutes, Storage storage, boolean useTokenRefresher)
-
Method Summary
Modifier and Type Method Description void
close()
Closes the component down by stopping the access token refresher.Response
doAuthenticatedRequest(StitchAuthRequest stitchReq)
Performs a request against Stitch using the providedStitchAuthRequest
object, and returns the response.<T> T
doAuthenticatedRequest(StitchAuthRequest stitchReq, Class<T> resultClass, CodecRegistry codecRegistry)
Performs a request against Stitch using the providedStitchAuthRequest
object, and decodes the JSON body of the response into a T value as specified by the provided class type.<T> T
doAuthenticatedRequest(StitchAuthRequest stitchReq, Decoder<T> resultDecoder)
Performs a request against Stitch using the providedStitchAuthRequest
object, and decodes the response using the provided result decoder.protected StitchAuthRoutes
getAuthRoutes()
protected String
getDeviceId()
protected Document
getDeviceInfo()
protected StitchRequestClient
getRequestClient()
StitchUserT
getUser()
Returns the active logged in user.protected abstract StitchUserFactory<StitchUserT>
getUserFactory()
protected boolean
hasDeviceId()
boolean
isLoggedIn()
Returns whether or not the client is logged in.boolean
isLoggedInInterruptibly()
Returns whether or not the client is logged in.protected StitchUserT
linkUserWithCredentialInternal(CoreStitchUser user, StitchCredential credential)
List<StitchUserT>
listUsers()
protected StitchUserT
loginWithCredentialInternal(StitchCredential credential)
protected void
logoutInternal()
protected void
logoutUserWithIdInternal(String userId)
protected abstract void
onActiveUserChanged(StitchUserT currentActiveUser, StitchUserT previousActiveUser)
protected abstract void
onAuthEvent()
protected abstract void
onListenerInitialized()
protected abstract void
onUserAdded(StitchUserT createdUser)
protected abstract void
onUserLinked(StitchUserT linkedUser)
protected abstract void
onUserLoggedIn(StitchUserT loggedInUser)
protected abstract void
onUserLoggedOut(StitchUserT loggedOutUser)
protected abstract void
onUserRemoved(StitchUserT removedUser)
<T> Stream<T>
openAuthenticatedStream(StitchAuthRequest stitchReq, Decoder<T> decoder)
void
refreshAccessToken()
protected void
removeUserInternal()
protected void
removeUserWithIdInternal(String userId)
StitchUserT
switchToUserWithId(String userId)
-
-
-
Constructor Detail
-
CoreStitchAuth
protected CoreStitchAuth(StitchRequestClient requestClient, StitchAuthRoutes authRoutes, Storage storage, boolean useTokenRefresher)
-
-
Method Detail
-
getUserFactory
protected abstract StitchUserFactory<StitchUserT> getUserFactory()
-
onAuthEvent
protected abstract void onAuthEvent()
-
onUserAdded
protected abstract void onUserAdded(StitchUserT createdUser)
-
onUserLoggedIn
protected abstract void onUserLoggedIn(StitchUserT loggedInUser)
-
onUserLoggedOut
protected abstract void onUserLoggedOut(StitchUserT loggedOutUser)
-
onActiveUserChanged
protected abstract void onActiveUserChanged(StitchUserT currentActiveUser, @Nullable StitchUserT previousActiveUser)
-
onUserRemoved
protected abstract void onUserRemoved(StitchUserT removedUser)
-
onUserLinked
protected abstract void onUserLinked(StitchUserT linkedUser)
-
onListenerInitialized
protected abstract void onListenerInitialized()
-
getDeviceInfo
protected Document getDeviceInfo()
-
isLoggedInInterruptibly
@CheckReturnValue(when=NEVER) public boolean isLoggedInInterruptibly() throws InterruptedException
Returns whether or not the client is logged in.- Returns:
- whether or not the client is logged in.
- Throws:
InterruptedException
-
isLoggedIn
@CheckReturnValue(when=NEVER) public boolean isLoggedIn()
Returns whether or not the client is logged in.- Returns:
- whether or not the client is logged in.
-
getUser
@Nullable public StitchUserT getUser()
Returns the active logged in user.
-
listUsers
public List<StitchUserT> listUsers()
-
doAuthenticatedRequest
public Response doAuthenticatedRequest(StitchAuthRequest stitchReq)
Performs a request against Stitch using the providedStitchAuthRequest
object, and returns the response.- Specified by:
doAuthenticatedRequest
in interfaceStitchAuthRequestClient
- Parameters:
stitchReq
- the request to perform.- Returns:
- the response to the request, successful or not.
-
doAuthenticatedRequest
public <T> T doAuthenticatedRequest(StitchAuthRequest stitchReq, Decoder<T> resultDecoder)
Performs a request against Stitch using the providedStitchAuthRequest
object, and decodes the response using the provided result decoder.- Specified by:
doAuthenticatedRequest
in interfaceStitchAuthRequestClient
- Parameters:
stitchReq
- The request to perform.- Returns:
- The response to the request, successful or not.
-
doAuthenticatedRequest
public <T> T doAuthenticatedRequest(StitchAuthRequest stitchReq, Class<T> resultClass, CodecRegistry codecRegistry)
Performs a request against Stitch using the providedStitchAuthRequest
object, and decodes the JSON body of the response into a T value as specified by the provided class type. The type will be decoded using the codec found for T in the codec registry given. If the provided type is not supported by the codec registry to be used, the method will throw aCodecConfigurationException
.- Specified by:
doAuthenticatedRequest
in interfaceStitchAuthRequestClient
- Type Parameters:
T
- the type into which the JSON response will be decoded into.- Parameters:
stitchReq
- the request to perform.resultClass
- the class that the JSON response should be decoded as.codecRegistry
- the codec registry used for de/serialization.- Returns:
- the decoded value.
-
openAuthenticatedStream
public <T> Stream<T> openAuthenticatedStream(StitchAuthRequest stitchReq, Decoder<T> decoder) throws InterruptedException
- Specified by:
openAuthenticatedStream
in interfaceStitchAuthRequestClient
- Throws:
InterruptedException
-
switchToUserWithId
public StitchUserT switchToUserWithId(String userId) throws StitchClientException
- Throws:
StitchClientException
-
loginWithCredentialInternal
protected StitchUserT loginWithCredentialInternal(StitchCredential credential)
-
linkUserWithCredentialInternal
protected StitchUserT linkUserWithCredentialInternal(CoreStitchUser user, StitchCredential credential)
-
logoutInternal
protected void logoutInternal()
-
logoutUserWithIdInternal
protected void logoutUserWithIdInternal(String userId) throws StitchClientException
- Throws:
StitchClientException
-
removeUserInternal
protected void removeUserInternal()
-
removeUserWithIdInternal
protected void removeUserWithIdInternal(String userId)
-
hasDeviceId
protected boolean hasDeviceId()
-
getDeviceId
protected String getDeviceId()
-
refreshAccessToken
public void refreshAccessToken()
-
close
public void close() throws IOException
Closes the component down by stopping the access token refresher.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getRequestClient
protected StitchRequestClient getRequestClient()
-
getAuthRoutes
protected StitchAuthRoutes getAuthRoutes()
-
-