From bbb89bf98a52ad9a18a464b6d4a8e4ff6a6c51b6 Mon Sep 17 00:00:00 2001 From: Mateusz <76775507+szczygiel-m@users.noreply.github.com> Date: Fri, 18 Aug 2023 12:30:22 +0200 Subject: [PATCH] Feature/auth (#1707) Added auth to hermes console --- hermes-console-vue/json-server/db.json | 4 +- hermes-console-vue/package.json | 4 + hermes-console-vue/src/App.vue | 28 ++-- .../src/api/access-token-response.ts | 3 + .../src/api/app-configuration.ts | 2 + .../src/api/hermes-client/index.ts | 25 ++++ .../console-header/ConsoleHeader.spec.ts | 130 +++++++++++++++++- .../console-header/ConsoleHeader.vue | 38 ++++- hermes-console-vue/src/dummy/app-config.ts | 6 +- hermes-console-vue/src/dummy/store.ts | 13 +- hermes-console-vue/src/i18n/en-US.ts | 4 + hermes-console-vue/src/main.ts | 3 + hermes-console-vue/src/mocks/handlers.ts | 10 ++ hermes-console-vue/src/router/index.ts | 31 +++-- .../src/store/{ => app-config}/types.ts | 0 .../src/store/app-config/useAppConfigStore.ts | 8 +- hermes-console-vue/src/store/auth/types.ts | 10 ++ .../src/store/auth/useAuthStore.spec.ts | 65 +++++++++ .../src/store/auth/useAuthStore.ts | 90 ++++++++++++ hermes-console-vue/src/utils/jwt-utils.ts | 4 + .../consumer-groups/ConsumerGroupsView.vue | 8 +- .../views/group-topics/GroupTopicsView.vue | 4 +- .../GroupTopicsListing.vue | 4 +- .../src/views/groups/GroupsView.vue | 2 +- .../groups/group-listing/GroupListing.vue | 2 +- .../src/views/home/HomeView.spec.ts | 4 +- .../src/views/home/HomeView.vue | 16 +-- .../src/views/redirect/RedirectView.spec.ts | 42 ++++++ .../src/views/redirect/RedirectView.vue | 23 ++++ .../views/subscription/SubscriptionView.vue | 6 +- .../src/views/topic/TopicView.spec.ts | 2 +- .../src/views/topic/TopicView.vue | 6 +- hermes-console-vue/yarn.lock | 39 ++++++ .../config/console/ConsoleProperties.java | 20 ++- 34 files changed, 598 insertions(+), 58 deletions(-) create mode 100644 hermes-console-vue/src/api/access-token-response.ts rename hermes-console-vue/src/store/{ => app-config}/types.ts (100%) create mode 100644 hermes-console-vue/src/store/auth/types.ts create mode 100644 hermes-console-vue/src/store/auth/useAuthStore.spec.ts create mode 100644 hermes-console-vue/src/store/auth/useAuthStore.ts create mode 100644 hermes-console-vue/src/utils/jwt-utils.ts create mode 100644 hermes-console-vue/src/views/redirect/RedirectView.spec.ts create mode 100644 hermes-console-vue/src/views/redirect/RedirectView.vue diff --git a/hermes-console-vue/json-server/db.json b/hermes-console-vue/json-server/db.json index f5ddfc6a36..9d2f84c417 100644 --- a/hermes-console-vue/json-server/db.json +++ b/hermes-console-vue/json-server/db.json @@ -466,7 +466,9 @@ "auth": { "oauth": { "enabled": false, - "url": "localhost:8092/auth", + "url": "localhost:8092", + "authorizationEndpoint": "/auth/oauth/authorize", + "tokenEndpoint": "/auth/oauth/token", "clientId": "hermes", "scope": "hermes" }, diff --git a/hermes-console-vue/package.json b/hermes-console-vue/package.json index c92657b99c..72e4abb85d 100644 --- a/hermes-console-vue/package.json +++ b/hermes-console-vue/package.json @@ -18,7 +18,11 @@ }, "dependencies": { "axios": "1.4.0", + "base64-arraybuffer": "1.0.2", + "jwt-decode": "3.1.2", "pinia": "2.1.4", + "pinia-plugin-persistedstate": "3.2.0", + "query-string": "8.1.0", "vue": "3.3.4", "vue-i18n": "9.2.2", "vue-router": "4.2.2", diff --git a/hermes-console-vue/src/App.vue b/hermes-console-vue/src/App.vue index de7bb6d33a..06c6eb61d2 100644 --- a/hermes-console-vue/src/App.vue +++ b/hermes-console-vue/src/App.vue @@ -1,25 +1,29 @@ - - + + diff --git a/hermes-console-vue/src/views/subscription/SubscriptionView.vue b/hermes-console-vue/src/views/subscription/SubscriptionView.vue index 6c74ecd0ff..24954c1af1 100644 --- a/hermes-console-vue/src/views/subscription/SubscriptionView.vue +++ b/hermes-console-vue/src/views/subscription/SubscriptionView.vue @@ -42,15 +42,15 @@ }, { title: t('subscription.subscriptionBreadcrumbs.groups'), - href: '/#/groups', + href: '/ui/groups', }, { title: groupId, - href: `/#/groups/${groupId}`, + href: `/ui/groups/${groupId}`, }, { title: topicId, - href: `/#/groups/${groupId}/topics/${topicId}`, + href: `/ui/groups/${groupId}/topics/${topicId}`, }, { title: subscriptionId, diff --git a/hermes-console-vue/src/views/topic/TopicView.spec.ts b/hermes-console-vue/src/views/topic/TopicView.spec.ts index 5e851ce36c..cbf6c13134 100644 --- a/hermes-console-vue/src/views/topic/TopicView.spec.ts +++ b/hermes-console-vue/src/views/topic/TopicView.spec.ts @@ -45,7 +45,7 @@ const useTopicMock: UseTopic = { describe('TopicView', () => { beforeEach(async () => { await router.push( - `/groups/pl.allegro.public.group` + `/topics/${dummyTopic.name}`, + `/ui/groups/pl.allegro.public.group` + `/topics/${dummyTopic.name}`, ); }); diff --git a/hermes-console-vue/src/views/topic/TopicView.vue b/hermes-console-vue/src/views/topic/TopicView.vue index f068b3358b..2070d276da 100644 --- a/hermes-console-vue/src/views/topic/TopicView.vue +++ b/hermes-console-vue/src/views/topic/TopicView.vue @@ -40,15 +40,15 @@ }, { title: t('subscription.subscriptionBreadcrumbs.groups'), - href: '/#/groups', + href: '/ui/groups', }, { title: groupId, - href: `/#/groups/${groupId}`, + href: `/ui/groups/${groupId}`, }, { title: topicName, - href: `/#/groups/${groupId}/topics/${topicName}`, + href: `/ui/groups/${groupId}/topics/${topicName}`, }, ]; const configStore = useAppConfigStore(); diff --git a/hermes-console-vue/yarn.lock b/hermes-console-vue/yarn.lock index a4c0a6f9e1..8efb916664 100644 --- a/hermes-console-vue/yarn.lock +++ b/hermes-console-vue/yarn.lock @@ -1041,6 +1041,11 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== +base64-arraybuffer@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz#1c37589a7c4b0746e34bd1feb951da2df01c1bdc" + integrity sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ== + base64-js@^1.3.1: version "1.5.1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" @@ -1482,6 +1487,11 @@ decimal.js@^10.4.3: resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.4.3.tgz#1044092884d245d1b7f65725fa4ad4c6f781cc23" integrity sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA== +decode-uri-component@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.4.1.tgz#2ac4859663c704be22bf7db760a1494a49ab2cc5" + integrity sha512-+8VxcR21HhTy8nOt6jf20w0c9CADrw1O8d+VZ/YzzCt4bJ3uBjw+D1q2osAB8RnpwwaeYBxy0HyKQxD5JBMuuQ== + deep-eql@^4.1.2: version "4.1.3" resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.3.tgz#7c7775513092f7df98d8df9996dd085eb668cc6d" @@ -2038,6 +2048,11 @@ fill-range@^7.0.1: dependencies: to-regex-range "^5.0.1" +filter-obj@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/filter-obj/-/filter-obj-5.1.0.tgz#5bd89676000a713d7db2e197f660274428e524ed" + integrity sha512-qWeTREPoT7I0bifpPUXtxkZJ1XJzxWtfoWWkdVGqa+eCr3SHW/Ocp89o8vLvbUuQnadybJpjOKu4V+RwO6sGng== + finalhandler@1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.2.0.tgz#7d23fe5731b207b4640e4fcd00aec1f9207a7b32" @@ -2852,6 +2867,11 @@ jsonc-parser@^3.2.0: resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76" integrity sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w== +jwt-decode@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-3.1.2.tgz#3fb319f3675a2df0c2895c8f5e9fa4b67b04ed59" + integrity sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A== + levn@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/levn/-/levn-0.4.1.tgz#ae4562c007473b932a6200d403268dd2fffc6ade" @@ -3468,6 +3488,11 @@ pify@^3.0.0: resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176" integrity sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg== +pinia-plugin-persistedstate@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/pinia-plugin-persistedstate/-/pinia-plugin-persistedstate-3.2.0.tgz#9932ca2ae88aa6c0d6763bebc6447d7bd1f097d0" + integrity sha512-tZbNGf2vjAQcIm7alK40sE51Qu/m9oWr+rEgNm/2AWr1huFxj72CjvpQcIQzMknDBJEkQznCLAGtJTIcLKrKdw== + pinia@2.1.4: version "2.1.4" resolved "https://registry.yarnpkg.com/pinia/-/pinia-2.1.4.tgz#a642adfe6208e10c36d3dc16184a91064788142a" @@ -3596,6 +3621,15 @@ qs@6.11.0: dependencies: side-channel "^1.0.4" +query-string@^8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/query-string/-/query-string-8.1.0.tgz#e7f95367737219544cd360a11a4f4ca03836e115" + integrity sha512-BFQeWxJOZxZGix7y+SByG3F36dA0AbTy9o6pSmKFcFz7DAj0re9Frkty3saBn3nHo3D0oZJ/+rx3r8H8r8Jbpw== + dependencies: + decode-uri-component "^0.4.1" + filter-obj "^5.1.0" + split-on-first "^3.0.0" + querystringify@^2.1.1: version "2.2.0" resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6" @@ -3970,6 +4004,11 @@ spdx-license-ids@^3.0.0: resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.12.tgz#69077835abe2710b65f03969898b6637b505a779" integrity sha512-rr+VVSXtRhO4OHbXUiAF7xW3Bo9DuuF6C5jH+q/x15j2jniycgKbxU09Hr0WqlSLUs4i4ltHGXqTe7VHclYWyA== +split-on-first@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-3.0.0.tgz#f04959c9ea8101b9b0bbf35a61b9ebea784a23e7" + integrity sha512-qxQJTx2ryR0Dw0ITYyekNQWpz6f8dGd7vffGNflQQ3Iqj9NJ6qiZ7ELpZsJ/QBhIVAiDfXdag3+Gp8RvWa62AA== + stack-utils@^2.0.3: version "2.0.6" resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-2.0.6.tgz#aaf0748169c02fc33c8232abccf933f54a1cc34f" diff --git a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/config/console/ConsoleProperties.java b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/config/console/ConsoleProperties.java index 122da5d7a2..a3ec5a1170 100644 --- a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/config/console/ConsoleProperties.java +++ b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/config/console/ConsoleProperties.java @@ -277,7 +277,9 @@ public void setHeaders(AuthHeaders headers) { public static final class OAuth { private boolean enabled = false; - private String url = "localhost:8092/auth"; + private String url = "localhost:8092"; + private String authorizationEndpoint = "/auth/oauth/authorize"; + private String tokenEndpoint = "/auth/oauth/token"; private String clientId = "hermes"; private String scope = "hermes"; @@ -297,6 +299,22 @@ public void setUrl(String url) { this.url = url; } + public String getAuthorizationEndpoint() { + return authorizationEndpoint; + } + + public void setAuthorizationEndpoint(String authorizationEndpoint) { + this.authorizationEndpoint = authorizationEndpoint; + } + + public String getTokenEndpoint() { + return tokenEndpoint; + } + + public void setTokenEndpoint(String tokenEndpoint) { + this.tokenEndpoint = tokenEndpoint; + } + public String getClientId() { return clientId; }