tenant login changes
This commit is contained in:
parent
f1d899ea0e
commit
ebdeeb6e7d
|
@ -80,7 +80,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
||||||
if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) {
|
if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) {
|
||||||
status = EventProcessingStatus.Postponed;
|
status = EventProcessingStatus.Postponed;
|
||||||
currentPrincipalResolver.pop();
|
currentPrincipalResolver.pop();
|
||||||
tenantScope.removeTempTenant(this.tenantEntityManager);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ import { Observable, Subject, forkJoin, from, of } from 'rxjs';
|
||||||
import { exhaustMap, map, takeUntil } from 'rxjs/operators';
|
import { exhaustMap, map, takeUntil } from 'rxjs/operators';
|
||||||
import { ConfigurationService } from '../configuration/configuration.service';
|
import { ConfigurationService } from '../configuration/configuration.service';
|
||||||
import { PrincipalService } from '../http/principal.service';
|
import { PrincipalService } from '../http/principal.service';
|
||||||
|
import { BaseHttpParams } from '@common/http/base-http-params';
|
||||||
|
import { InterceptorType } from '@common/http/interceptors/interceptor-type';
|
||||||
|
|
||||||
export interface ResolutionContext {
|
export interface ResolutionContext {
|
||||||
roles: AppRole[];
|
roles: AppRole[];
|
||||||
|
@ -156,10 +158,11 @@ export class AuthService extends BaseService {
|
||||||
return observable.pipe(
|
return observable.pipe(
|
||||||
map((x) => this.currentAuthenticationToken(x)),
|
map((x) => this.currentAuthenticationToken(x)),
|
||||||
exhaustMap(() => forkJoin([
|
exhaustMap(() => forkJoin([
|
||||||
this.accessToken ? this.principalService.me(httpParams) : of(null)
|
this.accessToken ? this.ensureTenant() : of(false),
|
||||||
|
this.accessToken ? this.principalService.me(httpParams) : of(null),
|
||||||
])),
|
])),
|
||||||
map((item) => {
|
map((item) => {
|
||||||
this.currentAccount(item[0]);
|
this.currentAccount(item[1]);
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -173,6 +176,38 @@ export class AuthService extends BaseService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ensureTenant(): Observable<string> {
|
||||||
|
if (!this.selectedTenant()) {
|
||||||
|
this.selectedTenant('default');
|
||||||
|
}
|
||||||
|
const params = new BaseHttpParams();
|
||||||
|
params.interceptorContext = {
|
||||||
|
excludedInterceptors: [InterceptorType.TenantHeaderInterceptor]
|
||||||
|
};
|
||||||
|
return this.principalService.myTenants({ params: params }).pipe(takeUntil(this._destroyed),
|
||||||
|
map(
|
||||||
|
(myTenants) => {
|
||||||
|
if (myTenants) {
|
||||||
|
if (this.selectedTenant()) {
|
||||||
|
if (myTenants.findIndex(x => x.code.toLocaleLowerCase() == this.selectedTenant().toLocaleLowerCase()) < 0) {
|
||||||
|
this.selectedTenant(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.selectedTenant()) {
|
||||||
|
if (myTenants.length > 0) {
|
||||||
|
this.selectedTenant(myTenants[0]?.code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.selectedTenant(null);
|
||||||
|
}
|
||||||
|
return this.selectedTenant();
|
||||||
|
}
|
||||||
|
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private currentAccount(
|
private currentAccount(
|
||||||
appAccount: AppAccount
|
appAccount: AppAccount
|
||||||
): void {
|
): void {
|
||||||
|
|
|
@ -36,38 +36,12 @@ export class LoginComponent extends BaseComponent implements OnInit {
|
||||||
if (!this.keycloakService.isLoggedIn()) {
|
if (!this.keycloakService.isLoggedIn()) {
|
||||||
this.authService.authenticate(this.returnUrl);
|
this.authService.authenticate(this.returnUrl);
|
||||||
} else {
|
} else {
|
||||||
if (!this.authService.selectedTenant()) {
|
|
||||||
this.authService.selectedTenant('default');
|
|
||||||
}
|
|
||||||
const params = new BaseHttpParams();
|
|
||||||
params.interceptorContext = {
|
|
||||||
excludedInterceptors: [InterceptorType.TenantHeaderInterceptor]
|
|
||||||
};
|
|
||||||
this.principalService.myTenants({ params: params }).subscribe(myTenants => {
|
|
||||||
if (myTenants) {
|
|
||||||
if (this.authService.selectedTenant()) {
|
|
||||||
if (myTenants.findIndex(x => x.code.toLocaleLowerCase() == this.authService.selectedTenant().toLocaleLowerCase()) < 0) {
|
|
||||||
this.authService.selectedTenant(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.authService.selectedTenant()) {
|
|
||||||
if (myTenants.length > 0) {
|
|
||||||
this.authService.selectedTenant(myTenants[0]?.code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.authService.selectedTenant(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.authService.prepareAuthRequest(from(this.keycloakService.getToken())).pipe(takeUntil(this._destroyed)).subscribe(
|
this.authService.prepareAuthRequest(from(this.keycloakService.getToken())).pipe(takeUntil(this._destroyed)).subscribe(
|
||||||
() => {
|
() => {
|
||||||
let returnUrL = this.returnUrl;
|
let returnUrL = this.returnUrl;
|
||||||
this.zone.run(() => this.router.navigateByUrl(returnUrL));
|
this.zone.run(() => this.router.navigateByUrl(returnUrL));
|
||||||
},
|
},
|
||||||
(error) => this.authService.authenticate('/'));
|
(error) => this.authService.authenticate('/'));
|
||||||
}, (error) => this.authService.authenticate('/')); //TODO HANDLE-ERRORS ?
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
||||||
if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) {
|
if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) {
|
||||||
status = EventProcessingStatus.Postponed;
|
status = EventProcessingStatus.Postponed;
|
||||||
currentPrincipalResolver.pop();
|
currentPrincipalResolver.pop();
|
||||||
tenantScope.removeTempTenant(this.tenantEntityManager);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue