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);
}
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());
}
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());
}
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);
}
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")));
}
Aggregations