[webapp,manager] 路由守卫,升级sureness
This commit is contained in:
@@ -108,7 +108,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.usthe.sureness</groupId>
|
<groupId>com.usthe.sureness</groupId>
|
||||||
<artifactId>spring-boot-starter-sureness</artifactId>
|
<artifactId>spring-boot-starter-sureness</artifactId>
|
||||||
<version>1.0.0-beta.2</version>
|
<version>1.0.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,11 @@
|
|||||||
resourceRole:
|
resourceRole:
|
||||||
- /account/auth/refresh===post===[role1,role2,role3,role4]
|
- /account/auth/refresh===post===[role1,role2,role3,role4]
|
||||||
|
|
||||||
# load api resource which do not need be protected, means them need be excluded.
|
# load api resource which do not need protected, means them need be excluded.
|
||||||
# these api resource can be access by everyone
|
# these api resource can be access by everyone
|
||||||
excludedResource:
|
excludedResource:
|
||||||
- /**===*
|
|
||||||
- /account/auth/form===post
|
- /account/auth/form===post
|
||||||
|
- /i18n/**===get
|
||||||
- /**/*.html===get
|
- /**/*.html===get
|
||||||
- /**/*.js===get
|
- /**/*.js===get
|
||||||
- /**/*.css===get
|
- /**/*.css===get
|
||||||
|
|||||||
27
web-app/src/app/core/guard/detect-auth-guard.ts
Normal file
27
web-app/src/app/core/guard/detect-auth-guard.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from "@angular/router";
|
||||||
|
import {Observable} from "rxjs";
|
||||||
|
import {Injectable} from "@angular/core";
|
||||||
|
import {LocalStorageService} from "../../service/local-storage.service";
|
||||||
|
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class DetectAuthGuard implements CanActivate {
|
||||||
|
|
||||||
|
constructor(private localStorageSvc : LocalStorageService,
|
||||||
|
private notifySvc: NzNotificationService,
|
||||||
|
private router: Router) { }
|
||||||
|
|
||||||
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
|
||||||
|
Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||||
|
let activate = this.localStorageSvc.hasAuthorizationToken();
|
||||||
|
if (!activate) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.notifySvc.warning('请先登陆!','')
|
||||||
|
this.router.navigateByUrl('/passport/login');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return activate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { RouterModule, Routes } from '@angular/router';
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
import { SimpleGuard } from '@delon/auth';
|
|
||||||
import { environment } from '@env/environment';
|
import { environment } from '@env/environment';
|
||||||
// layout
|
// layout
|
||||||
import { LayoutBasicComponent } from '../layout/basic/basic.component';
|
import { LayoutBasicComponent } from '../layout/basic/basic.component';
|
||||||
@@ -14,13 +13,14 @@ import { UserLockComponent } from './passport/lock/lock.component';
|
|||||||
import { UserLoginComponent } from './passport/login/login.component';
|
import { UserLoginComponent } from './passport/login/login.component';
|
||||||
import { UserRegisterResultComponent } from './passport/register-result/register-result.component';
|
import { UserRegisterResultComponent } from './passport/register-result/register-result.component';
|
||||||
import { UserRegisterComponent } from './passport/register/register.component';
|
import { UserRegisterComponent } from './passport/register/register.component';
|
||||||
|
import {DetectAuthGuard} from "../core/guard/detect-auth-guard";
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
component: LayoutBasicComponent,
|
component: LayoutBasicComponent,
|
||||||
// 路由守卫 在路由之前判断是否有认证或者权限进入此路由
|
// 路由守卫 在路由之前判断是否有认证或者权限进入此路由
|
||||||
// canActivate: [SimpleGuard],
|
canActivate: [DetectAuthGuard],
|
||||||
children: [
|
children: [
|
||||||
// todo 根据路由自动生成面包屑
|
// todo 根据路由自动生成面包屑
|
||||||
{ path: '', redirectTo: 'dashboard', pathMatch: 'full'},
|
{ path: '', redirectTo: 'dashboard', pathMatch: 'full'},
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ export class LocalStorageService {
|
|||||||
return this.putData(Authorization, token);
|
return this.putData(Authorization, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public hasAuthorizationToken() {
|
||||||
|
return localStorage.getItem(Authorization) === null;
|
||||||
|
}
|
||||||
|
|
||||||
public clear() {
|
public clear() {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user