Skip to content

Commit

Permalink
Remove usage of IsAuthenticatedRequest and LoginResult #2216
Browse files Browse the repository at this point in the history
  • Loading branch information
ashklianko committed Jan 21, 2025
1 parent a7124b8 commit 8b40a42
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Project settings
#
version=7.16.0-SNAPSHOT
libAdminUiVersion=5.0.0-SNAPSHOT
libAdminUiVersion=5.1.0-SNAPSHOT-AUTH

systemProp.org.gradle.internal.http.connectionTimeout=120000
systemProp.org.gradle.internal.http.socketTimeout=120000
5 changes: 5 additions & 0 deletions src/main/resources/admin/tools/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ const mustache = require('/lib/mustache');
const portal = require('/lib/xp/portal');
const i18n = require('/lib/xp/i18n');
const assetLib = require('/lib/enonic/asset');
const authLib = require('/lib/xp/auth');

function getConfigAsJson() {
const user = authLib.getUser();

return JSON.stringify({
adminUrl: admin.getBaseUri(),
appId: app.name,
Expand Down Expand Up @@ -42,6 +45,8 @@ function getConfigAsJson() {
theme: 'dark',
}
}),
user,
principals: authLib.getMemberships(user.key, true)
}, null, 4).replace(/<(\/?script|!--)/gi, "\\u003C$1");
}

Expand Down
13 changes: 3 additions & 10 deletions src/main/resources/assets/js/app/create/UserItemTypesTreeGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import {Group, GroupBuilder} from '../principal/Group';
import {Role, RoleBuilder} from '../principal/Role';
import {PrincipalKey} from '@enonic/lib-admin-ui/security/PrincipalKey';
import {PrincipalType} from '@enonic/lib-admin-ui/security/PrincipalType';
import {IsAuthenticatedRequest} from '@enonic/lib-admin-ui/security/auth/IsAuthenticatedRequest';
import {IdProviderKey} from '@enonic/lib-admin-ui/security/IdProviderKey';
import {i18n} from '@enonic/lib-admin-ui/util/Messages';
import {DefaultErrorHandler} from '@enonic/lib-admin-ui/DefaultErrorHandler';
import {LoginResult} from '@enonic/lib-admin-ui/security/auth/LoginResult';
import {UserItem} from '@enonic/lib-admin-ui/security/UserItem';
import {TreeListBox, TreeListBoxParams, TreeListElement, TreeListElementParams} from '@enonic/lib-admin-ui/ui/selector/list/TreeListBox';
import {UserTypesTreeGridItemViewer} from './UserTypesTreeGridItemViewer';
import {AuthHelper} from '@enonic/lib-admin-ui/auth/AuthHelper';

export class UserItemTypesTreeGrid
extends TreeListBox<UserTypeTreeGridItem> {
Expand Down Expand Up @@ -76,13 +75,7 @@ export class UserItemTypesTreeGrid
}

private fetchRoot(): Q.Promise<UserTypeTreeGridItem[]> {
return Q.all([new IsAuthenticatedRequest().sendAndParse(), this.fetchIdProviders()]).then(
(result: [LoginResult, IdProvider[]]) => result[0].isUserAdmin(),
reason => {
DefaultErrorHandler.handle(reason);
return false;
}
).then(userIsAdmin => [
return this.fetchIdProviders().then(() => [
new UserTypeTreeGridItemBuilder()
.setUserItem(new UserBuilder()
.setKey(new PrincipalKey(IdProviderKey.SYSTEM, PrincipalType.USER, 'user'))
Expand All @@ -93,7 +86,7 @@ export class UserItemTypesTreeGrid
.setKey(new PrincipalKey(IdProviderKey.SYSTEM, PrincipalType.GROUP, 'user-group'))
.setDisplayName(i18n('field.userGroup'))
.build()).build(),
...((this.presetIdProvider || !userIsAdmin) ? [] : [
...((this.presetIdProvider || !AuthHelper.isUserAdmin()) ? [] : [
new UserTypeTreeGridItemBuilder()
.setUserItem(new IdProviderBuilder()
.setKey(IdProviderKey.SYSTEM.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import {Principal} from '@enonic/lib-admin-ui/security/Principal';
import {PrincipalType} from '@enonic/lib-admin-ui/security/PrincipalType';
import {PrincipalKey} from '@enonic/lib-admin-ui/security/PrincipalKey';
import {PrincipalViewer} from '@enonic/lib-admin-ui/ui/security/PrincipalViewer';
import {RoleKeys} from '@enonic/lib-admin-ui/security/RoleKeys';
import {DivEl} from '@enonic/lib-admin-ui/dom/DivEl';
import {Path} from '@enonic/lib-admin-ui/rest/Path';
import {IsAuthenticatedRequest} from '@enonic/lib-admin-ui/security/auth/IsAuthenticatedRequest';
import {AppHelper} from '@enonic/lib-admin-ui/util/AppHelper';
import {i18n} from '@enonic/lib-admin-ui/util/Messages';
import {DefaultErrorHandler} from '@enonic/lib-admin-ui/DefaultErrorHandler';
Expand All @@ -25,10 +23,10 @@ import {CheckboxBuilder} from '@enonic/lib-admin-ui/ui/Checkbox';
import {Element} from '@enonic/lib-admin-ui/dom/Element';
import {Button} from '@enonic/lib-admin-ui/ui/button/Button';
import {UserItemStatisticsHeader} from './UserItemStatisticsHeader';
import {LoginResult} from '@enonic/lib-admin-ui/security/auth/LoginResult';
import {CONFIG} from '@enonic/lib-admin-ui/util/Config';
import {MembersListing} from './MembersListing';
import {SelectionChange} from '@enonic/lib-admin-ui/util/SelectionChange';
import {AuthHelper} from '@enonic/lib-admin-ui/auth/AuthHelper';

export class UserItemStatisticsPanel
extends ItemStatisticsPanel {
Expand Down Expand Up @@ -198,9 +196,7 @@ export class UserItemStatisticsPanel
}

private async createReportGroup(principal: Principal): Promise<ItemDataGroup | null> {
const isAdmin = await new IsAuthenticatedRequest().sendAndParse().then((loginResult: LoginResult) => {
return loginResult.getPrincipals().some(key => key.equals(RoleKeys.ADMIN));
});
const isAdmin = AuthHelper.isAdmin();

if(!isAdmin) { return Q(null); }

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/assets/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {InputTypeManager} from '@enonic/lib-admin-ui/form/inputtype/InputTypeMan
import {Class} from '@enonic/lib-admin-ui/Class';
import {JSONObject} from '@enonic/lib-admin-ui/types';
import {LauncherHelper} from '@enonic/lib-admin-ui/util/LauncherHelper';
import {AuthContext} from '@enonic/lib-admin-ui/auth/AuthContext';
import {Principal} from '@enonic/lib-admin-ui/security/Principal';
import {PrincipalJson} from '@enonic/lib-admin-ui/security/PrincipalJson';

const body = Body.get();

Expand Down Expand Up @@ -92,6 +95,8 @@ function startApplication() {

const configScriptEl: HTMLElement = document.getElementById(configScriptId);
CONFIG.setConfig(JSON.parse(configScriptEl.innerText) as JSONObject);
AuthContext.init(Principal.fromJson(CONFIG.get('user') as PrincipalJson),
(CONFIG.get('principals') as PrincipalJson[]).map(Principal.fromJson));

await i18nInit(CONFIG.getString('apis.i18nUrl'));
startApplication();
Expand Down

0 comments on commit 8b40a42

Please sign in to comment.