Implement AuthStrategy for S3
This commit is contained in:
parent
862596114b
commit
4e6983862f
@ -5,6 +5,7 @@ import org.cryptomator.data.cloud.dropbox.DropboxCloudContentRepositoryFactory;
|
|||||||
import org.cryptomator.data.cloud.local.LocalStorageContentRepositoryFactory;
|
import org.cryptomator.data.cloud.local.LocalStorageContentRepositoryFactory;
|
||||||
import org.cryptomator.data.cloud.onedrive.OnedriveCloudContentRepositoryFactory;
|
import org.cryptomator.data.cloud.onedrive.OnedriveCloudContentRepositoryFactory;
|
||||||
import org.cryptomator.data.cloud.pcloud.PCloudContentRepositoryFactory;
|
import org.cryptomator.data.cloud.pcloud.PCloudContentRepositoryFactory;
|
||||||
|
import org.cryptomator.data.cloud.s3.S3CloudContentRepositoryFactory;
|
||||||
import org.cryptomator.data.cloud.webdav.WebDavCloudContentRepositoryFactory;
|
import org.cryptomator.data.cloud.webdav.WebDavCloudContentRepositoryFactory;
|
||||||
import org.cryptomator.data.repository.CloudContentRepositoryFactory;
|
import org.cryptomator.data.repository.CloudContentRepositoryFactory;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -25,6 +26,7 @@ public class CloudContentRepositoryFactories implements Iterable<CloudContentRep
|
|||||||
public CloudContentRepositoryFactories(DropboxCloudContentRepositoryFactory dropboxFactory, //
|
public CloudContentRepositoryFactories(DropboxCloudContentRepositoryFactory dropboxFactory, //
|
||||||
OnedriveCloudContentRepositoryFactory oneDriveFactory, //
|
OnedriveCloudContentRepositoryFactory oneDriveFactory, //
|
||||||
PCloudContentRepositoryFactory pCloudFactory, //
|
PCloudContentRepositoryFactory pCloudFactory, //
|
||||||
|
S3CloudContentRepositoryFactory s3Factory, //
|
||||||
CryptoCloudContentRepositoryFactory cryptoFactory, //
|
CryptoCloudContentRepositoryFactory cryptoFactory, //
|
||||||
LocalStorageContentRepositoryFactory localStorageFactory, //
|
LocalStorageContentRepositoryFactory localStorageFactory, //
|
||||||
WebDavCloudContentRepositoryFactory webDavFactory) {
|
WebDavCloudContentRepositoryFactory webDavFactory) {
|
||||||
@ -32,6 +34,7 @@ public class CloudContentRepositoryFactories implements Iterable<CloudContentRep
|
|||||||
factories = asList(dropboxFactory, //
|
factories = asList(dropboxFactory, //
|
||||||
oneDriveFactory, //
|
oneDriveFactory, //
|
||||||
pCloudFactory, //
|
pCloudFactory, //
|
||||||
|
s3Factory, //
|
||||||
cryptoFactory, //
|
cryptoFactory, //
|
||||||
localStorageFactory, //
|
localStorageFactory, //
|
||||||
webDavFactory);
|
webDavFactory);
|
||||||
|
@ -37,10 +37,12 @@ import org.cryptomator.presentation.R
|
|||||||
import org.cryptomator.presentation.exception.ExceptionHandlers
|
import org.cryptomator.presentation.exception.ExceptionHandlers
|
||||||
import org.cryptomator.presentation.exception.PermissionNotGrantedException
|
import org.cryptomator.presentation.exception.PermissionNotGrantedException
|
||||||
import org.cryptomator.presentation.intent.AuthenticateCloudIntent
|
import org.cryptomator.presentation.intent.AuthenticateCloudIntent
|
||||||
|
import org.cryptomator.presentation.intent.Intents
|
||||||
import org.cryptomator.presentation.model.CloudModel
|
import org.cryptomator.presentation.model.CloudModel
|
||||||
import org.cryptomator.presentation.model.CloudTypeModel
|
import org.cryptomator.presentation.model.CloudTypeModel
|
||||||
import org.cryptomator.presentation.model.ProgressModel
|
import org.cryptomator.presentation.model.ProgressModel
|
||||||
import org.cryptomator.presentation.model.ProgressStateModel
|
import org.cryptomator.presentation.model.ProgressStateModel
|
||||||
|
import org.cryptomator.presentation.model.S3CloudModel
|
||||||
import org.cryptomator.presentation.model.WebDavCloudModel
|
import org.cryptomator.presentation.model.WebDavCloudModel
|
||||||
import org.cryptomator.presentation.model.mappers.CloudModelMapper
|
import org.cryptomator.presentation.model.mappers.CloudModelMapper
|
||||||
import org.cryptomator.presentation.ui.activity.view.AuthenticateCloudView
|
import org.cryptomator.presentation.ui.activity.view.AuthenticateCloudView
|
||||||
@ -72,6 +74,7 @@ class AuthenticateCloudPresenter @Inject constructor( //
|
|||||||
OnedriveAuthStrategy(), //
|
OnedriveAuthStrategy(), //
|
||||||
PCloudAuthStrategy(), //
|
PCloudAuthStrategy(), //
|
||||||
WebDAVAuthStrategy(), //
|
WebDAVAuthStrategy(), //
|
||||||
|
S3AuthStrategy(), //
|
||||||
LocalStorageAuthStrategy() //
|
LocalStorageAuthStrategy() //
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -404,6 +407,38 @@ class AuthenticateCloudPresenter @Inject constructor( //
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private inner class S3AuthStrategy : AuthStrategy {
|
||||||
|
|
||||||
|
private var authenticationStarted = false
|
||||||
|
|
||||||
|
override fun supports(cloud: CloudModel): Boolean {
|
||||||
|
return cloud.cloudType() == CloudTypeModel.S3
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun resumed(intent: AuthenticateCloudIntent) {
|
||||||
|
when {
|
||||||
|
ExceptionUtil.contains(intent.error(), WrongCredentialsException::class.java) -> {
|
||||||
|
if (!authenticationStarted) {
|
||||||
|
startAuthentication(intent.cloud())
|
||||||
|
Toast.makeText(
|
||||||
|
context(),
|
||||||
|
String.format(getString(R.string.error_authentication_failed), intent.cloud().username()),
|
||||||
|
Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Timber.tag("AuthicateCloudPrester").e(intent.error())
|
||||||
|
failAuthentication(intent.cloud().name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startAuthentication(cloud: CloudModel) {
|
||||||
|
authenticationStarted = true
|
||||||
|
startIntent(Intents.s3AddOrChangeIntent().withS3Cloud(cloud as S3CloudModel))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private inner class LocalStorageAuthStrategy : AuthStrategy {
|
private inner class LocalStorageAuthStrategy : AuthStrategy {
|
||||||
|
|
||||||
private var authenticationStarted = false
|
private var authenticationStarted = false
|
||||||
|
@ -40,10 +40,12 @@ import org.cryptomator.presentation.R
|
|||||||
import org.cryptomator.presentation.exception.ExceptionHandlers
|
import org.cryptomator.presentation.exception.ExceptionHandlers
|
||||||
import org.cryptomator.presentation.exception.PermissionNotGrantedException
|
import org.cryptomator.presentation.exception.PermissionNotGrantedException
|
||||||
import org.cryptomator.presentation.intent.AuthenticateCloudIntent
|
import org.cryptomator.presentation.intent.AuthenticateCloudIntent
|
||||||
|
import org.cryptomator.presentation.intent.Intents
|
||||||
import org.cryptomator.presentation.model.CloudModel
|
import org.cryptomator.presentation.model.CloudModel
|
||||||
import org.cryptomator.presentation.model.CloudTypeModel
|
import org.cryptomator.presentation.model.CloudTypeModel
|
||||||
import org.cryptomator.presentation.model.ProgressModel
|
import org.cryptomator.presentation.model.ProgressModel
|
||||||
import org.cryptomator.presentation.model.ProgressStateModel
|
import org.cryptomator.presentation.model.ProgressStateModel
|
||||||
|
import org.cryptomator.presentation.model.S3CloudModel
|
||||||
import org.cryptomator.presentation.model.WebDavCloudModel
|
import org.cryptomator.presentation.model.WebDavCloudModel
|
||||||
import org.cryptomator.presentation.model.mappers.CloudModelMapper
|
import org.cryptomator.presentation.model.mappers.CloudModelMapper
|
||||||
import org.cryptomator.presentation.ui.activity.view.AuthenticateCloudView
|
import org.cryptomator.presentation.ui.activity.view.AuthenticateCloudView
|
||||||
@ -76,6 +78,7 @@ class AuthenticateCloudPresenter @Inject constructor( //
|
|||||||
OnedriveAuthStrategy(), //
|
OnedriveAuthStrategy(), //
|
||||||
PCloudAuthStrategy(), //
|
PCloudAuthStrategy(), //
|
||||||
WebDAVAuthStrategy(), //
|
WebDAVAuthStrategy(), //
|
||||||
|
S3AuthStrategy(), //
|
||||||
LocalStorageAuthStrategy() //
|
LocalStorageAuthStrategy() //
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -448,6 +451,38 @@ class AuthenticateCloudPresenter @Inject constructor( //
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private inner class S3AuthStrategy : AuthStrategy {
|
||||||
|
|
||||||
|
private var authenticationStarted = false
|
||||||
|
|
||||||
|
override fun supports(cloud: CloudModel): Boolean {
|
||||||
|
return cloud.cloudType() == CloudTypeModel.S3
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun resumed(intent: AuthenticateCloudIntent) {
|
||||||
|
when {
|
||||||
|
ExceptionUtil.contains(intent.error(), WrongCredentialsException::class.java) -> {
|
||||||
|
if (!authenticationStarted) {
|
||||||
|
startAuthentication(intent.cloud())
|
||||||
|
Toast.makeText(
|
||||||
|
context(),
|
||||||
|
String.format(getString(R.string.error_authentication_failed), intent.cloud().username()),
|
||||||
|
Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Timber.tag("AuthicateCloudPrester").e(intent.error())
|
||||||
|
failAuthentication(intent.cloud().name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startAuthentication(cloud: CloudModel) {
|
||||||
|
authenticationStarted = true
|
||||||
|
startIntent(Intents.s3AddOrChangeIntent().withS3Cloud(cloud as S3CloudModel))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private inner class LocalStorageAuthStrategy : AuthStrategy {
|
private inner class LocalStorageAuthStrategy : AuthStrategy {
|
||||||
|
|
||||||
private var authenticationStarted = false
|
private var authenticationStarted = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user