Skip to content

Commit

Permalink
Added security flag in order to use different security systems
Browse files Browse the repository at this point in the history
  • Loading branch information
sjimenez77 committed May 17, 2018
1 parent a52b70f commit 09bc1b0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/app/core/security/httpRequestInterceptor.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { environment } from '../../../environments/environment';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import {
Expand All @@ -20,10 +21,22 @@ export class HttpRequestInterceptorService implements HttpInterceptor {
// Get the auth header from the service.
const authHeader: string = this.auth.getToken();
if (authHeader) {
const authReq: HttpRequest<any> = req.clone({
withCredentials: true,
setHeaders: { 'x-csrf-token': authHeader },
});
let authReq: HttpRequest<any>;

// CSRF
if (environment.security === 'csrf') {
authReq = req.clone({
withCredentials: true,
setHeaders: { 'x-csrf-token': authHeader },
});
}

// JWT
if (environment.security === 'jwt') {
authReq = req.clone({
setHeaders: { Authorization: authHeader },
});
}

return next.handle(authReq);
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ export const environment: {
production: boolean;
restPathRoot: string;
restServiceRoot: string;
security: 'csrf' | 'jwt';
} = {
production: true,
restPathRoot: 'http://localhost:8081/demo-server/',
restServiceRoot: 'http://localhost:8081/demo-server/services/rest/',
security: 'csrf',
};
4 changes: 3 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ export const environment: {
production: boolean;
restPathRoot: string;
restServiceRoot: string;
security: 'csrf' | 'jwt';
} = {
production: false,
production: true,
restPathRoot: 'http://localhost:8081/demo-server/',
restServiceRoot: 'http://localhost:8081/demo-server/services/rest/',
security: 'csrf',
};

0 comments on commit 09bc1b0

Please sign in to comment.