Search in sources :

Example 1 with SecurityService

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

the class ContextScriptTest method initialize.

@Override
protected void initialize() throws Exception {
    super.initialize();
    final SecurityService securityService = Mockito.mock(SecurityService.class);
    addService(SecurityService.class, securityService);
    final User user = User.create().login(PrincipalKey.ofSuperUser().getId()).displayName("Super User").key(PrincipalKey.ofSuperUser()).build();
    final AuthenticationInfo authInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN, RoleKeys.EVERYONE).build();
    Mockito.when(securityService.authenticate(Mockito.any())).thenReturn(authInfo);
}
Also used : User(com.enonic.xp.security.User) SecurityService(com.enonic.xp.security.SecurityService) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo)

Example 2 with SecurityService

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

the class SetPermissionsHandlerTest method testContentNotFoundByPath.

@Test
public void testContentNotFoundByPath() throws Exception {
    Mockito.when(this.contentService.getByPath(Mockito.any())).thenThrow(new ContentNotFoundException(ContentPath.ROOT, Branch.from("draft")));
    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);
    runFunction("/test/SetPermissionsHandlerTest.js", "setPermissionsNotFoundByPath");
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) SecurityService(com.enonic.xp.security.SecurityService) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 3 with SecurityService

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

the class ProjectServiceImpl method doModify.

private Project doModify(final ModifyProjectParams params) {
    final UpdateRepositoryParams updateParams = UpdateRepositoryParams.create().repositoryId(params.getName().getRepoId()).editor(editableRepository -> modifyProjectData(params, editableRepository.data)).build();
    final Repository updatedRepository = repositoryService.updateRepository(updateParams);
    if (!ProjectConstants.DEFAULT_PROJECT_NAME.equals(params.getName())) {
        UpdateProjectRoleNamesCommand.create().securityService(securityService).projectName(params.getName()).projectDisplayName(params.getDisplayName()).build().execute();
    }
    return Project.from(updatedRepository);
}
Also used : ArchiveInitializer(com.enonic.xp.core.impl.project.init.ArchiveInitializer) DeleteRepositoryParams(com.enonic.xp.repository.DeleteRepositoryParams) RepositoryService(com.enonic.xp.repository.RepositoryService) LoggerFactory(org.slf4j.LoggerFactory) AttachmentSerializer(com.enonic.xp.attachment.AttachmentSerializer) ImageHelper(com.enonic.xp.image.ImageHelper) IndexService(com.enonic.xp.index.IndexService) BigDecimal(java.math.BigDecimal) RepositoryId(com.enonic.xp.repository.RepositoryId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeService(com.enonic.xp.node.NodeService) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ImageIO(javax.imageio.ImageIO) ContextBuilder(com.enonic.xp.context.ContextBuilder) EnumSet(java.util.EnumSet) SecurityService(com.enonic.xp.security.SecurityService) RoundingMode(java.math.RoundingMode) BinaryReference(com.enonic.xp.util.BinaryReference) ProjectService(com.enonic.xp.project.ProjectService) Projects(com.enonic.xp.project.Projects) BufferedImage(java.awt.image.BufferedImage) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Project(com.enonic.xp.project.Project) Collectors(java.util.stream.Collectors) CreateProjectParams(com.enonic.xp.project.CreateProjectParams) UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) ProjectNotFoundException(com.enonic.xp.project.ProjectNotFoundException) Optional(java.util.Optional) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) Queue(java.util.Queue) Repository(com.enonic.xp.repository.Repository) EventPublisher(com.enonic.xp.event.EventPublisher) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Callable(java.util.concurrent.Callable) Attachment(com.enonic.xp.attachment.Attachment) ProjectConstants(com.enonic.xp.project.ProjectConstants) ProjectGraphEntry(com.enonic.xp.project.ProjectGraphEntry) ArrayList(java.util.ArrayList) IssueInitializer(com.enonic.xp.core.impl.project.init.IssueInitializer) ProjectRole(com.enonic.xp.project.ProjectRole) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ProjectName(com.enonic.xp.project.ProjectName) ContentInitializer(com.enonic.xp.core.impl.project.init.ContentInitializer) ModifyProjectIconParams(com.enonic.xp.project.ModifyProjectIconParams) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) Logger(org.slf4j.Logger) ProjectGraph(com.enonic.xp.project.ProjectGraph) ProjectPermissions(com.enonic.xp.project.ProjectPermissions) PropertySet(com.enonic.xp.data.PropertySet) IOException(java.io.IOException) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) ModifyProjectParams(com.enonic.xp.project.ModifyProjectParams) InputStream(java.io.InputStream) Repository(com.enonic.xp.repository.Repository) UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams)

Example 4 with SecurityService

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

the class SetPermissionsHandlerTest method testMissingPrincipals.

@Test
public void testMissingPrincipals() throws Exception {
    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);
    Mockito.<Optional<? extends Principal>>when(securityService.getPrincipal(Mockito.any(PrincipalKey.class))).thenReturn(Optional.empty());
    runFunction("/test/SetPermissionsHandlerTest.js", "setPermissionsMissingPrincipals");
}
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 5 with SecurityService

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

the class SetPermissionsHandlerTest method testContentNotFoundById.

@Test
public void testContentNotFoundById() throws Exception {
    Mockito.when(this.contentService.getByPath(Mockito.any())).thenThrow(new ContentNotFoundException(ContentId.from("ee70f5d0-025c-4fbd-a835-5e50ff7b76ba"), Branch.from("draft")));
    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);
    runFunction("/test/SetPermissionsHandlerTest.js", "setPermissionsNotFoundById");
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) SecurityService(com.enonic.xp.security.SecurityService) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

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