diff --git a/login/adminLoginGuard.guard.ts b/login/adminLoginGuard.guard.ts index 0548fb3b..53b2ec94 100644 --- a/login/adminLoginGuard.guard.ts +++ b/login/adminLoginGuard.guard.ts @@ -13,7 +13,9 @@ import {LoginErrorCodes} from './utils/guardHelper.class'; import {UserManagementService} from "../services/user-management.service"; import {map, tap} from "rxjs/operators"; -@Injectable() +@Injectable({ + providedIn: 'root' +}) export class AdminLoginGuard implements CanActivate, CanActivateChild { constructor(private router: Router, diff --git a/login/loginGuard.guard.ts b/login/loginGuard.guard.ts index 59e72592..0c9f737c 100644 --- a/login/loginGuard.guard.ts +++ b/login/loginGuard.guard.ts @@ -6,15 +6,17 @@ import { CanLoad, Route, Router, - RouterStateSnapshot, UrlTree + RouterStateSnapshot, + UrlTree } from '@angular/router'; import {Observable} from 'rxjs'; -import {Session} from './utils/helper.class'; import {LoginErrorCodes} from './utils/guardHelper.class'; import {map, tap} from "rxjs/operators"; import {UserManagementService} from "../services/user-management.service"; -@Injectable() +@Injectable({ + providedIn: 'root' +}) export class LoginGuard implements CanActivate, CanLoad, CanActivateChild { constructor(private router: Router, diff --git a/login/utils/helper.class.ts b/login/utils/helper.class.ts index ca98fd5c..7594fac1 100644 --- a/login/utils/helper.class.ts +++ b/login/utils/helper.class.ts @@ -6,8 +6,8 @@ export class User { fullname: string; expirationDate: number; role: string[]; - jwt: string; - + accessToken?: string; + refreshToken?: string; } export class Session { diff --git a/reload/reload.component.ts b/reload/reload.component.ts index e86df79c..833b43ce 100644 --- a/reload/reload.component.ts +++ b/reload/reload.component.ts @@ -16,6 +16,7 @@ export class ReloadComponent { public ngOnInit() { let URL = Session.getReloadUrl(); + console.log(URL); if (URL && URL["path"] && URL["path"] != "") { let url: string = URL["path"]; let host = URL["host"]; @@ -23,6 +24,7 @@ export class ReloadComponent { if (host == (location.protocol + "//" + location.host)) { let baseUrl = (document && document.getElementsByTagName('base')) ? document.getElementsByTagName('base')[0].href.split(document.location.host)[1] : "/"; url = (baseUrl.length > 1 && url.indexOf(baseUrl) != -1) ? ("/" + url.split(baseUrl)[1]) : url; + console.log(url); if (paramsObject) { Session.setReloadUrl("", "", "", ""); if(URL['fragment'] && URL['fragment'] !== '') { diff --git a/services/user-management.service.ts b/services/user-management.service.ts index 9291cc6a..0b942edb 100644 --- a/services/user-management.service.ts +++ b/services/user-management.service.ts @@ -54,13 +54,19 @@ export class UserManagementService { } }); } - + private parseUserInfo(info: any) { const user: User = new User(); user.id = (info.sub && info.sub.indexOf('@')) ? info.sub.substring(0, info.sub.indexOf('@')) : info.sub; user.firstname = (info.given_name) ? info.given_name : ""; user.lastname = (info.family_name) ? info.family_name : ""; user.email = info.email.toLowerCase(); // TODO remove, is a quick fix + if(info.accessToken) { + user.accessToken = info.accessToken; + } + if(info.refreshToken) { + user.refreshToken = info.refreshToken; + } user.fullname = (info.name) ? info.name : ""; if (user.fullname == "") { if (user.firstname != "") { diff --git a/utils/properties/env-properties.ts b/utils/properties/env-properties.ts index cacc7cb1..4b1279bf 100644 --- a/utils/properties/env-properties.ts +++ b/utils/properties/env-properties.ts @@ -64,6 +64,7 @@ export interface EnvProperties { registryUrl?: string; logoutUrl?: string; userInfoUrl?: string; + clientManagementUrl?: string, cookieDomain?: string; feedbackmail?: string; feedbackmailForMissingEntities?: string; diff --git a/utils/string-utils.class.ts b/utils/string-utils.class.ts index 61d45b48..b1dab0d3 100644 --- a/utils/string-utils.class.ts +++ b/utils/string-utils.class.ts @@ -266,6 +266,8 @@ export class StringUtils { '[a-zA-Z0-9]+\\.[^\\s]{2,}'; public static routeRegex = '^[a-zA-Z0-9\/][a-zA-Z0-9\/-]*$'; + + public static jsonRegex = /^[\],:{}\s]*$/; public static urlPrefix(url: string): string { if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//")) { @@ -325,6 +327,19 @@ export class StringUtils { public static urlValidator(): ValidatorFn { return Validators.pattern(StringUtils.urlRegex); } + + public static jsonValidator(error: string = ''): ValidatorFn { + return (control: AbstractControl): ValidationErrors | null => { + if(control.value) { + let test = control.getRawValue().replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''); + console.log('test') + if(!new RegExp(this.jsonRegex).test(test)) { + return {error: 'Please provide a valid JSON.' + error} + } + } + return null; + }; + } public static validatorType(options: string[]): ValidatorFn { return (control: AbstractControl): { [key: string]: boolean } | null => {