mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-10-12 23:37:00 +08:00
CB-2625 reset user state on token expired error
This commit is contained in:
+5
-2
@@ -112,8 +112,11 @@ public class WebUserContext implements SMCredentialsProvider {
|
||||
* reset the state as if the user is not logged in
|
||||
*/
|
||||
public synchronized void reset() throws DBException {
|
||||
if (this.smCredentials != null) {
|
||||
this.securityController.logout();
|
||||
try {
|
||||
if (this.smCredentials != null) {
|
||||
this.securityController.logout();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
this.userPermissions = getDefaultPermissions();
|
||||
this.smCredentials = null;
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.jkiss.dbeaver.model.auth.SMCredentialsProvider;
|
||||
import org.jkiss.dbeaver.model.rm.RMConstants;
|
||||
import org.jkiss.dbeaver.model.rm.RMProject;
|
||||
import org.jkiss.dbeaver.model.rm.RMProjectPermission;
|
||||
import org.jkiss.dbeaver.model.security.exception.SMRefreshTokenExpiredException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
@@ -45,4 +46,18 @@ public class SMUtils {
|
||||
return permissionInfos;
|
||||
}
|
||||
|
||||
public static boolean isTokenExpiredExceptionWasHandled(Throwable ex) {
|
||||
if (ex instanceof SMRefreshTokenExpiredException) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Throwable cause = ex;
|
||||
while ((cause = cause.getCause()) != null) {
|
||||
if (cause instanceof SMRefreshTokenExpiredException) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
@@ -26,6 +26,7 @@ import io.cloudbeaver.model.session.WebSessionProvider;
|
||||
import io.cloudbeaver.server.CBApplication;
|
||||
import io.cloudbeaver.server.CBPlatform;
|
||||
import io.cloudbeaver.server.graphql.GraphQLEndpoint;
|
||||
import io.cloudbeaver.service.security.SMUtils;
|
||||
import org.jkiss.code.NotNull;
|
||||
import org.jkiss.dbeaver.DBException;
|
||||
import org.jkiss.dbeaver.Log;
|
||||
@@ -170,6 +171,17 @@ public abstract class WebServiceBindingBase<API_TYPE extends DBWService> impleme
|
||||
throw e.getTargetException();
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
if (SMUtils.isTokenExpiredExceptionWasHandled(ex)) {
|
||||
WebSession webSession = findWebSession(env);
|
||||
if (webSession != null) {
|
||||
webSession.resetUserState();
|
||||
}
|
||||
throw new DBWebException(
|
||||
"Authentication has expired",
|
||||
DBWebException.ERROR_CODE_SESSION_EXPIRED,
|
||||
ex
|
||||
);
|
||||
}
|
||||
for (Class<?> exType : method.getExceptionTypes()) {
|
||||
if (exType.isInstance(ex)) {
|
||||
throw ex;
|
||||
|
||||
+9
@@ -32,6 +32,7 @@ import io.cloudbeaver.server.CBApplication;
|
||||
import io.cloudbeaver.service.auth.DBWServiceAuth;
|
||||
import io.cloudbeaver.service.auth.WebAuthStatus;
|
||||
import io.cloudbeaver.service.auth.WebUserInfo;
|
||||
import io.cloudbeaver.service.security.SMUtils;
|
||||
import org.jkiss.code.NotNull;
|
||||
import org.jkiss.code.Nullable;
|
||||
import org.jkiss.dbeaver.DBException;
|
||||
@@ -157,6 +158,14 @@ public class WebServiceAuthImpl implements DBWServiceAuth {
|
||||
return new WebUserInfo(webSession, webSession.getUser());
|
||||
}
|
||||
} catch (DBException e) {
|
||||
if (SMUtils.isTokenExpiredExceptionWasHandled(e)) {
|
||||
try {
|
||||
webSession.resetUserState();
|
||||
return null;
|
||||
} catch (DBException ex) {
|
||||
throw new DBWebException("Error reading user details", e);
|
||||
}
|
||||
}
|
||||
throw new DBWebException("Error reading user details", e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user