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 theactiveUserAuthInfoandactiveUserobjects such that access to them is 1. always atomic and 2. queued to prevent excess token refreshes.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCoreStitchAuth(StitchRequestClient requestClient, StitchAuthRoutes authRoutes, Storage storage, boolean useTokenRefresher)
-
Method Summary
Modifier and Type Method Description voidclose()Closes the component down by stopping the access token refresher.ResponsedoAuthenticatedRequest(StitchAuthRequest stitchReq)Performs a request against Stitch using the providedStitchAuthRequestobject, and returns the response.<T> TdoAuthenticatedRequest(StitchAuthRequest stitchReq, Class<T> resultClass, CodecRegistry codecRegistry)Performs a request against Stitch using the providedStitchAuthRequestobject, and decodes the JSON body of the response into a T value as specified by the provided class type.<T> TdoAuthenticatedRequest(StitchAuthRequest stitchReq, Decoder<T> resultDecoder)Performs a request against Stitch using the providedStitchAuthRequestobject, and decodes the response using the provided result decoder.protected StitchAuthRoutesgetAuthRoutes()protected StringgetDeviceId()protected DocumentgetDeviceInfo()protected StitchRequestClientgetRequestClient()StitchUserTgetUser()Returns the active logged in user.protected abstract StitchUserFactory<StitchUserT>getUserFactory()protected booleanhasDeviceId()booleanisLoggedIn()Returns whether or not the client is logged in.booleanisLoggedInInterruptibly()Returns whether or not the client is logged in.protected StitchUserTlinkUserWithCredentialInternal(CoreStitchUser user, StitchCredential credential)List<StitchUserT>listUsers()protected StitchUserTloginWithCredentialInternal(StitchCredential credential)protected voidlogoutInternal()protected voidlogoutUserWithIdInternal(String userId)protected abstract voidonActiveUserChanged(StitchUserT currentActiveUser, StitchUserT previousActiveUser)protected abstract voidonAuthEvent()protected abstract voidonListenerInitialized()protected abstract voidonUserAdded(StitchUserT createdUser)protected abstract voidonUserLinked(StitchUserT linkedUser)protected abstract voidonUserLoggedIn(StitchUserT loggedInUser)protected abstract voidonUserLoggedOut(StitchUserT loggedOutUser)protected abstract voidonUserRemoved(StitchUserT removedUser)<T> Stream<T>openAuthenticatedStream(StitchAuthRequest stitchReq, Decoder<T> decoder)voidrefreshAccessToken()protected voidremoveUserInternal()protected voidremoveUserWithIdInternal(String userId)StitchUserTswitchToUserWithId(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 providedStitchAuthRequestobject, and returns the response.- Specified by:
doAuthenticatedRequestin 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 providedStitchAuthRequestobject, and decodes the response using the provided result decoder.- Specified by:
doAuthenticatedRequestin 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 providedStitchAuthRequestobject, 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:
doAuthenticatedRequestin 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:
openAuthenticatedStreamin 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 IOExceptionCloses the component down by stopping the access token refresher.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getRequestClient
protected StitchRequestClient getRequestClient()
-
getAuthRoutes
protected StitchAuthRoutes getAuthRoutes()
-
-