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())))) {
|
||||
status = EventProcessingStatus.Postponed;
|
||||
currentPrincipalResolver.pop();
|
||||
tenantScope.removeTempTenant(this.tenantEntityManager);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ import { Observable, Subject, forkJoin, from, of } from 'rxjs';
|
|||
import { exhaustMap, map, takeUntil } from 'rxjs/operators';
|
||||
import { ConfigurationService } from '../configuration/configuration.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 {
|
||||
roles: AppRole[];
|
||||
|
@ -156,10 +158,11 @@ export class AuthService extends BaseService {
|
|||
return observable.pipe(
|
||||
map((x) => this.currentAuthenticationToken(x)),
|
||||
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) => {
|
||||
this.currentAccount(item[0]);
|
||||
this.currentAccount(item[1]);
|
||||
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(
|
||||
appAccount: AppAccount
|
||||
): void {
|
||||
|
|
|
@ -36,38 +36,12 @@ export class LoginComponent extends BaseComponent implements OnInit {
|
|||
if (!this.keycloakService.isLoggedIn()) {
|
||||
this.authService.authenticate(this.returnUrl);
|
||||
} 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(
|
||||
() => {
|
||||
let returnUrL = this.returnUrl;
|
||||
this.zone.run(() => this.router.navigateByUrl(returnUrL));
|
||||
},
|
||||
(error) => this.authService.authenticate('/'));
|
||||
}, (error) => this.authService.authenticate('/')); //TODO HANDLE-ERRORS ?
|
||||
|
||||
|
||||
this.authService.prepareAuthRequest(from(this.keycloakService.getToken())).pipe(takeUntil(this._destroyed)).subscribe(
|
||||
() => {
|
||||
let returnUrL = this.returnUrl;
|
||||
this.zone.run(() => this.router.navigateByUrl(returnUrL));
|
||||
},
|
||||
(error) => this.authService.authenticate('/'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
|||
if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) {
|
||||
status = EventProcessingStatus.Postponed;
|
||||
currentPrincipalResolver.pop();
|
||||
tenantScope.removeTempTenant(this.tenantEntityManager);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue