Add refreshToken and accessToken in userInfo. Add property for clientManagementAPI. Create jsonValidator
This commit is contained in:
parent
56428d0dae
commit
7d2eb68914
|
@ -13,7 +13,9 @@ import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||||
import {UserManagementService} from "../services/user-management.service";
|
import {UserManagementService} from "../services/user-management.service";
|
||||||
import {map, tap} from "rxjs/operators";
|
import {map, tap} from "rxjs/operators";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
export class AdminLoginGuard implements CanActivate, CanActivateChild {
|
export class AdminLoginGuard implements CanActivate, CanActivateChild {
|
||||||
|
|
||||||
constructor(private router: Router,
|
constructor(private router: Router,
|
||||||
|
|
|
@ -6,15 +6,17 @@ import {
|
||||||
CanLoad,
|
CanLoad,
|
||||||
Route,
|
Route,
|
||||||
Router,
|
Router,
|
||||||
RouterStateSnapshot, UrlTree
|
RouterStateSnapshot,
|
||||||
|
UrlTree
|
||||||
} from '@angular/router';
|
} from '@angular/router';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {Session} from './utils/helper.class';
|
|
||||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||||
import {map, tap} from "rxjs/operators";
|
import {map, tap} from "rxjs/operators";
|
||||||
import {UserManagementService} from "../services/user-management.service";
|
import {UserManagementService} from "../services/user-management.service";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
export class LoginGuard implements CanActivate, CanLoad, CanActivateChild {
|
export class LoginGuard implements CanActivate, CanLoad, CanActivateChild {
|
||||||
|
|
||||||
constructor(private router: Router,
|
constructor(private router: Router,
|
||||||
|
|
|
@ -6,8 +6,8 @@ export class User {
|
||||||
fullname: string;
|
fullname: string;
|
||||||
expirationDate: number;
|
expirationDate: number;
|
||||||
role: string[];
|
role: string[];
|
||||||
jwt: string;
|
accessToken?: string;
|
||||||
|
refreshToken?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Session {
|
export class Session {
|
||||||
|
|
|
@ -16,6 +16,7 @@ export class ReloadComponent {
|
||||||
|
|
||||||
public ngOnInit() {
|
public ngOnInit() {
|
||||||
let URL = Session.getReloadUrl();
|
let URL = Session.getReloadUrl();
|
||||||
|
console.log(URL);
|
||||||
if (URL && URL["path"] && URL["path"] != "") {
|
if (URL && URL["path"] && URL["path"] != "") {
|
||||||
let url: string = URL["path"];
|
let url: string = URL["path"];
|
||||||
let host = URL["host"];
|
let host = URL["host"];
|
||||||
|
@ -23,6 +24,7 @@ export class ReloadComponent {
|
||||||
if (host == (location.protocol + "//" + location.host)) {
|
if (host == (location.protocol + "//" + location.host)) {
|
||||||
let baseUrl = (document && document.getElementsByTagName('base')) ? document.getElementsByTagName('base')[0].href.split(document.location.host)[1] : "/";
|
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;
|
url = (baseUrl.length > 1 && url.indexOf(baseUrl) != -1) ? ("/" + url.split(baseUrl)[1]) : url;
|
||||||
|
console.log(url);
|
||||||
if (paramsObject) {
|
if (paramsObject) {
|
||||||
Session.setReloadUrl("", "", "", "");
|
Session.setReloadUrl("", "", "", "");
|
||||||
if(URL['fragment'] && URL['fragment'] !== '') {
|
if(URL['fragment'] && URL['fragment'] !== '') {
|
||||||
|
|
|
@ -54,13 +54,19 @@ export class UserManagementService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseUserInfo(info: any) {
|
private parseUserInfo(info: any) {
|
||||||
const user: User = new User();
|
const user: User = new User();
|
||||||
user.id = (info.sub && info.sub.indexOf('@')) ? info.sub.substring(0, info.sub.indexOf('@')) : info.sub;
|
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.firstname = (info.given_name) ? info.given_name : "";
|
||||||
user.lastname = (info.family_name) ? info.family_name : "";
|
user.lastname = (info.family_name) ? info.family_name : "";
|
||||||
user.email = info.email.toLowerCase(); // TODO remove, is a quick fix
|
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 : "";
|
user.fullname = (info.name) ? info.name : "";
|
||||||
if (user.fullname == "") {
|
if (user.fullname == "") {
|
||||||
if (user.firstname != "") {
|
if (user.firstname != "") {
|
||||||
|
|
|
@ -64,6 +64,7 @@ export interface EnvProperties {
|
||||||
registryUrl?: string;
|
registryUrl?: string;
|
||||||
logoutUrl?: string;
|
logoutUrl?: string;
|
||||||
userInfoUrl?: string;
|
userInfoUrl?: string;
|
||||||
|
clientManagementUrl?: string,
|
||||||
cookieDomain?: string;
|
cookieDomain?: string;
|
||||||
feedbackmail?: string;
|
feedbackmail?: string;
|
||||||
feedbackmailForMissingEntities?: string;
|
feedbackmailForMissingEntities?: string;
|
||||||
|
|
|
@ -266,6 +266,8 @@ export class StringUtils {
|
||||||
'[a-zA-Z0-9]+\\.[^\\s]{2,}';
|
'[a-zA-Z0-9]+\\.[^\\s]{2,}';
|
||||||
|
|
||||||
public static routeRegex = '^[a-zA-Z0-9\/][a-zA-Z0-9\/-]*$';
|
public static routeRegex = '^[a-zA-Z0-9\/][a-zA-Z0-9\/-]*$';
|
||||||
|
|
||||||
|
public static jsonRegex = /^[\],:{}\s]*$/;
|
||||||
|
|
||||||
public static urlPrefix(url: string): string {
|
public static urlPrefix(url: string): string {
|
||||||
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//")) {
|
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//")) {
|
||||||
|
@ -325,6 +327,19 @@ export class StringUtils {
|
||||||
public static urlValidator(): ValidatorFn {
|
public static urlValidator(): ValidatorFn {
|
||||||
return Validators.pattern(StringUtils.urlRegex);
|
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 {
|
public static validatorType(options: string[]): ValidatorFn {
|
||||||
return (control: AbstractControl): { [key: string]: boolean } | null => {
|
return (control: AbstractControl): { [key: string]: boolean } | null => {
|
||||||
|
|
Loading…
Reference in New Issue