From c232a1f734dc1730d9c1ab4e5329a0024eb53db4 Mon Sep 17 00:00:00 2001 From: TanelOrumaa Date: Tue, 18 Jan 2022 00:34:45 +0200 Subject: [PATCH] Fixed the error handling a bit, added some text to login page --- .../mobileauthapp/AuthFragment.kt | 17 +- .../mobileauthapp/CanFragment.kt | 1 + .../mobileauthapp/MainActivity.kt | 30 + .../mobileauthapp/PinFragment.kt | 1 + .../mobileauthapp/ResultFragment.kt | 3 +- demoBackend/.gitignore | 2 +- demoBackend/pom.xml | 1 + .../src/demo-website/package-lock.json | 30 +- demoBackend/src/demo-website/package.json | 3 +- .../src/demo-website/src/components/Login.vue | 12 +- demoBackend/src/demo-website/src/web-eid.js | 9050 ----------------- .../config/ApplicationConfiguration.kt | 2 +- .../demobackend/config/SessionManager.kt | 19 +- .../demobackend/dto/AuthDto.kt | 2 +- .../demobackend/dto/AuthTokenDTO.kt | 2 +- .../security/WebEidAuthentication.kt | 47 +- .../web/rest/AuthenticationController.kt | 16 +- 17 files changed, 124 insertions(+), 9114 deletions(-) delete mode 100644 demoBackend/src/demo-website/src/web-eid.js diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt index 4d3d678..76e1e56 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt @@ -68,18 +68,18 @@ class AuthFragment : Fragment() { override fun onFinish() { Thread.sleep(750) - cancelAuth() + cancelAuth(408) } }.start() // The button exists in code for testing reasons, but not visible to the user anymore unless visibility is changed in the code. binding.nextButton.visibility = View.GONE binding.nextButton.setOnClickListener { goToNextFragment() } - binding.cancelButton.setOnClickListener { cancelAuth() } + binding.cancelButton.setOnClickListener { cancelAuth(444) } val adapter = NfcAdapter.getDefaultAdapter(activity) if (adapter != null) getInfoFromIdCard(adapter) else { // If NFC adapter can not be detected then end the auth process as it is not possible to read an ID card - cancelAuth() // It would be a good idea to show user some notification as it might be confusing if the app suddenly closes + cancelAuth(447) // It would be a good idea to show user some notification as it might be confusing if the app suddenly closes } } @@ -89,7 +89,7 @@ class AuthFragment : Fragment() { findNavController().navigate(action) } - private fun cancelAuth() { + private fun cancelAuth(code: Int) { viewModel.clearUserInfo() timer.cancel() if (args.mobile) { @@ -97,6 +97,7 @@ class AuthFragment : Fragment() { requireActivity().setResult(AppCompatActivity.RESULT_CANCELED, resultIntent) requireActivity().finish() } else { + (activity as MainActivity).returnError(code) requireActivity().finishAndRemoveTask() } } @@ -123,24 +124,28 @@ class AuthFragment : Fragment() { } } catch (e: Exception) { when(e) { - is TagLostException -> requireActivity().runOnUiThread { binding!!.timeCounter.text = getString(R.string.id_card_removed_early) } + is TagLostException -> requireActivity().runOnUiThread { + binding!!.timeCounter.text = getString(R.string.id_card_removed_early) + cancelAuth(444) + } else -> { when ("invalid pin") { in e.message.toString().lowercase() -> requireActivity().runOnUiThread { val messagePieces = e.message.toString().split(" ") binding.timeCounter.text = getString(R.string.wrong_pin, messagePieces[messagePieces.size - 1]) viewModel.deletePin(requireContext()) + cancelAuth(449) } else -> requireActivity().runOnUiThread { binding.timeCounter.text = getString(R.string.wrong_can_text) viewModel.deleteCan(requireContext()) + cancelAuth(449) } } } } // Give user some time to read the error message Thread.sleep(2000) - cancelAuth() } finally { adapter.disableReaderMode(activity) } diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/CanFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/CanFragment.kt index 01061fc..de2b7aa 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/CanFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/CanFragment.kt @@ -90,6 +90,7 @@ class CanFragment : Fragment() { requireActivity().setResult(AppCompatActivity.RESULT_CANCELED, resultIntent) requireActivity().finish() } else { + (activity as MainActivity).returnError(444) requireActivity().finishAndRemoveTask() } } else { diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/MainActivity.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/MainActivity.kt index 8ec228c..1468611 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/MainActivity.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/MainActivity.kt @@ -5,9 +5,17 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.widget.Toast +import androidx.activity.viewModels +import androidx.fragment.app.activityViewModels import androidx.navigation.NavController import androidx.navigation.fragment.NavHostFragment +import androidx.navigation.fragment.navArgs +import androidx.navigation.navArgs +import com.google.gson.JsonObject +import com.koushikdutta.ion.Ion import com.tarkvaraprojekt.mobileauthapp.databinding.ActivityMainBinding +import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentResultBinding +import com.tarkvaraprojekt.mobileauthapp.model.ParametersViewModel /** @@ -16,6 +24,8 @@ import com.tarkvaraprojekt.mobileauthapp.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { private lateinit var navigationController: NavController + private val paramsModel: ParametersViewModel by viewModels() + // If true the settings menu can be accessed from the toolbar in the upper part of the screen. var menuAvailable: Boolean = true @@ -54,4 +64,24 @@ class MainActivity : AppCompatActivity() { } else -> super.onOptionsItemSelected(item) } + + fun returnError(errorCode: Int) { + val json = JsonObject() + json.addProperty("auth-token", "") + json.addProperty("error", errorCode) + + Ion.getDefault(this).conscryptMiddleware.enable(false) + val ion = Ion.with(this) + .load(paramsModel.authUrl) + for ((header, value) in paramsModel.headers) { + ion.setHeader(header, value) + } + + ion + .setJsonObjectBody(json) + .asJsonObject() + .setCallback { _, _ -> + + } + } } \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/PinFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/PinFragment.kt index bd69f47..476d849 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/PinFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/PinFragment.kt @@ -96,6 +96,7 @@ class PinFragment : Fragment() { requireActivity().setResult(AppCompatActivity.RESULT_CANCELED, resultIntent) requireActivity().finish() } else { + (activity as MainActivity).returnError(444) requireActivity().finishAndRemoveTask() } } else { diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/ResultFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/ResultFragment.kt index 1df15db..59a8837 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/ResultFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/ResultFragment.kt @@ -68,8 +68,7 @@ class ResultFragment : Fragment() { fun postToken() { val json = JsonObject() json.addProperty("auth-token", paramsModel.token) - - + json.addProperty("error", 200) Ion.getDefault(activity).conscryptMiddleware.enable(false) val ion = Ion.with(activity) diff --git a/demoBackend/.gitignore b/demoBackend/.gitignore index 3ec119f..f8a8efa 100644 --- a/demoBackend/.gitignore +++ b/demoBackend/.gitignore @@ -33,4 +33,4 @@ build/ .vscode/ ### web-eid.js ### -!**src/demo-website/src/web-eid.js \ No newline at end of file +src/demo-website/src/web-eid.js \ No newline at end of file diff --git a/demoBackend/pom.xml b/demoBackend/pom.xml index 94c2cc8..77f75a4 100644 --- a/demoBackend/pom.xml +++ b/demoBackend/pom.xml @@ -94,6 +94,7 @@ ${project.basedir}/src/main/kotlin ${project.basedir}/src/test/kotlin + demo org.springframework.boot diff --git a/demoBackend/src/demo-website/package-lock.json b/demoBackend/src/demo-website/package-lock.json index d157ab9..01c0825 100644 --- a/demoBackend/src/demo-website/package-lock.json +++ b/demoBackend/src/demo-website/package-lock.json @@ -8,7 +8,7 @@ "name": "demo-website", "version": "0.1.0", "dependencies": { - "@web-eid/web-eid-library": "github:TanelOrumaa/web-eid.js#main", + "@web-eid/web-eid-library": "../../../../web-eid.js/", "core-js": "^3.6.5", "vue": "^3.0.0", "vue-cookie-next": "^1.3.0", @@ -32,7 +32,6 @@ "../../../../web-eid.js": { "name": "@web-eid/web-eid-library", "version": "1.0.1", - "extraneous": true, "license": "MIT", "dependencies": { "@types/node": "^16.11.11" @@ -1925,7 +1924,8 @@ "node_modules/@types/node": { "version": "16.11.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.12.tgz", - "integrity": "sha512-+2Iggwg7PxoO5Kyhvsq9VarmPbIelXP070HMImEpbtGCoyWNINQj4wzjbQCXzdHTRXnqufutJb5KAURZANNBAw==" + "integrity": "sha512-+2Iggwg7PxoO5Kyhvsq9VarmPbIelXP070HMImEpbtGCoyWNINQj4wzjbQCXzdHTRXnqufutJb5KAURZANNBAw==", + "dev": true }, "node_modules/@types/normalize-package-data": { "version": "2.4.1", @@ -2643,12 +2643,8 @@ "dev": true }, "node_modules/@web-eid/web-eid-library": { - "version": "1.0.1", - "resolved": "git+ssh://git@github.com/TanelOrumaa/web-eid.js.git#b9c6f50c78a39b444d5df308826cd3f3476233d1", - "license": "MIT", - "dependencies": { - "@types/node": "^16.11.11" - } + "resolved": "../../../../web-eid.js", + "link": true }, "node_modules/@webassemblyjs/ast": { "version": "1.9.0", @@ -16604,7 +16600,8 @@ "@types/node": { "version": "16.11.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.12.tgz", - "integrity": "sha512-+2Iggwg7PxoO5Kyhvsq9VarmPbIelXP070HMImEpbtGCoyWNINQj4wzjbQCXzdHTRXnqufutJb5KAURZANNBAw==" + "integrity": "sha512-+2Iggwg7PxoO5Kyhvsq9VarmPbIelXP070HMImEpbtGCoyWNINQj4wzjbQCXzdHTRXnqufutJb5KAURZANNBAw==", + "dev": true }, "@types/normalize-package-data": { "version": "2.4.1", @@ -17212,10 +17209,17 @@ "dev": true }, "@web-eid/web-eid-library": { - "version": "git+ssh://git@github.com/TanelOrumaa/web-eid.js.git#b9c6f50c78a39b444d5df308826cd3f3476233d1", - "from": "@web-eid/web-eid-library@github:TanelOrumaa/web-eid.js#main", + "version": "file:../../../../web-eid.js", "requires": { - "@types/node": "^16.11.11" + "@types/node": "^16.11.11", + "@typescript-eslint/eslint-plugin": "^4.31.2", + "@typescript-eslint/parser": "^4.31.2", + "eslint": "^7.25.0", + "rimraf": "^3.0.2", + "rollup": "^2.26.11", + "rollup-plugin-polyfill-node": "^0.8.0", + "rollup-plugin-terser": "^5.3.1", + "typescript": "^3.8.3" } }, "@webassemblyjs/ast": { diff --git a/demoBackend/src/demo-website/package.json b/demoBackend/src/demo-website/package.json index 4982059..a0825e8 100644 --- a/demoBackend/src/demo-website/package.json +++ b/demoBackend/src/demo-website/package.json @@ -8,7 +8,8 @@ "lint": "vue-cli-service lint" }, "dependencies": { - "@web-eid/web-eid-library": "github:TanelOrumaa/web-eid.js#main", + + "@web-eid/web-eid-library": "../../../../web-eid.js/", "core-js": "^3.6.5", "vue": "^3.0.0", "vue-cookie-next": "^1.3.0", diff --git a/demoBackend/src/demo-website/src/components/Login.vue b/demoBackend/src/demo-website/src/components/Login.vue index ed3db41..9215bd4 100644 --- a/demoBackend/src/demo-website/src/components/Login.vue +++ b/demoBackend/src/demo-website/src/components/Login.vue @@ -1,9 +1,15 @@