From 36ea37aff2d9ff1036ab71adf63a238a3db4eb2c Mon Sep 17 00:00:00 2001 From: MaxKey Date: Sun, 15 May 2022 09:05:56 +0800 Subject: [PATCH] jwt login support --- .../org/maxkey/authn/jwt/AuthJwtService.java | 5 +- .../authn/support/jwt/HttpJwtEntryPoint.java | 28 +++++++++- .../app/routes/passport/jwt-auth.component.ts | 56 +++++++++++++++++++ .../passport/passport-routing.module.ts | 11 ++-- .../src/app/service/authn.service.ts | 12 ++++ .../maxkey-web-app/src/app/shared/consts.ts | 1 + .../layout/passport/passport.component.html | 17 ++++-- .../app/layout/passport/passport.component.ts | 22 ++++++-- .../app-basic-details-editer.component.ts | 7 +-- .../app-cas-details-editer.component.ts | 7 +-- ...app-extend-api-details-editer.component.ts | 7 +-- ...app-form-based-details-editer.component.ts | 7 +-- .../app-jwt-details-editer.component.ts | 7 +-- .../app-oauth20-details-editer.component.ts | 7 +-- .../app-saml20-details-editer.component.ts | 7 +-- ...pp-token-based-details-editer.component.ts | 7 +-- .../app/routes/passport/jwt-auth.component.ts | 10 ++-- .../routes/passport/login/login.component.ts | 20 +++---- ...entication.service.ts => authn.service.ts} | 10 +++- .../src/app/shared/consts.ts | 1 + 20 files changed, 181 insertions(+), 68 deletions(-) create mode 100644 maxkey-web-frontend/maxkey-web-app/src/app/routes/passport/jwt-auth.component.ts rename maxkey-web-frontend/maxkey-web-mgt-app/src/app/service/{authentication.service.ts => authn.service.ts} (92%) diff --git a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/jwt/AuthJwtService.java b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/jwt/AuthJwtService.java index 0031aac26..26d11d66f 100644 --- a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/jwt/AuthJwtService.java +++ b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/jwt/AuthJwtService.java @@ -124,8 +124,9 @@ public class AuthJwtService { JWTClaimsSet claims = resolve(authToken); boolean isExpiration = claims.getExpirationTime().after(DateTime.now().toDate()); boolean isVerify = hmac512Service.verify(authToken); - _logger.trace("JWT Verify {} , now {} , ExpirationTime {} , isExpiration : {}" , - isVerify,DateTime.now().toDate(),claims.getExpirationTime(),isExpiration); + _logger.debug("JWT Validate {} , Verify {} , now {} , ExpirationTime {} , isExpiration : {}" , + isVerify && isExpiration,isVerify,DateTime.now().toDate(),claims.getExpirationTime(),isExpiration); + return isVerify && isExpiration; } } catch (ParseException e) { diff --git a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/support/jwt/HttpJwtEntryPoint.java b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/support/jwt/HttpJwtEntryPoint.java index 19e0b0865..7d30cff6e 100644 --- a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/support/jwt/HttpJwtEntryPoint.java +++ b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/support/jwt/HttpJwtEntryPoint.java @@ -54,7 +54,7 @@ public class HttpJwtEntryPoint { JwtLoginService jwtLoginService; @RequestMapping(value={"/jwt"}, produces = {MediaType.APPLICATION_JSON_VALUE}) - public ResponseEntity jwt(@RequestParam(value = WebConstants.JWT_TOKEN_PARAMETER, required = false) String jwt) { + public ResponseEntity jwt(@RequestParam(value = WebConstants.JWT_TOKEN_PARAMETER, required = true) String jwt) { try { //for jwt Login _logger.debug("jwt : " + jwt); @@ -75,6 +75,32 @@ public class HttpJwtEntryPoint { return new Message(Message.FAIL).buildResponse(); } + + /** + * trust same HS512 + * @param jwt + * @return + */ + @RequestMapping(value={"/jwt/trust"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity jwtTrust(@RequestParam(value = WebConstants.JWT_TOKEN_PARAMETER, required = true) String jwt) { + try { + //for jwt Login + _logger.debug("jwt : " + jwt); + + if(authTokenService.validateJwtToken(jwt)) { + String username =authTokenService.resolve(jwt).getSubject(); + LoginCredential loginCredential =new LoginCredential(username,"",ConstsLoginType.JWT); + Authentication authentication = authenticationProvider.authenticate(loginCredential,true); + _logger.debug("JWT Logined in , username " + username); + AuthJwt authJwt = authTokenService.genAuthJwt(authentication); + return new Message(authJwt).buildResponse(); + } + }catch(Exception e) { + _logger.error("Exception ",e); + } + + return new Message(Message.FAIL).buildResponse(); + } public void setApplicationConfig(ApplicationConfig applicationConfig) { diff --git a/maxkey-web-frontend/maxkey-web-app/src/app/routes/passport/jwt-auth.component.ts b/maxkey-web-frontend/maxkey-web-app/src/app/routes/passport/jwt-auth.component.ts new file mode 100644 index 000000000..4a618af59 --- /dev/null +++ b/maxkey-web-frontend/maxkey-web-app/src/app/routes/passport/jwt-auth.component.ts @@ -0,0 +1,56 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Component, OnInit, Inject } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { ReuseTabService } from '@delon/abc/reuse-tab'; +import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth'; +import { SettingsService } from '@delon/theme'; + +import { AuthnService } from '../../service/authn.service'; + +@Component({ + selector: 'app-jwt-auth', + template: `` +}) +export class JwtAuthComponent implements OnInit { + jwt = ''; + + constructor( + private authnService: AuthnService, + @Inject(ReuseTabService) + private reuseTabService: ReuseTabService, + private router: Router, + private settingsSrv: SettingsService, + private route: ActivatedRoute + ) { } + + ngOnInit(): void { + this.jwt = this.route.snapshot.queryParams['jwt']; + + this.authnService.jwtAuth({ jwt: this.jwt }).subscribe(res => { + if (res.code !== 0) { + this.router.navigateByUrl('/passport/login'); + } else { + // 清空路由复用信息 + this.reuseTabService.clear(); + // 设置用户Token信息 + this.authnService.auth(res.data); + this.authnService.navigate({}); + } + }); + } +} diff --git a/maxkey-web-frontend/maxkey-web-app/src/app/routes/passport/passport-routing.module.ts b/maxkey-web-frontend/maxkey-web-app/src/app/routes/passport/passport-routing.module.ts index e3d9a16bf..f69e87e0b 100644 --- a/maxkey-web-frontend/maxkey-web-app/src/app/routes/passport/passport-routing.module.ts +++ b/maxkey-web-frontend/maxkey-web-app/src/app/routes/passport/passport-routing.module.ts @@ -1,19 +1,18 @@ /* * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; @@ -21,6 +20,7 @@ import { RouterModule, Routes } from '@angular/router'; import { LayoutPassportComponent } from '../../layout/passport/passport.component'; import { CallbackComponent } from './callback.component'; import { ForgotComponent } from './forgot/forgot.component'; +import { JwtAuthComponent } from './jwt-auth.component'; import { UserLockComponent } from './lock/lock.component'; import { UserLoginComponent } from './login/login.component'; import { UserRegisterResultComponent } from './register-result/register-result.component'; @@ -60,7 +60,8 @@ const routes: Routes = [ ] }, // 单页不包裹Layout - { path: 'passport/callback/:provider', component: CallbackComponent } + { path: 'passport/callback/:provider', component: CallbackComponent }, + { path: 'passport/jwt/auth', component: JwtAuthComponent } ]; @NgModule({ diff --git a/maxkey-web-frontend/maxkey-web-app/src/app/service/authn.service.ts b/maxkey-web-frontend/maxkey-web-app/src/app/service/authn.service.ts index 8a2c991b1..7b6a16ce3 100644 --- a/maxkey-web-frontend/maxkey-web-app/src/app/service/authn.service.ts +++ b/maxkey-web-frontend/maxkey-web-app/src/app/service/authn.service.ts @@ -100,6 +100,18 @@ export class AuthnService { this.tokenService.get()?.expired; } + jwtAuth(authParam: any) { + return this.http.get(`/login/jwt/trust?_allow_anonymous=true`, authParam); + } + + setInst(inst: any) { + localStorage.setItem(CONSTS.INST, JSON.stringify({ id: inst.id, name: inst.name, title: inst.frontTitle, logo: inst.logo })); + } + + getInst() { + return JSON.parse(`${localStorage.getItem(CONSTS.INST)}`); + } + setRoles(aclService: ACLService | null): string[] { let authorities: string[] = JSON.parse(localStorage.getItem(CONSTS.TOKEN) || '')?.authorities || []; if (aclService) { diff --git a/maxkey-web-frontend/maxkey-web-app/src/app/shared/consts.ts b/maxkey-web-frontend/maxkey-web-app/src/app/shared/consts.ts index 9a2827765..35f698e63 100644 --- a/maxkey-web-frontend/maxkey-web-app/src/app/shared/consts.ts +++ b/maxkey-web-frontend/maxkey-web-app/src/app/shared/consts.ts @@ -15,6 +15,7 @@ */ export const CONSTS = { + INST: 'inst', CONGRESS: 'congress', ONLINE_TICKET: 'online_ticket', REDIRECT_URI: 'redirect_uri', diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/layout/passport/passport.component.html b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/layout/passport/passport.component.html index 92c1c2166..55a280b7d 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/layout/passport/passport.component.html +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/layout/passport/passport.component.html @@ -1,12 +1,18 @@
-
+
+ + +
-
{{ 'mxk.login.title' | i18n }}{{ 'mxk.title' | i18n }}
+
MaxKey{{ 'mxk.title' | i18n }}
+
{{ inst.title }}
-
+
+ +
@@ -19,10 +25,11 @@
MaxKey {{ version }}
Copyright - 2022 http://www.maxkey.top
+ + 2022 http://www.maxkey.top
Licensed under the Apache License, Version 2.0
- + \ No newline at end of file diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/layout/passport/passport.component.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/layout/passport/passport.component.ts index c1c94f235..687aad528 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/layout/passport/passport.component.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/layout/passport/passport.component.ts @@ -1,22 +1,22 @@ /* * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - import { Component, Inject, OnInit } from '@angular/core'; import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth'; +import { AuthnService } from 'src/app/service/authn.service'; import { CONSTS } from 'src/app/shared/consts'; @Component({ @@ -26,6 +26,8 @@ import { CONSTS } from 'src/app/shared/consts'; }) export class LayoutPassportComponent implements OnInit { version = CONSTS.VERSION; + isTitle: boolean = false; + inst: any; links = [ { title: '帮助', @@ -37,9 +39,19 @@ export class LayoutPassportComponent implements OnInit { } ]; - constructor(@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService) { } + constructor(@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService, private authnService: AuthnService) { } ngOnInit(): void { + if ( + window.location.hostname != 'localhost' && + window.location.hostname != 'sso.maxkey.top' && + window.location.hostname != 'mgt.maxkey.top' + ) { + this.inst = this.authnService.getInst(); + if (this.inst != null) { + this.isTitle = true; + } + } this.tokenService.clear(); } } diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-basic-details-editer/app-basic-details-editer.component.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-basic-details-editer/app-basic-details-editer.component.ts index b4896e0a3..d238f0750 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-basic-details-editer/app-basic-details-editer.component.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-basic-details-editer/app-basic-details-editer.component.ts @@ -1,19 +1,18 @@ /* * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - import { Component, ChangeDetectorRef, ViewContainerRef, Input, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-cas-details-editer/app-cas-details-editer.component.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-cas-details-editer/app-cas-details-editer.component.ts index 34467043a..93d8e12ec 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-cas-details-editer/app-cas-details-editer.component.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-cas-details-editer/app-cas-details-editer.component.ts @@ -1,19 +1,18 @@ /* * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - import { Component, ChangeDetectorRef, ViewContainerRef, Input, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-extend-api-details-editer/app-extend-api-details-editer.component.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-extend-api-details-editer/app-extend-api-details-editer.component.ts index 58a017275..52159702b 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-extend-api-details-editer/app-extend-api-details-editer.component.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-extend-api-details-editer/app-extend-api-details-editer.component.ts @@ -1,19 +1,18 @@ /* * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - import { Component, ChangeDetectorRef, ViewContainerRef, Input, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-form-based-details-editer/app-form-based-details-editer.component.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-form-based-details-editer/app-form-based-details-editer.component.ts index bc68459c7..ba4598733 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-form-based-details-editer/app-form-based-details-editer.component.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-form-based-details-editer/app-form-based-details-editer.component.ts @@ -1,19 +1,18 @@ /* * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - import { Component, ChangeDetectorRef, ViewContainerRef, Input, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-jwt-details-editer/app-jwt-details-editer.component.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-jwt-details-editer/app-jwt-details-editer.component.ts index cd1df1f66..aeeb96249 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-jwt-details-editer/app-jwt-details-editer.component.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-jwt-details-editer/app-jwt-details-editer.component.ts @@ -1,19 +1,18 @@ /* * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - import { Component, ChangeDetectorRef, ViewContainerRef, Input, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-oauth20-details-editer/app-oauth20-details-editer.component.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-oauth20-details-editer/app-oauth20-details-editer.component.ts index aedfbe3e5..8d9a8f60a 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-oauth20-details-editer/app-oauth20-details-editer.component.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-oauth20-details-editer/app-oauth20-details-editer.component.ts @@ -1,19 +1,18 @@ /* * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - import { Component, ChangeDetectorRef, ViewContainerRef, Input, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-saml20-details-editer/app-saml20-details-editer.component.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-saml20-details-editer/app-saml20-details-editer.component.ts index b2aae27be..e2c10df8f 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-saml20-details-editer/app-saml20-details-editer.component.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-saml20-details-editer/app-saml20-details-editer.component.ts @@ -1,19 +1,18 @@ /* * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - import { Component, ChangeDetectorRef, ViewContainerRef, Input, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-token-based-details-editer/app-token-based-details-editer.component.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-token-based-details-editer/app-token-based-details-editer.component.ts index e8c859ced..509944340 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-token-based-details-editer/app-token-based-details-editer.component.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/apps/app-token-based-details-editer/app-token-based-details-editer.component.ts @@ -1,19 +1,18 @@ /* * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - import { Component, ChangeDetectorRef, ViewContainerRef, Input, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/passport/jwt-auth.component.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/passport/jwt-auth.component.ts index 053a98522..4a618af59 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/passport/jwt-auth.component.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/passport/jwt-auth.component.ts @@ -20,7 +20,7 @@ import { ReuseTabService } from '@delon/abc/reuse-tab'; import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth'; import { SettingsService } from '@delon/theme'; -import { AuthenticationService } from '../../service/authentication.service'; +import { AuthnService } from '../../service/authn.service'; @Component({ selector: 'app-jwt-auth', @@ -30,7 +30,7 @@ export class JwtAuthComponent implements OnInit { jwt = ''; constructor( - private authenticationService: AuthenticationService, + private authnService: AuthnService, @Inject(ReuseTabService) private reuseTabService: ReuseTabService, private router: Router, @@ -41,15 +41,15 @@ export class JwtAuthComponent implements OnInit { ngOnInit(): void { this.jwt = this.route.snapshot.queryParams['jwt']; - this.authenticationService.jwtAuth({ jwt: this.jwt }).subscribe(res => { + this.authnService.jwtAuth({ jwt: this.jwt }).subscribe(res => { if (res.code !== 0) { this.router.navigateByUrl('/passport/login'); } else { // 清空路由复用信息 this.reuseTabService.clear(); // 设置用户Token信息 - this.authenticationService.auth(res.data); - this.authenticationService.navigate({}); + this.authnService.auth(res.data); + this.authnService.navigate({}); } }); } diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/passport/login/login.component.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/passport/login/login.component.ts index c62e9bd16..f4d42e3d3 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/passport/login/login.component.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/routes/passport/login/login.component.ts @@ -25,7 +25,7 @@ import { environment } from '@env/environment'; import { NzTabChangeEvent } from 'ng-zorro-antd/tabs'; import { finalize } from 'rxjs/operators'; -import { AuthenticationService } from '../../../service/authentication.service'; +import { AuthnService } from '../../../service/authn.service'; import { ImageCaptchaService } from '../../../service/image-captcha.service'; @Component({ @@ -37,16 +37,11 @@ import { ImageCaptchaService } from '../../../service/image-captcha.service'; export class UserLoginComponent implements OnInit, OnDestroy { constructor( fb: FormBuilder, - private router: Router, - private settingsService: SettingsService, @Optional() @Inject(ReuseTabService) private reuseTabService: ReuseTabService, - @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService, - private startupSrv: StartupService, - private authenticationService: AuthenticationService, + private authnService: AuthnService, private imageCaptchaService: ImageCaptchaService, - private http: _HttpClient, private cdr: ChangeDetectorRef ) { this.form = fb.group({ @@ -84,8 +79,8 @@ export class UserLoginComponent implements OnInit, OnDestroy { ngOnInit(): void { //init socials,state - this.authenticationService.clear(); - this.authenticationService + this.authnService.clear(); + this.authnService .get({}) .pipe( finalize(() => { @@ -100,6 +95,7 @@ export class UserLoginComponent implements OnInit, OnDestroy { } else { // 清空路由复用信息 console.log(res.data); + this.authnService.setInst(res.data.inst); this.state = res.data.state; //init image captcha this.imageCaptchaService.captcha({ state: this.state }).subscribe(res => { @@ -149,7 +145,7 @@ export class UserLoginComponent implements OnInit, OnDestroy { // 然一般来说登录请求不需要校验,因此可以在请求URL加上:`/login?_allow_anonymous=true` 表示不触发用户 Token 校验 this.loading = true; this.cdr.detectChanges(); - this.authenticationService + this.authnService .login({ authType: 'normal', state: this.state, @@ -174,8 +170,8 @@ export class UserLoginComponent implements OnInit, OnDestroy { // 清空路由复用信息 this.reuseTabService.clear(); // 设置用户Token信息 - this.authenticationService.auth(res.data); - this.authenticationService.navigate({}); + this.authnService.auth(res.data); + this.authnService.navigate({}); } this.cdr.detectChanges(); }); diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/service/authentication.service.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/service/authn.service.ts similarity index 92% rename from maxkey-web-frontend/maxkey-web-mgt-app/src/app/service/authentication.service.ts rename to maxkey-web-frontend/maxkey-web-mgt-app/src/app/service/authn.service.ts index 2fcb27bb9..7421ba79b 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/service/authentication.service.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/service/authn.service.ts @@ -28,7 +28,7 @@ import { hostname } from 'os'; @Injectable({ providedIn: 'root' }) -export class AuthenticationService { +export class AuthnService { redirect_uri: string = ''; constructor( @@ -94,6 +94,14 @@ export class AuthenticationService { this.tokenService.get()?.expired; } + setInst(inst: any) { + localStorage.setItem(CONSTS.INST, JSON.stringify({ id: inst.id, name: inst.name, title: inst.consoleTitle, logo: inst.logo })); + } + + getInst() { + return JSON.parse(`${localStorage.getItem(CONSTS.INST)}`); + } + navigate(authJwt: any) { // 重新获取 StartupService 内容,我们始终认为应用信息一般都会受当前用户授权范围而影响 this.startupService.load().subscribe(() => { diff --git a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/shared/consts.ts b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/shared/consts.ts index 8a1d1787f..2c1936578 100644 --- a/maxkey-web-frontend/maxkey-web-mgt-app/src/app/shared/consts.ts +++ b/maxkey-web-frontend/maxkey-web-mgt-app/src/app/shared/consts.ts @@ -16,6 +16,7 @@ export const CONSTS = { CONGRESS: 'congress', + INST: 'inst', REDIRECT_URI: 'redirect_uri', REMEMBER: 'remember', VERSION: 'v3.5.0 GA'