fix refresh token fail

This commit is contained in:
Efstratios Giannopoulos 2024-05-16 13:54:01 +03:00
parent 9441f0f326
commit 36a8936a95
3 changed files with 19 additions and 14 deletions

View File

@ -235,20 +235,11 @@ public class UserQuery extends QueryBase<UserEntity> {
if (this.userScope.isSet()) userId = this.userScope.getUserIdSafe(); if (this.userScope.isSet()) userId = this.userScope.getUserIdSafe();
else throw new MyNotFoundException("Only user scoped allowed"); else throw new MyNotFoundException("Only user scoped allowed");
Subquery<UUID> dmpUserDmpQuery = this.queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
new BuildSubQueryInput.Builder<>(DmpUserEntity.class, UUID.class, queryContext)
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpUserEntity._dmpId))
.filterFunc((subQueryRoot, cb) -> cb.and(
cb.equal(subQueryRoot.get(DmpUserEntity._userId), userId),
cb.equal(subQueryRoot.get(DmpUserEntity._isActive), IsActive.Active)
))
));
Subquery<UUID> dmpUserUserQuery = this.queryUtilsService.buildSubQuery(new BuildSubQueryInput<>( Subquery<UUID> dmpUserUserQuery = this.queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
new BuildSubQueryInput.Builder<>(DmpUserEntity.class, UUID.class, queryContext) new BuildSubQueryInput.Builder<>(DmpUserEntity.class, UUID.class, queryContext)
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpUserEntity._userId)) .keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpUserEntity._userId))
.filterFunc((subQueryRoot, cb) -> cb.and( .filterFunc((subQueryRoot, cb) -> cb.and(
cb.in(subQueryRoot.get(DmpUserEntity._dmpId)).value(dmpUserDmpQuery) , cb.in(subQueryRoot.get(DmpUserEntity._dmpId)).value(this.queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, false)) ,
cb.equal(subQueryRoot.get(DmpUserEntity._isActive), IsActive.Active) cb.equal(subQueryRoot.get(DmpUserEntity._isActive), IsActive.Active)
)) ))
)); ));

View File

@ -262,7 +262,16 @@ export class AuthService extends BaseService {
if ( if (
e.type === KeycloakEventType.OnTokenExpired e.type === KeycloakEventType.OnTokenExpired
) { ) {
this.refreshToken({}); this.refreshToken({}).then((isRefreshed) => {
if (!isRefreshed) {
this.clear();
}
return isRefreshed;
}).catch(x => {
this.clear();
throw x;
});
} }
}, },
}); });
@ -275,7 +284,7 @@ export class AuthService extends BaseService {
} }
public refreshToken(httpParams?: Object): Promise<boolean> { public refreshToken(httpParams?: Object): Promise<boolean> {
return this.keycloakService.updateToken(60).then((isRefreshed) => { return this.keycloakService.updateToken().then((isRefreshed) => {
if (!isRefreshed) { if (!isRefreshed) {
return false; return false;
} }

View File

@ -48,6 +48,9 @@ export class UnauthorizedResponseInterceptor extends BaseInterceptor {
} }
return true; return true;
}).catch(x => {
this.logoutUser();
return false;
}) })
).pipe(filter((x) => x)); ).pipe(filter((x) => x));
} }
@ -65,8 +68,10 @@ export class UnauthorizedResponseInterceptor extends BaseInterceptor {
} }
private logoutUser() { private logoutUser() {
//this.authService.clear(); if (!this.isLoginRoute() && !this.isSignupRoute()) {
if (!this.isLoginRoute() && !this.isSignupRoute()) { this.router.navigate(['/unauthorized']); } this.authService.clear();
this.router.navigate(['/unauthorized']);
}
} }
private isLoginRoute(): boolean { private isLoginRoute(): boolean {