Search in sources :

Example 6 with SecurityService

use of com.enonic.xp.security.SecurityService in project xp by enonic.

the class SetPermissionsHandlerTest method testExample.

@Test
public void testExample() {
    final Content content = TestDataFixtures.newExampleContent();
    Mockito.when(this.contentService.getByPath(Mockito.any())).thenReturn(content);
    Mockito.when(this.contentService.applyPermissions(Mockito.any())).thenReturn(ApplyContentPermissionsResult.create().build());
    SecurityService securityService = Mockito.mock(SecurityService.class);
    addService(SecurityService.class, securityService);
    final Optional<? extends Principal> value = Optional.of(User.ANONYMOUS);
    Mockito.<Optional<? extends Principal>>when(securityService.getPrincipal(Mockito.any(PrincipalKey.class))).thenReturn(value);
    runScript("/lib/xp/examples/content/setPermissions.js");
}
Also used : Content(com.enonic.xp.content.Content) SecurityService(com.enonic.xp.security.SecurityService) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 7 with SecurityService

use of com.enonic.xp.security.SecurityService in project xp by enonic.

the class IdProviderControllerServiceImplTest method setup.

@BeforeEach
public void setup() throws Exception {
    // Mocks the IdProviderDescriptorService
    final IdProviderDescriptorService idProviderDescriptorService = Mockito.mock(IdProviderDescriptorService.class);
    Mockito.when(idProviderDescriptorService.getDescriptor(ApplicationKey.from("myapplication"))).thenReturn(IdProviderDescriptor.create().key(ApplicationKey.from("myapplication")).build());
    // Mocks the SecurityService
    final SecurityService securityService = Mockito.mock(SecurityService.class);
    final IdProvider emptyIdProvider = IdProvider.create().build();
    final IdProviderConfig idProviderConfig = IdProviderConfig.create().applicationKey(ApplicationKey.from("myapplication")).build();
    final IdProvider idProvider = IdProvider.create().idProviderConfig(idProviderConfig).build();
    Mockito.when(securityService.getIdProvider(IdProviderKey.from("myemptyidprovider"))).thenReturn(emptyIdProvider);
    Mockito.when(securityService.getIdProvider(IdProviderKey.from("myidprovider"))).thenReturn(idProvider);
    Mockito.when(securityService.getIdProvider(IdProviderKey.from("myemptyuserstore"))).thenReturn(emptyIdProvider);
    Mockito.when(securityService.getIdProvider(IdProviderKey.from("myuserstore"))).thenReturn(idProvider);
    // Mocks the PortalScriptService
    final PortalScriptService portalScriptService = setupPortalScriptService();
    // Creates IdProviderControllerScriptFactoryImpl
    final IdProviderControllerScriptFactoryImpl idProviderControllerScriptFactory = new IdProviderControllerScriptFactoryImpl();
    idProviderControllerScriptFactory.setScriptService(portalScriptService);
    // Creates IdProviderControllerServiceImpl
    idProviderControllerService = new IdProviderControllerServiceImpl();
    idProviderControllerService.setIdProviderControllerScriptFactory(idProviderControllerScriptFactory);
    idProviderControllerService.setIdProviderDescriptorService(idProviderDescriptorService);
    idProviderControllerService.setSecurityService(securityService);
}
Also used : IdProviderDescriptorService(com.enonic.xp.idprovider.IdProviderDescriptorService) PortalScriptService(com.enonic.xp.portal.script.PortalScriptService) SecurityService(com.enonic.xp.security.SecurityService) IdProvider(com.enonic.xp.security.IdProvider) IdProviderConfig(com.enonic.xp.security.IdProviderConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

SecurityService (com.enonic.xp.security.SecurityService)7 PrincipalKey (com.enonic.xp.security.PrincipalKey)4 Test (org.junit.jupiter.api.Test)4 Content (com.enonic.xp.content.Content)2 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)2 Attachment (com.enonic.xp.attachment.Attachment)1 AttachmentSerializer (com.enonic.xp.attachment.AttachmentSerializer)1 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)1 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)1 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 ArchiveInitializer (com.enonic.xp.core.impl.project.init.ArchiveInitializer)1 ContentInitializer (com.enonic.xp.core.impl.project.init.ContentInitializer)1 IssueInitializer (com.enonic.xp.core.impl.project.init.IssueInitializer)1 PropertySet (com.enonic.xp.data.PropertySet)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 EventPublisher (com.enonic.xp.event.EventPublisher)1 IdProviderDescriptorService (com.enonic.xp.idprovider.IdProviderDescriptorService)1 ImageHelper (com.enonic.xp.image.ImageHelper)1