Skip to content

Commit

Permalink
Merge branch 'devel' into dbeaver/pro#3393-udbt-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rider authored Oct 16, 2024
2 parents c3089c6 + f677f48 commit 62da6ba
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public List<WebNavigatorNodeInfo> getNavigatorNodeChildren(
return result.subList(offset, result.size());
}
} catch (DBException e) {
throw new DBWebException(e);
throw new DBWebException(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ type UserInfo {
configurationParameters: Object!
# User teams
teams: [UserTeamInfo!]!

@since(version: "24.2.3")
isAnonymous: Boolean!
}

type UserTeamInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public List<WebUserAuthToken> getAuthTokens() {

@Property
public List<String> getLinkedAuthProviders() throws DBWebException {
if (isAnonymous()) {
return List.of();
}
if (linkedProviders == null) {
try {
linkedProviders = session.getSecurityController().getCurrentUserLinkedProviders();
Expand Down Expand Up @@ -104,4 +107,9 @@ public List<WebUserTeamInfo> getTeams() throws DBWebException {
return List.of();
}
}

@Property
public boolean isAnonymous() {
return session.getUser() == null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.cloudbeaver.auth.SMSignOutLinkProvider;
import io.cloudbeaver.auth.provider.local.LocalAuthProvider;
import io.cloudbeaver.model.WebPropertyInfo;
import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.session.WebAuthInfo;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.model.session.WebSessionAuthProcessor;
Expand Down Expand Up @@ -189,7 +190,12 @@ public WebLogoutInfo authLogout(
@Override
public WebUserInfo activeUser(@NotNull WebSession webSession) throws DBWebException {
if (webSession.getUser() == null) {
return null;
WebAppConfiguration appConfiguration = webSession.getApplication().getAppConfiguration();
if (!appConfiguration.isAnonymousAccessEnabled()) {
return null;
}
SMUser anonymous = new SMUser("anonymous", true, null);
return new WebUserInfo(webSession, new WebUser(anonymous));
}
try {
// Read user from security controller. It will also read meta parameters
Expand Down
8 changes: 3 additions & 5 deletions webapp/packages/core-authentication/src/AppAuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import { UserInfoResource } from './UserInfoResource.js';
@injectable()
export class AppAuthService extends Bootstrap {
get authenticated(): boolean {
const user = this.userInfoResource.data;

return this.serverConfigResource.anonymousAccessEnabled || this.serverConfigResource.configurationMode || user !== null;
return this.serverConfigResource.configurationMode || this.userInfoResource.hasAccess();
}

get loaders(): ILoadableState[] {
Expand Down Expand Up @@ -56,9 +54,9 @@ export class AppAuthService extends Bootstrap {
throw new Error("Can't configure Authentication");
}

const user = await this.userInfoResource.load();
await this.userInfoResource.load();

return !this.serverConfigResource.configurationMode && !this.serverConfigResource.anonymousAccessEnabled && user === null;
return !this.serverConfigResource.configurationMode && !this.userInfoResource.hasAccess();
}

async authUser(): Promise<boolean> {
Expand Down
4 changes: 0 additions & 4 deletions webapp/packages/core-authentication/src/AuthInfoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ export class AuthInfoService {
return this.userInfoResource.data;
}

get isAnonymous(): boolean {
return !this.userInfoResource.data;
}

constructor(
private readonly userInfoResource: UserInfoResource,
private readonly authProvidersResource: AuthProvidersResource,
Expand Down
12 changes: 12 additions & 0 deletions webapp/packages/core-authentication/src/UserInfoResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,
});
}

isAnonymous(): this is { data: UserInfo } {
return this.data?.isAnonymous === true;
}

isAuthenticated(): this is { data: UserInfo } {
return !!this.data && !this.isAnonymous();
}

hasAccess(): this is { data: UserInfo } {
return this.isAnonymous() || this.isAuthenticated();
}

isLinked(provideId: string): boolean {
return this.data?.linkedAuthProviders.includes(provideId) || false;
}
Expand Down
4 changes: 1 addition & 3 deletions webapp/packages/core-projects/src/ProjectsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { computed, makeObservable } from 'mobx';

import { ANONYMOUS_USER_ID, UserDataService, UserInfoResource } from '@cloudbeaver/core-authentication';
import { UserDataService, UserInfoResource } from '@cloudbeaver/core-authentication';
import { Dependency, injectable } from '@cloudbeaver/core-di';
import { Executor, ExecutorInterrupter, type IExecutor, type ISyncExecutor, SyncExecutor } from '@cloudbeaver/core-executor';
import { CachedMapAllKey, resourceKeyList, ResourceKeyUtils } from '@cloudbeaver/core-resource';
Expand Down Expand Up @@ -35,8 +35,6 @@ export class ProjectsService extends Dependency {

if (this.userInfoResource.data) {
project = this.projectInfoResource.getUserProject(this.userInfoResource.data.userId);
} else {
project = this.projectInfoResource.get(ANONYMOUS_USER_ID);
}

return project;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
query getActiveUser($includeConfigurationParameters: Boolean!) {
user: activeUser {
userId
isAnonymous
displayName
authRole
linkedAuthProviders
Expand Down
6 changes: 3 additions & 3 deletions webapp/packages/core-settings-user/src/UserSettingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class UserSettingsService extends SettingsSource {
}

async save() {
if (this.userInfoResource.data) {
if (this.userInfoResource.isAuthenticated()) {
await this.userInfoResource.updatePreferences(Object.fromEntries(this.changes));
} else {
this.update(() => {
Expand Down Expand Up @@ -94,7 +94,7 @@ export class UserSettingsService extends SettingsSource {

private refreshConfig() {
this.update(() => {
if (!this.userInfoResource.data) {
if (!this.userInfoResource.isAuthenticated()) {
this.clear();
this.lastConfig = null;
return;
Expand All @@ -121,7 +121,7 @@ export class UserSettingsService extends SettingsSource {
}

private getSource() {
if (this.userInfoResource.data) {
if (this.userInfoResource.isAuthenticated()) {
return this.settings;
}

Expand Down
4 changes: 3 additions & 1 deletion webapp/packages/core-theming/src/styles/_form-controls.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@
box-shadow: 0 0 0 50px $input-background-readonly inset;
}
}
&:not([data-select='true'])[disabled] {

&[disabled] {
@include mdc-theme-prop(color, input-color-readonly, false);
@include mdc-theme-prop(border-color, input-border-readonly, false);
@include mdc-theme-prop(background-color, input-background-readonly, false);
pointer-events: all;
opacity: 1;
&:-internal-autofill-selected,
&:-internal-autofill-previewed {
box-shadow: 0 0 0 50px $input-background-readonly inset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class AuthenticationService extends Bootstrap {
this.onLogin = new Executor();

this.onLogout.before(this.navigationService.navigationTask);
this.onLogin.before(this.navigationService.navigationTask, undefined, () => authInfoService.isAnonymous);
this.onLogin.before(this.navigationService.navigationTask, undefined, () => userInfoResource.isAnonymous());

this.authPromise = null;
this.configureAuthProvider = null;
Expand Down
8 changes: 4 additions & 4 deletions webapp/packages/plugin-authentication/src/PluginBootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { AuthInfoService } from '@cloudbeaver/core-authentication';
import { UserInfoResource } from '@cloudbeaver/core-authentication';
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { ServerConfigResource } from '@cloudbeaver/core-root';
import { MenuBaseItem, MenuService } from '@cloudbeaver/core-view';
Expand All @@ -18,7 +18,7 @@ export class PluginBootstrap extends Bootstrap {
constructor(
private readonly serverConfigResource: ServerConfigResource,
private readonly authenticationService: AuthenticationService,
private readonly authInfoService: AuthInfoService,
private readonly userInfoResource: UserInfoResource,
private readonly menuService: MenuService,
) {
super();
Expand All @@ -28,7 +28,7 @@ export class PluginBootstrap extends Bootstrap {
this.menuService.addCreator({
menus: [TOP_NAV_BAR_SETTINGS_MENU],
getItems: (context, items) => {
if (this.serverConfigResource.enabledAuthProviders.length > 0 && !this.authInfoService.userInfo) {
if (this.serverConfigResource.enabledAuthProviders.length > 0 && this.userInfoResource.isAnonymous()) {
return [
...items,
new MenuBaseItem(
Expand All @@ -42,7 +42,7 @@ export class PluginBootstrap extends Bootstrap {
];
}

if (this.authInfoService.userInfo) {
if (this.userInfoResource.isAuthenticated()) {
return [
...items,
new MenuBaseItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { AuthInfoService, AuthProviderService } from '@cloudbeaver/core-authentication';
import { AuthProviderService, UserInfoResource } from '@cloudbeaver/core-authentication';
import { importLazyComponent } from '@cloudbeaver/core-blocks';
import {
type Connection,
Expand All @@ -28,7 +28,7 @@ export class ConnectionAuthService extends Dependency {
private readonly connectionInfoResource: ConnectionInfoResource,
private readonly commonDialogService: CommonDialogService,
private readonly authProviderService: AuthProviderService,
private readonly authInfoService: AuthInfoService,
private readonly userInfoResource: UserInfoResource,
private readonly connectionsManagerService: ConnectionsManagerService,
private readonly authenticationService: AuthenticationService,
) {
Expand All @@ -41,7 +41,7 @@ export class ConnectionAuthService extends Dependency {
connections: connectionInfoResource.values.filter(connection => connection.connected).map(createConnectionParam),
state,
}),
state => state === 'before' && authInfoService.isAnonymous,
state => state === 'before' && userInfoResource.isAnonymous(),
);
this.authenticationService.onLogout.before(
connectionsManagerService.onDisconnect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class ConnectionFoldersBootstrap extends Bootstrap {
isActionApplicable: (context, action) => {
const tree = context.get(DATA_CONTEXT_ELEMENTS_TREE)!;

if (action !== ACTION_NEW_FOLDER || !this.userInfoResource.data || tree.baseRoot !== ROOT_NODE_PATH) {
if (action !== ACTION_NEW_FOLDER || !this.userInfoResource.isAuthenticated() || tree.baseRoot !== ROOT_NODE_PATH) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ export class PublicConnectionFormService {
executorHandlerFilter(
() => !!this.formState && this.optionsPanelService.isOpen(formGetter),
async (event, context) => {
if (event === 'before' && this.userInfoResource.data === null) {
if (event === 'before' && this.userInfoResource.isAnonymous()) {
const confirmed = await this.showUnsavedChangesDialog();

if (!confirmed) {
ExecutorInterrupter.interrupt(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class ResourceFoldersBootstrap extends Bootstrap {
isActionApplicable: context => {
const tree = context.get(DATA_CONTEXT_ELEMENTS_TREE);

if (!tree?.baseRoot.startsWith(RESOURCES_NODE_PATH) || !this.userInfoResource.data) {
if (!tree?.baseRoot.startsWith(RESOURCES_NODE_PATH) || !this.userInfoResource.isAuthenticated()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
*/
import { computed, makeObservable } from 'mobx';

import { AuthInfoService } from '@cloudbeaver/core-authentication';
import { UserInfoResource } from '@cloudbeaver/core-authentication';
import { injectable } from '@cloudbeaver/core-di';
import type { ProjectInfo } from '@cloudbeaver/core-projects';
import { ServerConfigResource } from '@cloudbeaver/core-root';

@injectable()
export class ResourceManagerService {
get enabled() {
return !!this.serverConfigResource.data?.resourceManagerEnabled && !!this.authInfoService.userInfo;
return !!this.serverConfigResource.data?.resourceManagerEnabled && this.userInfoResource.isAuthenticated();
}

constructor(
private readonly authInfoService: AuthInfoService,
private readonly userInfoResource: UserInfoResource,
private readonly serverConfigResource: ServerConfigResource,
) {
makeObservable(this, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SessionExpireWarningDialogBootstrap extends Bootstrap {
}

private handleSessionResourceDataUpdate(isValid?: boolean, remainingTime?: number) {
if (!this.serverConfigResource.anonymousAccessEnabled && !this.userInfoResource.data && !this.serverConfigResource.configurationMode) {
if (!this.serverConfigResource.configurationMode && !this.userInfoResource.hasAccess()) {
return;
}

Expand Down
11 changes: 5 additions & 6 deletions webapp/packages/plugin-user-profile/src/UserMenu/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { observer } from 'mobx-react-lite';

import { AuthInfoService, DATA_CONTEXT_USER } from '@cloudbeaver/core-authentication';
import { DATA_CONTEXT_USER, UserInfoResource } from '@cloudbeaver/core-authentication';
import { Icon, Loader, s, useS } from '@cloudbeaver/core-blocks';
import { useDataContextLink } from '@cloudbeaver/core-data-context';
import { useService } from '@cloudbeaver/core-di';
Expand All @@ -20,21 +20,20 @@ import style from './UserMenu.module.css';

export const UserMenu = observer(function UserMenu() {
const styles = useS(style);
const authInfoService = useService(AuthInfoService);
const userInfoResource = useService(UserInfoResource);
const menu = useMenu({ menu: MENU_USER_PROFILE });
const userInfo = authInfoService.userInfo;

useDataContextLink(menu.context, (context, id) => {
context.set(DATA_CONTEXT_USER, userInfo, id);
context.set(DATA_CONTEXT_USER, userInfoResource.data, id);
});

if (!userInfo) {
if (!userInfoResource.isAuthenticated()) {
return null;
}

return (
<Loader suspense inline>
<UserInfo info={userInfo} />
<UserInfo info={userInfoResource.data} />
<ContextMenu className={s(styles, { contextMenu: true })} menu={menu} modal>
<Icon className={s(styles, { icon: true })} name="angle" viewBox="0 0 15 8" />
</ContextMenu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { AuthInfoService } from '@cloudbeaver/core-authentication';
import { UserInfoResource } from '@cloudbeaver/core-authentication';
import { importLazyComponent } from '@cloudbeaver/core-blocks';
import { Bootstrap, injectable } from '@cloudbeaver/core-di';

Expand All @@ -17,7 +17,7 @@ const UserProfileFormPanel = importLazyComponent(() => import('./UserProfileForm
export class UserProfileFormBootstrap extends Bootstrap {
constructor(
private readonly userProfileTabsService: UserProfileTabsService,
private readonly authInfoService: AuthInfoService,
private readonly userInfoResource: UserInfoResource,
) {
super();
}
Expand All @@ -27,7 +27,7 @@ export class UserProfileFormBootstrap extends Bootstrap {
key: 'account',
name: 'plugin_user_profile_account_title',
order: 1,
isHidden: () => this.authInfoService.isAnonymous,
isHidden: () => this.userInfoResource.isAnonymous(),
panel: () => UserProfileFormPanel,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class UserProfileOptionsPanelService {
return;
}

if (this.userInfoResource.data === null) {
if (!this.userInfoResource.hasAccess()) {
this.close(true);
}
}
Expand Down

0 comments on commit 62da6ba

Please sign in to comment.