use of com.enonic.xp.security.User in project xp by enonic.
the class AuthenticationInfoTest method testSerializationWithUserProfile.
@Test
void testSerializationWithUserProfile() throws Exception {
final PropertySet data = new PropertySet();
data.setString("subString", "subStringValue");
data.setLong("subLong", 123L);
final PropertyTree userProfile = new PropertyTree();
userProfile.setSet("myApp", data);
userProfile.setString("string", "stringValue");
final User user = User.create().login("userlogin").displayName("my user").key(PrincipalKey.ofUser(IdProviderKey.from("myidprovider"), "userid")).email("user@email").modifiedTime(Instant.now(clock)).profile(userProfile).build();
final IdProviderKey idProvider = IdProviderKey.from("myStore");
final PrincipalKey group1 = PrincipalKey.ofGroup(idProvider, "group1");
final PrincipalKey group2 = PrincipalKey.from("group:myStore:group2");
final PrincipalKey role1 = PrincipalKey.from("role:administrators");
final AuthenticationInfo info = AuthenticationInfo.create().user(user).principals(group1).principals(PrincipalKeys.from(group2, role1)).build();
final byte[] serializedObject = serialize(info);
final AuthenticationInfo deserializedObject = (AuthenticationInfo) deserialize(serializedObject);
assertEquals(deserializedObject, info);
}
use of com.enonic.xp.security.User in project xp by enonic.
the class CreateContentCommand method populateCreator.
private void populateCreator(final CreateContentTranslatorParams.Builder builder) {
final User currentUser = getCurrentUser();
builder.creator(currentUser.getKey());
}
use of com.enonic.xp.security.User in project xp by enonic.
the class ContentAuditLogSupportImplTest method testCreateContent.
@Test
public void testCreateContent() throws Exception {
final PropertyTree propertyTree = new PropertyTree();
propertyTree.addString("test-data", "test-data");
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.site()).parent(ContentPath.ROOT).contentData(propertyTree).displayName("displayName").build();
final Content content = Content.create().id(ContentId.from("contentId")).type(ContentTypeName.site()).name("contentName").displayName("displayName").parentPath(ContentPath.ROOT).build();
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "testUser")).displayName("Test User").modifiedTime(Instant.now()).email("test-user@enonic.com").login("test-user").build();
final AuthenticationInfo authInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN_LOGIN).build();
final Context context = ContextBuilder.create().branch(ContentConstants.BRANCH_DRAFT).repositoryId(RepositoryId.from("test-repository")).authInfo(authInfo).build();
// test
context.runWith(() -> support.createContent(params, content));
executor.shutdown();
executor.awaitTermination(1, TimeUnit.MINUTES);
// verify and assert
final ArgumentCaptor<LogAuditLogParams> argumentCaptor = ArgumentCaptor.forClass(LogAuditLogParams.class);
Mockito.verify(auditLogService, Mockito.times(1)).log(argumentCaptor.capture());
Assertions.assertEquals(user.getKey(), argumentCaptor.getValue().getUser());
}
use of com.enonic.xp.security.User in project xp by enonic.
the class ProjectServiceImplTest method create_with_role_members.
@Test
void create_with_role_members() {
final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
adminContext().runWith(() -> {
final User user1 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("user1").login("user1").build());
final User user2 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user2")).displayName("user2").login("user2").build());
doCreateProjectAsAdmin(ProjectName.from(projectRepoId), ProjectPermissions.create().addOwner(user1.getKey()).addOwner(user2.getKey()).build());
final Set<PrincipalKey> members = securityService.getRelationships(PrincipalKey.ofRole("cms.project.test-project.owner")).stream().map(PrincipalRelationship::getTo).collect(Collectors.toSet());
assertTrue(members.contains(user1.getKey()));
assertTrue(members.contains(user2.getKey()));
});
}
use of com.enonic.xp.security.User in project xp by enonic.
the class ProjectServiceImplTest method modify_default_project_permissions.
@Test
void modify_default_project_permissions() {
adminContext().runWith(() -> {
final User user1 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("user1").login("user1").build());
final RuntimeException ex = Assertions.assertThrows(RuntimeException.class, () -> projectService.modifyPermissions(ProjectConstants.DEFAULT_PROJECT_NAME, ProjectPermissions.create().addOwner(user1.getKey()).build()));
assertEquals("Default project permissions cannot be modified.", ex.getMessage());
});
}
Aggregations