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