Skip to content

Commit 5000436

Browse files
committed
Angular Security course
1 parent a6730c7 commit 5000436

8 files changed

+8
-181
lines changed

server/authorization.middleware.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

server/login-as-user.route.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

server/server.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import {login} from "./login.route";
1212
import {retrieveUserIdFromRequest} from "./get-user.middleware";
1313
import {checkIfAuthenticated} from "./authentication.middleware";
1414
import {checkCsrfToken} from "./csrf.middleware";
15-
import {loginAsUser} from "./login-as-user.route";
16-
import {checkIfAuthorized} from "./authorization.middleware";
17-
import * as _ from 'lodash';
15+
1816
const bodyParser = require('body-parser');
1917
const cookieParser = require('cookie-parser');
2018

@@ -36,15 +34,11 @@ const options = commandLineArgs(optionDefinitions);
3634

3735
// REST API
3836
app.route('/api/lessons')
39-
.get(checkIfAuthenticated, _.partial(checkIfAuthorized, ['STUDENT']), readAllLessons);
37+
.get(checkIfAuthenticated, readAllLessons);
4038

4139
app.route('/api/signup')
4240
.post(createUser);
4341

44-
45-
app.route('/api/admin')
46-
.post(checkIfAuthenticated, _.partial(checkIfAuthorized, ['ADMIN']) , loginAsUser);
47-
4842
app.route('/api/user')
4943
.get(getUser);
5044

src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<li>
1010
<a routerLink="/lessons">Lessons</a>
1111
</li>
12-
<li *rbacAllow="['ADMIN']">
12+
<li>
1313
<a routerLink="/admin">Admin</a>
1414
</li>
1515
<li *ngIf="isLoggedOut$ | async">

src/app/app.module.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {LessonsService} from "./services/lessons.service";
1111
import {ReactiveFormsModule} from "@angular/forms";
1212

1313
import {AuthService} from "./services/auth.service";
14+
import { AdminComponent } from './admin/admin.component';
15+
import { RouterModule} from "@angular/router";
16+
1417

1518
import 'rxjs/add/operator/switchMap';
1619
import 'rxjs/add/operator/map';
@@ -20,11 +23,6 @@ import 'rxjs/add/operator/filter';
2023
import 'rxjs/add/operator/catch';
2124
import 'rxjs/add/operator/first';
2225
import 'rxjs/add/observable/of';
23-
import { AdminComponent } from './admin/admin.component';
24-
import {AuthorizationGuard} from "./services/auth.guard";
25-
import {Router, RouterModule} from "@angular/router";
26-
import {RbacAllow} from "./common/rbac-allow.directive";
27-
2826

2927

3028

@@ -35,8 +33,7 @@ import {RbacAllow} from "./common/rbac-allow.directive";
3533
LessonsComponent,
3634
LoginComponent,
3735
SignupComponent,
38-
AdminComponent,
39-
RbacAllow
36+
AdminComponent
4037
],
4138
imports: [
4239
BrowserModule,
@@ -49,15 +46,6 @@ import {RbacAllow} from "./common/rbac-allow.directive";
4946
ReactiveFormsModule
5047
],
5148
providers: [
52-
{
53-
provide: 'adminsOnlyGuard',
54-
useFactory: (authService:AuthService,
55-
router:Router) => new AuthorizationGuard(['ADMIN'], authService, router),
56-
deps: [
57-
AuthService,
58-
Router
59-
]
60-
},
6149
LessonsService,
6250
AuthService
6351
],

src/app/common/rbac-allow.directive.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/app/routes.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export const routesConfig: Routes = [
1919
},
2020
{
2121
path: 'admin',
22-
component: AdminComponent,
23-
canActivate: ["adminsOnlyGuard"]
22+
component: AdminComponent
2423
},
2524
{
2625
path: '',

src/app/services/auth.guard.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)