Unverified Commit 02023100 authored by Aniket Singh's avatar Aniket Singh Committed by GitHub

Merge branch 'develop' into aniket/feat/create-new-channel

parents 6467d655 e5b6f8bf
...@@ -23,21 +23,22 @@ ...@@ -23,21 +23,22 @@
android:networkSecurityConfig="@xml/network_security_config" android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"> android:supportsRtl="true">
<activity <activity
android:name=".authentication.ui.AuthenticationActivity" android:name=".authentication.ui.AuthenticationActivity"
android:configChanges="orientation" android:configChanges="orientation"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/AuthenticationTheme" android:theme="@style/AuthenticationTheme"
android:windowSoftInputMode="adjustResize"> android:windowSoftInputMode="adjustResize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
...@@ -50,25 +51,31 @@ ...@@ -50,25 +51,31 @@
android:scheme="https" /> android:scheme="https" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".server.ui.ChangeServerActivity" android:name=".server.ui.ChangeServerActivity"
android:theme="@style/AuthenticationTheme" /> android:theme="@style/AuthenticationTheme" />
<activity <activity
android:name=".main.ui.MainActivity" android:name=".main.ui.MainActivity"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" /> android:windowSoftInputMode="adjustResize|stateAlwaysHidden" />
<activity <activity
android:name=".webview.ui.WebViewActivity" android:name=".webview.ui.WebViewActivity"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" /> android:windowSoftInputMode="adjustResize|stateAlwaysHidden" />
<activity <activity
android:name=".webview.cas.ui.CasWebViewActivity" android:name=".webview.sso.ui.SsoWebViewActivity"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" /> android:windowSoftInputMode="adjustResize|stateAlwaysHidden" />
<activity <activity
android:name=".webview.oauth.ui.OauthWebViewActivity" android:name=".webview.oauth.ui.OauthWebViewActivity"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" /> android:windowSoftInputMode="adjustResize|stateAlwaysHidden" />
<activity <activity
android:name=".chatroom.ui.ChatRoomActivity" android:name=".chatroom.ui.ChatRoomActivity"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
...@@ -103,6 +110,7 @@ ...@@ -103,6 +110,7 @@
<category android:name="${applicationId}" /> <category android:name="${applicationId}" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver <receiver
android:name=".push.DirectReplyReceiver" android:name=".push.DirectReplyReceiver"
android:enabled="true" android:enabled="true"
...@@ -119,6 +127,7 @@ ...@@ -119,6 +127,7 @@
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter> </intent-filter>
</service> </service>
<service <service
android:name=".push.GcmListenerService" android:name=".push.GcmListenerService"
android:exported="false"> android:exported="false">
...@@ -126,6 +135,7 @@ ...@@ -126,6 +135,7 @@
<action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter> </intent-filter>
</service> </service>
<service <service
android:name=".chatroom.service.MessageService" android:name=".chatroom.service.MessageService"
android:exported="true" android:exported="true"
......
...@@ -17,8 +17,8 @@ object DateTimeHelper { ...@@ -17,8 +17,8 @@ object DateTimeHelper {
* @param long The [Long] * @param long The [Long]
* @return The [LocalDateTime] from a [Long]. * @return The [LocalDateTime] from a [Long].
*/ */
fun getLocalDateTime(long: Long): LocalDateTime { fun getLocalDateTime(long: Long?): LocalDateTime {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(long), ZoneId.systemDefault()) return LocalDateTime.ofInstant(long?.let { Instant.ofEpochMilli(it) }, ZoneId.systemDefault())
} }
/** /**
......
...@@ -25,8 +25,9 @@ import javax.inject.Inject ...@@ -25,8 +25,9 @@ import javax.inject.Inject
private const val TYPE_LOGIN_USER_EMAIL = 0 private const val TYPE_LOGIN_USER_EMAIL = 0
private const val TYPE_LOGIN_CAS = 1 private const val TYPE_LOGIN_CAS = 1
private const val TYPE_LOGIN_OAUTH = 2 private const val TYPE_LOGIN_SAML = 2
private const val TYPE_LOGIN_DEEP_LINK = 3 private const val TYPE_LOGIN_OAUTH = 3
private const val TYPE_LOGIN_DEEP_LINK = 4
private const val SERVICE_NAME_FACEBOOK = "facebook" private const val SERVICE_NAME_FACEBOOK = "facebook"
private const val SERVICE_NAME_GITHUB = "github" private const val SERVICE_NAME_GITHUB = "github"
private const val SERVICE_NAME_GOOGLE = "google" private const val SERVICE_NAME_GOOGLE = "google"
...@@ -82,14 +83,19 @@ class LoginPresenter @Inject constructor( ...@@ -82,14 +83,19 @@ class LoginPresenter @Inject constructor(
} }
} }
fun authenticateWithCas(token: String) { fun authenticateWithCas(casToken: String) {
credentialToken = token credentialToken = casToken
doAuthentication(TYPE_LOGIN_CAS) doAuthentication(TYPE_LOGIN_CAS)
} }
fun authenticateWithOauth(token: String, secret: String) { fun authenticateWithSaml(samlToken: String) {
credentialToken = token credentialToken = samlToken
credentialSecret = secret doAuthentication(TYPE_LOGIN_SAML)
}
fun authenticateWithOauth(oauthToken: String, oauthSecret: String) {
credentialToken = oauthToken
credentialSecret = oauthSecret
doAuthentication(TYPE_LOGIN_OAUTH) doAuthentication(TYPE_LOGIN_OAUTH)
} }
...@@ -99,7 +105,6 @@ class LoginPresenter @Inject constructor( ...@@ -99,7 +105,6 @@ class LoginPresenter @Inject constructor(
deepLinkUserId = deepLinkInfo.userId deepLinkUserId = deepLinkInfo.userId
deepLinkToken = deepLinkInfo.token deepLinkToken = deepLinkInfo.token
tokenRepository.save(serverUrl, Token(deepLinkUserId, deepLinkToken)) tokenRepository.save(serverUrl, Token(deepLinkUserId, deepLinkToken))
doAuthentication(TYPE_LOGIN_DEEP_LINK) doAuthentication(TYPE_LOGIN_DEEP_LINK)
} }
...@@ -124,8 +129,11 @@ class LoginPresenter @Inject constructor( ...@@ -124,8 +129,11 @@ class LoginPresenter @Inject constructor(
private fun setupCasView() { private fun setupCasView() {
if (settings.isCasAuthenticationEnabled()) { if (settings.isCasAuthenticationEnabled()) {
val token = generateRandomString(17) val casToken = generateRandomString(17)
view.setupCasButtonListener(settings.casLoginUrl().casUrl(currentServer, token), token) view.setupCasButtonListener(
settings.casLoginUrl().casUrl(currentServer, casToken),
casToken
)
view.showCasButton() view.showCasButton()
} }
} }
...@@ -216,7 +224,7 @@ class LoginPresenter @Inject constructor( ...@@ -216,7 +224,7 @@ class LoginPresenter @Inject constructor(
// totalSocialAccountsEnabled++ // totalSocialAccountsEnabled++
} }
if (settings.isTwitterAuthenticationEnabled()) { if (settings.isTwitterAuthenticationEnabled()) {
//TODO: Remove until we have this implemented //TODO: Remove until Twitter provides support to OAuth2
// view.enableLoginByTwitter() // view.enableLoginByTwitter()
// totalSocialAccountsEnabled++ // totalSocialAccountsEnabled++
} }
...@@ -261,8 +269,23 @@ class LoginPresenter @Inject constructor( ...@@ -261,8 +269,23 @@ class LoginPresenter @Inject constructor(
customOauthUrl, customOauthUrl,
state, state,
serviceName, serviceName,
getCustomOauthServiceNameColor(service), getServiceNameColor(service),
getCustomOauthButtonColor(service) getServiceButtonColor(service)
)
totalSocialAccountsEnabled++
}
}
getSamlServices(services).let {
val samlToken = generateRandomString(17)
for (service in it) {
view.addSamlServiceButton(
currentServer.samlUrl(getSamlProvider(service), samlToken),
samlToken,
getSamlServiceName(service),
getServiceNameColor(service),
getServiceButtonColor(service)
) )
totalSocialAccountsEnabled++ totalSocialAccountsEnabled++
} }
...@@ -307,6 +330,10 @@ class LoginPresenter @Inject constructor( ...@@ -307,6 +330,10 @@ class LoginPresenter @Inject constructor(
delay(3, TimeUnit.SECONDS) delay(3, TimeUnit.SECONDS)
client.loginWithCas(credentialToken) client.loginWithCas(credentialToken)
} }
TYPE_LOGIN_SAML -> {
delay(3, TimeUnit.SECONDS)
client.loginWithSaml(credentialToken)
}
TYPE_LOGIN_OAUTH -> { TYPE_LOGIN_OAUTH -> {
client.loginWithOauth(credentialToken, credentialSecret) client.loginWithOauth(credentialToken, credentialSecret)
} }
...@@ -319,7 +346,7 @@ class LoginPresenter @Inject constructor( ...@@ -319,7 +346,7 @@ class LoginPresenter @Inject constructor(
} }
} }
else -> { else -> {
throw IllegalStateException("Expected TYPE_LOGIN_USER_EMAIL, TYPE_LOGIN_CAS, TYPE_LOGIN_OAUTH or TYPE_LOGIN_DEEP_LINK") throw IllegalStateException("Expected TYPE_LOGIN_USER_EMAIL, TYPE_LOGIN_CAS,TYPE_LOGIN_SAML, TYPE_LOGIN_OAUTH or TYPE_LOGIN_DEEP_LINK")
} }
} }
} }
...@@ -365,6 +392,18 @@ class LoginPresenter @Inject constructor( ...@@ -365,6 +392,18 @@ class LoginPresenter @Inject constructor(
}.toString() }.toString()
} }
private fun getSamlServices(listMap: List<Map<String, Any>>): List<Map<String, Any>> {
return listMap.filter { map -> map["service"] == "saml" }
}
private fun getSamlServiceName(service: Map<String, Any>): String {
return service["buttonLabelText"].toString()
}
private fun getSamlProvider(service: Map<String, Any>): String {
return (service["clientConfig"] as Map<*, *>)["provider"].toString()
}
private fun getCustomOauthServices(listMap: List<Map<String, Any>>): List<Map<String, Any>> { private fun getCustomOauthServices(listMap: List<Map<String, Any>>): List<Map<String, Any>> {
return listMap.filter { map -> map["custom"] == true } return listMap.filter { map -> map["custom"] == true }
} }
...@@ -389,11 +428,11 @@ class LoginPresenter @Inject constructor( ...@@ -389,11 +428,11 @@ class LoginPresenter @Inject constructor(
return service["scope"].toString() return service["scope"].toString()
} }
private fun getCustomOauthButtonColor(service: Map<String, Any>): Int { private fun getServiceButtonColor(service: Map<String, Any>): Int {
return service["buttonColor"].toString().parseColor() return service["buttonColor"].toString().parseColor()
} }
private fun getCustomOauthServiceNameColor(service: Map<String, Any>): Int { private fun getServiceNameColor(service: Map<String, Any>): Int {
return service["buttonLabelColor"].toString().parseColor() return service["buttonLabelColor"].toString().parseColor()
} }
......
...@@ -87,7 +87,7 @@ interface LoginView : LoadingView, MessageView { ...@@ -87,7 +87,7 @@ interface LoginView : LoadingView, MessageView {
* Enables and shows the oauth view if there is login via social accounts enabled by the server settings. * Enables and shows the oauth view if there is login via social accounts enabled by the server settings.
* *
* REMARK: We must show at maximum *three* social accounts views ([enableLoginByFacebook], [enableLoginByGithub], [enableLoginByGoogle], * REMARK: We must show at maximum *three* social accounts views ([enableLoginByFacebook], [enableLoginByGithub], [enableLoginByGoogle],
* [enableLoginByLinkedin], [enableLoginByMeteor], [enableLoginByTwitter], [enableLoginByGitlab] or [addCustomOauthServiceButton]) for the oauth view. * [enableLoginByLinkedin], [enableLoginByMeteor], [enableLoginByTwitter], [enableLoginByGitlab], [addCustomOauthServiceButton] or [addSamlServiceButton]) for the oauth view.
* If the possibility of login via social accounts exceeds 3 different ways we should set up the FAB ([setupFabListener]) to show the remaining view(s). * If the possibility of login via social accounts exceeds 3 different ways we should set up the FAB ([setupFabListener]) to show the remaining view(s).
*/ */
fun enableOauthView() fun enableOauthView()
...@@ -197,7 +197,7 @@ interface LoginView : LoadingView, MessageView { ...@@ -197,7 +197,7 @@ interface LoginView : LoadingView, MessageView {
* @state A random string generated by the app, which you'll verify later (to protect against forgery attacks). * @state A random string generated by the app, which you'll verify later (to protect against forgery attacks).
* @serviceName The custom OAuth service name. * @serviceName The custom OAuth service name.
* @serviceNameColor The custom OAuth service name color (just stylizing). * @serviceNameColor The custom OAuth service name color (just stylizing).
* @buttonColor The color of the custom OAuth button (just stylizing). * @buttonColor The custom OAuth button color (just stylizing).
* @see [enableOauthView] * @see [enableOauthView]
*/ */
fun addCustomOauthServiceButton( fun addCustomOauthServiceButton(
...@@ -208,6 +208,23 @@ interface LoginView : LoadingView, MessageView { ...@@ -208,6 +208,23 @@ interface LoginView : LoadingView, MessageView {
buttonColor: Int buttonColor: Int
) )
/**
* Adds a SAML button in the oauth view.
*
* @samlUrl The SAML url to sets up the button (the listener).
* @serviceName The SAML service name.
* @serviceNameColor The SAML service name color (just stylizing).
* @buttonColor The SAML button color (just stylizing).
* @see [enableOauthView]
*/
fun addSamlServiceButton(
samlUrl: String,
samlToken: String,
serviceName: String,
serviceNameColor: Int,
buttonColor: Int
)
/** /**
* Setups the FloatingActionButton to show more social accounts views (expanding the oauth view interface to show the remaining view(s)). * Setups the FloatingActionButton to show more social accounts views (expanding the oauth view interface to show the remaining view(s)).
*/ */
......
...@@ -25,8 +25,8 @@ import chat.rocket.android.authentication.login.presentation.LoginView ...@@ -25,8 +25,8 @@ import chat.rocket.android.authentication.login.presentation.LoginView
import chat.rocket.android.helper.KeyboardHelper import chat.rocket.android.helper.KeyboardHelper
import chat.rocket.android.helper.TextHelper import chat.rocket.android.helper.TextHelper
import chat.rocket.android.util.extensions.* import chat.rocket.android.util.extensions.*
import chat.rocket.android.webview.cas.ui.INTENT_CAS_TOKEN import chat.rocket.android.webview.sso.ui.INTENT_SSO_TOKEN
import chat.rocket.android.webview.cas.ui.casWebViewIntent import chat.rocket.android.webview.sso.ui.ssoWebViewIntent
import chat.rocket.android.webview.oauth.ui.INTENT_OAUTH_CREDENTIAL_SECRET import chat.rocket.android.webview.oauth.ui.INTENT_OAUTH_CREDENTIAL_SECRET
import chat.rocket.android.webview.oauth.ui.INTENT_OAUTH_CREDENTIAL_TOKEN import chat.rocket.android.webview.oauth.ui.INTENT_OAUTH_CREDENTIAL_TOKEN
import chat.rocket.android.webview.oauth.ui.oauthWebViewIntent import chat.rocket.android.webview.oauth.ui.oauthWebViewIntent
...@@ -42,12 +42,12 @@ import kotlinx.android.synthetic.main.fragment_authentication_log_in.* ...@@ -42,12 +42,12 @@ import kotlinx.android.synthetic.main.fragment_authentication_log_in.*
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
internal const val REQUEST_CODE_FOR_CAS = 1 internal const val REQUEST_CODE_FOR_CAS = 1
internal const val REQUEST_CODE_FOR_OAUTH = 2 internal const val REQUEST_CODE_FOR_SAML = 2
internal const val MULTIPLE_CREDENTIALS_READ = 3 internal const val REQUEST_CODE_FOR_OAUTH = 3
internal const val NO_CREDENTIALS_EXIST = 4 internal const val MULTIPLE_CREDENTIALS_READ = 4
internal const val SAVE_CREDENTIALS = 5 internal const val NO_CREDENTIALS_EXIST = 5
internal const val SAVE_CREDENTIALS = 6
lateinit var googleApiClient: GoogleApiClient lateinit var googleApiClient: GoogleApiClient
...@@ -121,7 +121,10 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks ...@@ -121,7 +121,10 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
if (data != null) { if (data != null) {
when (requestCode) { when (requestCode) {
REQUEST_CODE_FOR_CAS -> data.apply { REQUEST_CODE_FOR_CAS -> data.apply {
presenter.authenticateWithCas(getStringExtra(INTENT_CAS_TOKEN)) presenter.authenticateWithCas(getStringExtra(INTENT_SSO_TOKEN))
}
REQUEST_CODE_FOR_SAML -> data.apply {
presenter.authenticateWithSaml(getStringExtra(INTENT_SSO_TOKEN))
} }
REQUEST_CODE_FOR_OAUTH -> { REQUEST_CODE_FOR_OAUTH -> {
isOauthSuccessful = true isOauthSuccessful = true
...@@ -371,7 +374,7 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks ...@@ -371,7 +374,7 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
ui { activity -> ui { activity ->
button_cas.setOnClickListener { button_cas.setOnClickListener {
startActivityForResult( startActivityForResult(
activity.casWebViewIntent(casUrl, casToken), activity.ssoWebViewIntent(casUrl, casToken),
REQUEST_CODE_FOR_CAS REQUEST_CODE_FOR_CAS
) )
activity.overridePendingTransition(R.anim.slide_up, R.anim.hold) activity.overridePendingTransition(R.anim.slide_up, R.anim.hold)
...@@ -566,7 +569,7 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks ...@@ -566,7 +569,7 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
buttonColor: Int buttonColor: Int
) { ) {
ui { activity -> ui { activity ->
val button = getCustomOauthButton(serviceName, serviceNameColor, buttonColor) val button = getCustomServiceButton(serviceName, serviceNameColor, buttonColor)
social_accounts_container.addView(button) social_accounts_container.addView(button)
button.setOnClickListener { button.setOnClickListener {
...@@ -579,6 +582,27 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks ...@@ -579,6 +582,27 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
} }
} }
override fun addSamlServiceButton(
samlUrl: String,
samlToken: String,
serviceName: String,
serviceNameColor: Int,
buttonColor: Int
) {
ui { activity ->
val button = getCustomServiceButton(serviceName, serviceNameColor, buttonColor)
social_accounts_container.addView(button)
button.setOnClickListener {
startActivityForResult(
activity.ssoWebViewIntent(samlUrl, samlToken),
REQUEST_CODE_FOR_SAML
)
activity.overridePendingTransition(R.anim.slide_up, R.anim.hold)
}
}
}
override fun setupFabListener() { override fun setupFabListener() {
ui { ui {
button_fab.isVisible = true button_fab.isVisible = true
...@@ -696,9 +720,9 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks ...@@ -696,9 +720,9 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
} }
/** /**
* Gets a stylized custom OAuth button. * Gets a stylized custom service button.
*/ */
private fun getCustomOauthButton( private fun getCustomServiceButton(
buttonText: String, buttonText: String,
buttonTextColor: Int, buttonTextColor: Int,
buttonBgColor: Int buttonBgColor: Int
......
...@@ -507,6 +507,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -507,6 +507,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
ui { ui {
val clipboard = it.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val clipboard = it.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.primaryClip = ClipData.newPlainText("", message) clipboard.primaryClip = ClipData.newPlainText("", message)
showToast(R.string.msg_message_copied)
} }
} }
......
...@@ -40,8 +40,11 @@ fun String.safeUrl(): String { ...@@ -40,8 +40,11 @@ fun String.safeUrl(): String {
fun String.serverLogoUrl(favicon: String) = "${removeTrailingSlash()}/$favicon" fun String.serverLogoUrl(favicon: String) = "${removeTrailingSlash()}/$favicon"
fun String.casUrl(serverUrl: String, token: String) = fun String.casUrl(serverUrl: String, casToken: String) =
"${removeTrailingSlash()}?service=${serverUrl.removeTrailingSlash()}/_cas/$token" "${removeTrailingSlash()}?service=${serverUrl.removeTrailingSlash()}/_cas/$casToken"
fun String.samlUrl(provider: String, samlToken: String) =
"${removeTrailingSlash()}/_saml/authorize/$provider/$samlToken"
fun String.termsOfServiceUrl() = "${removeTrailingSlash()}/terms-of-service" fun String.termsOfServiceUrl() = "${removeTrailingSlash()}/terms-of-service"
......
...@@ -36,7 +36,6 @@ class OauthWebViewActivity : AppCompatActivity() { ...@@ -36,7 +36,6 @@ class OauthWebViewActivity : AppCompatActivity() {
private lateinit var state: String private lateinit var state: String
private var isWebViewSetUp: Boolean = false private var isWebViewSetUp: Boolean = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_web_view) setContentView(R.layout.activity_web_view)
......
package chat.rocket.android.webview.cas.ui package chat.rocket.android.webview.sso.ui
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
...@@ -13,19 +13,23 @@ import chat.rocket.android.R ...@@ -13,19 +13,23 @@ import chat.rocket.android.R
import kotlinx.android.synthetic.main.activity_web_view.* import kotlinx.android.synthetic.main.activity_web_view.*
import kotlinx.android.synthetic.main.app_bar.* import kotlinx.android.synthetic.main.app_bar.*
fun Context.casWebViewIntent(webPageUrl: String, casToken: String): Intent { fun Context.ssoWebViewIntent(webPageUrl: String, casToken: String): Intent {
return Intent(this, CasWebViewActivity::class.java).apply { return Intent(this, SsoWebViewActivity::class.java).apply {
putExtra(INTENT_WEB_PAGE_URL, webPageUrl) putExtra(INTENT_WEB_PAGE_URL, webPageUrl)
putExtra(INTENT_CAS_TOKEN, casToken) putExtra(INTENT_SSO_TOKEN, casToken)
} }
} }
private const val INTENT_WEB_PAGE_URL = "web_page_url" private const val INTENT_WEB_PAGE_URL = "web_page_url"
const val INTENT_CAS_TOKEN = "cas_token" const val INTENT_SSO_TOKEN = "cas_token"
class CasWebViewActivity : AppCompatActivity() { /**
* This class is responsible to handle the authentication thought single sign-on protocol (CAS and SAML).
*/
class SsoWebViewActivity : AppCompatActivity() {
private lateinit var webPageUrl: String private lateinit var webPageUrl: String
private lateinit var casToken: String private lateinit var casToken: String
private var isWebViewSetUp: Boolean = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
...@@ -34,7 +38,7 @@ class CasWebViewActivity : AppCompatActivity() { ...@@ -34,7 +38,7 @@ class CasWebViewActivity : AppCompatActivity() {
webPageUrl = intent.getStringExtra(INTENT_WEB_PAGE_URL) webPageUrl = intent.getStringExtra(INTENT_WEB_PAGE_URL)
requireNotNull(webPageUrl) { "no web_page_url provided in Intent extras" } requireNotNull(webPageUrl) { "no web_page_url provided in Intent extras" }
casToken = intent.getStringExtra(INTENT_CAS_TOKEN) casToken = intent.getStringExtra(INTENT_SSO_TOKEN)
requireNotNull(casToken) { "no cas_token provided in Intent extras" } requireNotNull(casToken) { "no cas_token provided in Intent extras" }
setupToolbar() setupToolbar()
...@@ -42,7 +46,10 @@ class CasWebViewActivity : AppCompatActivity() { ...@@ -42,7 +46,10 @@ class CasWebViewActivity : AppCompatActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
setupWebView() if (!isWebViewSetUp) {
setupWebView()
isWebViewSetUp = true
}
} }
override fun onBackPressed() { override fun onBackPressed() {
...@@ -64,15 +71,16 @@ class CasWebViewActivity : AppCompatActivity() { ...@@ -64,15 +71,16 @@ class CasWebViewActivity : AppCompatActivity() {
web_view.settings.javaScriptEnabled = true web_view.settings.javaScriptEnabled = true
web_view.webViewClient = object : WebViewClient() { web_view.webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) { override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
// The user may have already been logged in the CAS, so check if the URL contains the "ticket" word // The user may have already been logged in the SSO, so check if the URL contains
// (that means the user is successful authenticated and we don't need to wait until the page is fully loaded). // the "ticket" or "validate" word (that means the user is successful authenticated
if (url.contains("ticket")) { // and we don't need to wait until the page is fully loaded).
if (url.contains("ticket") || url.contains("validate")) {
closeView(Activity.RESULT_OK) closeView(Activity.RESULT_OK)
} }
} }
override fun onPageFinished(view: WebView, url: String) { override fun onPageFinished(view: WebView, url: String) {
if (url.contains("ticket")) { if (url.contains("ticket") || url.contains("validate")) {
closeView(Activity.RESULT_OK) closeView(Activity.RESULT_OK)
} else { } else {
view_loading.hide() view_loading.hide()
...@@ -83,7 +91,7 @@ class CasWebViewActivity : AppCompatActivity() { ...@@ -83,7 +91,7 @@ class CasWebViewActivity : AppCompatActivity() {
} }
private fun closeView(activityResult: Int = Activity.RESULT_CANCELED) { private fun closeView(activityResult: Int = Activity.RESULT_CANCELED) {
setResult(activityResult, Intent().putExtra(INTENT_CAS_TOKEN, casToken)) setResult(activityResult, Intent().putExtra(INTENT_SSO_TOKEN, casToken))
finish() finish()
overridePendingTransition(R.anim.hold, R.anim.slide_down) overridePendingTransition(R.anim.hold, R.anim.slide_down)
} }
......
...@@ -139,6 +139,7 @@ ...@@ -139,6 +139,7 @@
<string name="msg_add_members">Add Members</string> <string name="msg_add_members">Add Members</string>
// TODO: Add proper translation. // TODO: Add proper translation.
<string name="msg_search">Search</string> <string name="msg_search">Search</string>
<string name="msg_message_copied">Mensaje copiado</string>
<!-- System messages --> <!-- System messages -->
<string name="message_room_name_changed">Nombre de la sala cambiado para: %1$s por %2$s</string> <string name="message_room_name_changed">Nombre de la sala cambiado para: %1$s por %2$s</string>
......
...@@ -139,6 +139,7 @@ ...@@ -139,6 +139,7 @@
<string name="msg_add_members">Add Members</string> <string name="msg_add_members">Add Members</string>
// TODO: Add proper translation. // TODO: Add proper translation.
<string name="msg_search">Search</string> <string name="msg_search">Search</string>
<string name="msg_message_copied">Message copié</string>
<!-- System messages --> <!-- System messages -->
<string name="message_room_name_changed">Le nom de le salle a changé à: %1$s par %2$s</string> <string name="message_room_name_changed">Le nom de le salle a changé à: %1$s par %2$s</string>
......
...@@ -141,6 +141,7 @@ ...@@ -141,6 +141,7 @@
<string name="msg_add_members">Add Members</string> <string name="msg_add_members">Add Members</string>
// TODO: Add proper translation. // TODO: Add proper translation.
<string name="msg_search">Search</string> <string name="msg_search">Search</string>
<string name="msg_message_copied">संदेश कॉपी किया गया</string>
<!-- System messages --> <!-- System messages -->
<string name="message_room_name_changed">%2$s ने रूम का नाम बदलकर %1$s किया</string> <string name="message_room_name_changed">%2$s ने रूम का नाम बदलकर %1$s किया</string>
......
...@@ -131,6 +131,7 @@ ...@@ -131,6 +131,7 @@
<string name="msg_add_members">Add Members</string> <string name="msg_add_members">Add Members</string>
// TODO: Add proper translation. // TODO: Add proper translation.
<string name="msg_search">Search</string> <string name="msg_search">Search</string>
<string name="msg_message_copied">Mensagem copiada</string>
<!-- System messages --> <!-- System messages -->
<string name="message_room_name_changed">Nome da sala alterado para: %1$s por %2$s</string> <string name="message_room_name_changed">Nome da sala alterado para: %1$s por %2$s</string>
......
This diff is collapsed.
...@@ -129,6 +129,7 @@ ...@@ -129,6 +129,7 @@
<string name="public_channel_type">Public</string> <string name="public_channel_type">Public</string>
<string name="private_channel_type_description">Visible only to you and those whom you invite</string> <string name="private_channel_type_description">Visible only to you and those whom you invite</string>
<string name="public_channel_description">Visible to everyone</string> <string name="public_channel_description">Visible to everyone</string>
<string name="msg_message_copied">Message copied</string>
<!-- System messages --> <!-- System messages -->
<string name="message_room_name_changed">Room name changed to: %1$s by %2$s</string> <string name="message_room_name_changed">Room name changed to: %1$s by %2$s</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment