Search in sources :

Example 1 with AdminToolDescriptor

use of com.enonic.xp.admin.tool.AdminToolDescriptor in project xp by enonic.

the class AdminToolHandlerWorker method execute.

@Override
public PortalResponse execute() throws Exception {
    // Retrieves the AdminToolDescriptor
    final AdminToolDescriptor adminToolDescriptor = adminToolDescriptorService.getByKey(descriptorKey);
    if (adminToolDescriptor == null) {
        throw WebException.notFound(String.format("Admin application [%s] not found", descriptorKey));
    }
    // Checks if the access to AdminToolDescriptor is allowed
    final PrincipalKeys principals = ContextAccessor.current().getAuthInfo().getPrincipals();
    if (!adminToolDescriptor.isAccessAllowed(principals)) {
        throw WebException.forbidden(String.format("You don't have permission to access [%s]", descriptorKey));
    }
    // Renders the Admin application
    final ResourceKey scriptDir = ResourceKey.from(descriptorKey.getApplicationKey(), "admin/tools/" + descriptorKey.getName());
    final ControllerScript controllerScript = this.controllerScriptFactory.fromDir(scriptDir);
    return controllerScript.execute(this.request);
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) AdminToolDescriptor(com.enonic.xp.admin.tool.AdminToolDescriptor) ResourceKey(com.enonic.xp.resource.ResourceKey)

Example 2 with AdminToolDescriptor

use of com.enonic.xp.admin.tool.AdminToolDescriptor in project xp by enonic.

the class AdminToolDescriptorServiceImplTest method getByApplication.

@Test
public void getByApplication() {
    final AdminToolDescriptors result = this.service.getByApplication(ApplicationKey.from("myapp1"));
    assertEquals(1, result.getSize());
    final AdminToolDescriptor adminToolDescriptor = result.get(0);
    assertEquals("My admin tool", adminToolDescriptor.getDisplayName());
    assertEquals("My admin tool description", adminToolDescriptor.getDescription());
    assertEquals(1, adminToolDescriptor.getAllowedPrincipals().getSize());
}
Also used : AdminToolDescriptors(com.enonic.xp.admin.tool.AdminToolDescriptors) AdminToolDescriptor(com.enonic.xp.admin.tool.AdminToolDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with AdminToolDescriptor

use of com.enonic.xp.admin.tool.AdminToolDescriptor in project xp by enonic.

the class AdminToolDescriptorServiceImplTest method getByKey.

@Test
public void getByKey() {
    final DescriptorKey descriptorKey = DescriptorKey.from(ApplicationKey.from("myapp1"), "myadmintool");
    final AdminToolDescriptor result = this.service.getByKey(descriptorKey);
    assertNotNull(result);
    assertEquals("My admin tool", result.getDisplayName());
    assertEquals("My admin tool description", result.getDescription());
    assertEquals(1, result.getAllowedPrincipals().getSize());
}
Also used : DescriptorKey(com.enonic.xp.page.DescriptorKey) AdminToolDescriptor(com.enonic.xp.admin.tool.AdminToolDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with AdminToolDescriptor

use of com.enonic.xp.admin.tool.AdminToolDescriptor in project xp by enonic.

the class AdminToolHandlerTest method mockDescriptor.

private void mockDescriptor(DescriptorKey descriptorKey, boolean hasAccess) {
    AdminToolDescriptor descriptor = Mockito.mock(AdminToolDescriptor.class);
    Mockito.when(descriptor.getKey()).thenReturn(descriptorKey);
    Mockito.when(descriptor.isAccessAllowed(Mockito.any(PrincipalKeys.class))).thenReturn(hasAccess);
    Mockito.when(this.adminToolDescriptorService.getByKey(Mockito.any(DescriptorKey.class))).thenReturn(descriptor);
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) DescriptorKey(com.enonic.xp.page.DescriptorKey) AdminToolDescriptor(com.enonic.xp.admin.tool.AdminToolDescriptor)

Example 5 with AdminToolDescriptor

use of com.enonic.xp.admin.tool.AdminToolDescriptor in project xp by enonic.

the class XmlAdminToolDescriptorParserTest method assertResult.

private void assertResult() throws Exception {
    final AdminToolDescriptor result = this.builder.build();
    assertEquals("myapplication:myadmintool", result.getKey().toString());
    assertEquals("My admin tool", result.getDisplayName());
    assertEquals("key.display-name", result.getDisplayNameI18nKey());
    assertEquals("key.description", result.getDescriptionI18nKey());
    final PrincipalKeys allowedPrincipals = result.getAllowedPrincipals();
    assertNotNull(allowedPrincipals);
    assertEquals(1, allowedPrincipals.getSize());
    assertTrue(allowedPrincipals.first().equals(PrincipalKey.from("role:system.admin")));
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) AdminToolDescriptor(com.enonic.xp.admin.tool.AdminToolDescriptor)

Aggregations

AdminToolDescriptor (com.enonic.xp.admin.tool.AdminToolDescriptor)5 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)2 Test (org.junit.jupiter.api.Test)2 AdminToolDescriptors (com.enonic.xp.admin.tool.AdminToolDescriptors)1 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)1 ResourceKey (com.enonic.xp.resource.ResourceKey)1