return url fix
This commit is contained in:
parent
4a29e19351
commit
7ede13d0e4
|
@ -3,6 +3,7 @@ import { RouterModule, Routes } from '@angular/router';
|
||||||
import { AppPermission } from './core/common/enum/permission.enum';
|
import { AppPermission } from './core/common/enum/permission.enum';
|
||||||
import { BreadcrumbService } from './ui/misc/breadcrumb/breadcrumb.service';
|
import { BreadcrumbService } from './ui/misc/breadcrumb/breadcrumb.service';
|
||||||
import { ReloadHelperComponent } from './ui/misc/reload-helper/reload-helper.component';
|
import { ReloadHelperComponent } from './ui/misc/reload-helper/reload-helper.component';
|
||||||
|
import { AuthGuard } from './core/auth-guard.service';
|
||||||
|
|
||||||
const appRoutes: Routes = [
|
const appRoutes: Routes = [
|
||||||
{
|
{
|
||||||
|
@ -418,6 +419,7 @@ const appRoutes: Routes = [
|
||||||
const tenantEnrichedRoutes: Routes = [
|
const tenantEnrichedRoutes: Routes = [
|
||||||
{
|
{
|
||||||
path: 't/:tenant_code',
|
path: 't/:tenant_code',
|
||||||
|
canActivate: [AuthGuard],
|
||||||
data: {
|
data: {
|
||||||
breadcrumb: true,
|
breadcrumb: true,
|
||||||
...BreadcrumbService.generateRouteDataConfiguration({
|
...BreadcrumbService.generateRouteDataConfiguration({
|
||||||
|
|
|
@ -44,6 +44,7 @@ import { GuidedTourModule } from './library/guided-tour/guided-tour.module';
|
||||||
import { DepositOauth2DialogModule } from './ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.module';
|
import { DepositOauth2DialogModule } from './ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.module';
|
||||||
import { OpenCDMPCustomTranslationCompiler } from './utilities/translate/opencdmp-custom-translation-compiler';
|
import { OpenCDMPCustomTranslationCompiler } from './utilities/translate/opencdmp-custom-translation-compiler';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
import { RouterUtilsService } from './core/services/router/router-utils.service';
|
||||||
|
|
||||||
// AoT requires an exported function for factories
|
// AoT requires an exported function for factories
|
||||||
export function HttpLoaderFactory(languageHttpService: LanguageHttpService) {
|
export function HttpLoaderFactory(languageHttpService: LanguageHttpService) {
|
||||||
|
@ -80,7 +81,7 @@ const cookieConfig: NgcCookieConsentConfig = {
|
||||||
type: 'info'
|
type: 'info'
|
||||||
};
|
};
|
||||||
|
|
||||||
export function InstallationConfigurationFactory(appConfig: ConfigurationService, keycloak: KeycloakService, authService: AuthService, languageService: LanguageService, tenantHandlingService: TenantHandlingService, router: Router) {
|
export function InstallationConfigurationFactory(appConfig: ConfigurationService, keycloak: KeycloakService, authService: AuthService, languageService: LanguageService, tenantHandlingService: TenantHandlingService, router: Router, routerUtils: RouterUtilsService) {
|
||||||
return () => appConfig.loadConfiguration().then(() => {
|
return () => appConfig.loadConfiguration().then(() => {
|
||||||
return languageService.loadAvailableLanguages().toPromise();
|
return languageService.loadAvailableLanguages().toPromise();
|
||||||
}).then(x => keycloak.init({
|
}).then(x => keycloak.init({
|
||||||
|
@ -110,11 +111,13 @@ export function InstallationConfigurationFactory(appConfig: ConfigurationService
|
||||||
|
|
||||||
const tenantCode = tenantHandlingService.extractTenantCodeFromUrlPath(window.location.pathname) ?? authService.selectedTenant() ?? 'default';
|
const tenantCode = tenantHandlingService.extractTenantCodeFromUrlPath(window.location.pathname) ?? authService.selectedTenant() ?? 'default';
|
||||||
const tokenPromise = keycloak.getToken();
|
const tokenPromise = keycloak.getToken();
|
||||||
return authService.prepareAuthRequest(from(tokenPromise), tenantCode, { params })
|
|
||||||
|
return authService.prepareAuthRequest(from(tokenPromise), tenantCode, { params }, true)
|
||||||
.toPromise()
|
.toPromise()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (authService.selectedTenant() != tenantCode) {
|
if (authService.selectedTenant() != null && authService.selectedTenant() != tenantCode) {
|
||||||
router.navigate(['/']);
|
let trimedPath = tenantHandlingService.trimUrlPathFormTenantCode(window.location.pathname);
|
||||||
|
router.navigate([routerUtils.generateUrl(trimedPath)]);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => authService.onAuthenticateError(error));
|
.catch(error => authService.onAuthenticateError(error));
|
||||||
|
@ -165,7 +168,7 @@ export function InstallationConfigurationFactory(appConfig: ConfigurationService
|
||||||
{
|
{
|
||||||
provide: APP_INITIALIZER,
|
provide: APP_INITIALIZER,
|
||||||
useFactory: InstallationConfigurationFactory,
|
useFactory: InstallationConfigurationFactory,
|
||||||
deps: [ConfigurationService, KeycloakService, AuthService, LanguageService, TenantHandlingService, Router],
|
deps: [ConfigurationService, KeycloakService, AuthService, LanguageService, TenantHandlingService, Router, RouterUtilsService],
|
||||||
multi: true
|
multi: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -167,7 +167,12 @@ export class AuthService extends BaseService {
|
||||||
public isLoggedIn(): boolean {
|
public isLoggedIn(): boolean {
|
||||||
return this.authState();
|
return this.authState();
|
||||||
}
|
}
|
||||||
public prepareAuthRequest(observable: Observable<string>, tenantCode: string, httpParams?: Object): Observable<boolean> {
|
public prepareAuthRequest(observable: Observable<string>, tenantCode: string, httpParams?: Object, ignoreUnauth: boolean = false): Observable<boolean> {
|
||||||
|
if (ignoreUnauth) {
|
||||||
|
if (this.keycloakService.isLoggedIn() == false) return of(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return observable.pipe(
|
return observable.pipe(
|
||||||
map((x) => this.currentAuthenticationToken(x)),
|
map((x) => this.currentAuthenticationToken(x)),
|
||||||
concatMap(response => {
|
concatMap(response => {
|
||||||
|
@ -186,6 +191,7 @@ export class AuthService extends BaseService {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public refresh(): Observable<boolean> {
|
public refresh(): Observable<boolean> {
|
||||||
return this.principalService.me().pipe(
|
return this.principalService.me().pipe(
|
||||||
map((item) => {
|
map((item) => {
|
||||||
|
|
|
@ -32,6 +32,17 @@ export class TenantHandlingService extends BaseService {
|
||||||
return tenantCode;
|
return tenantCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trimUrlPathFormTenantCode(path: string): string {
|
||||||
|
const tenantCode = this.extractTenantCodeFromUrlPath(path);
|
||||||
|
|
||||||
|
if (tenantCode == null || tenantCode == '') return path;
|
||||||
|
|
||||||
|
const tenantPart = '/t/'+tenantCode;
|
||||||
|
|
||||||
|
return path.substring(tenantPart.length, path.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
getCurrentUrlEnrichedWithTenantCode(tenantCode: string, withOrigin: boolean) {
|
getCurrentUrlEnrichedWithTenantCode(tenantCode: string, withOrigin: boolean) {
|
||||||
const path = this.getUrlEnrichedWithTenantCode(this.router.routerState.snapshot.url, tenantCode)
|
const path = this.getUrlEnrichedWithTenantCode(this.router.routerState.snapshot.url, tenantCode)
|
||||||
return withOrigin ? this.getBaseUrl() + path.toString().substring(1) : path;
|
return withOrigin ? this.getBaseUrl() + path.toString().substring(1) : path;
|
||||||
|
|
|
@ -41,9 +41,8 @@ export class LoginComponent extends BaseComponent implements OnInit {
|
||||||
() => {
|
() => {
|
||||||
let returnUrL = this.returnUrl;
|
let returnUrL = this.returnUrl;
|
||||||
|
|
||||||
if (this.authService.selectedTenant() != tenantCode) returnUrL = this.routerUtils.generateUrl('/');
|
window.location.href = returnUrL;
|
||||||
|
// this.zone.run(() => this.router.navigateByUrl(returnUrL));
|
||||||
this.zone.run(() => this.router.navigateByUrl(this.routerUtils.generateUrl(returnUrL)));
|
|
||||||
},
|
},
|
||||||
(error) => this.authService.authenticate('/'));
|
(error) => this.authService.authenticate('/'));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue