Search in sources :

Example 56 with User

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

the class ModifyProfileHandler method execute.

public PropertyTreeMapper execute() {
    final Optional<User> user = this.securityService.get().getUser(this.key);
    if (user.isPresent()) {
        final UpdateUserParams params = UpdateUserParams.create().userKey(this.key).editor(this::newProfileEditor).build();
        final User updatedUser = this.securityService.get().updateUser(params);
        final PropertyTree updatedProfile = updatedUser.getProfile();
        return createPropertyTreeMapper(updatedProfile, false);
    }
    return null;
}
Also used : User(com.enonic.xp.security.User) EditableUser(com.enonic.xp.security.EditableUser) UpdateUserParams(com.enonic.xp.security.UpdateUserParams) PropertyTree(com.enonic.xp.data.PropertyTree)

Example 57 with User

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

the class GetMembersHandlerTest method testGetMembers.

@Test
public void testGetMembers() {
    final Group group = TestDataFixtures.getTestGroup();
    final User user1 = TestDataFixtures.getTestUser();
    final User user2 = TestDataFixtures.getTestUser2();
    final PrincipalKeys principalKeys = PrincipalKeys.from(user1.getKey(), user2.getKey());
    final PrincipalRelationships relationships = PrincipalRelationships.from(PrincipalRelationship.from(group.getKey()).to(user1.getKey()), PrincipalRelationship.from(group.getKey()).to(user2.getKey()));
    Mockito.when(securityService.getRelationships(group.getKey())).thenReturn(relationships);
    Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(user1, user2));
    runFunction("/test/getMembers-test.js", "getMembers");
}
Also used : Group(com.enonic.xp.security.Group) User(com.enonic.xp.security.User) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) Test(org.junit.jupiter.api.Test)

Example 58 with User

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

the class GetMembersHandlerTest method testExamples.

@Test
public void testExamples() {
    final Group group = TestDataFixtures.getTestGroup();
    final User user1 = TestDataFixtures.getTestUser();
    final User user2 = TestDataFixtures.getTestUser2();
    final PrincipalKeys principalKeys = PrincipalKeys.from(user1.getKey(), user2.getKey());
    final PrincipalRelationships relationships = PrincipalRelationships.from(PrincipalRelationship.from(group.getKey()).to(user1.getKey()), PrincipalRelationship.from(group.getKey()).to(user2.getKey()));
    Mockito.when(securityService.getRelationships(group.getKey())).thenReturn(relationships);
    Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(user1, user2));
    runScript("/lib/xp/examples/auth/getMembers.js");
}
Also used : Group(com.enonic.xp.security.Group) User(com.enonic.xp.security.User) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) Test(org.junit.jupiter.api.Test)

Example 59 with User

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

the class ModifyProfileHandlerTest method testExamples.

@Test
public void testExamples() {
    final User user = TestDataFixtures.getTestUser();
    Mockito.when(securityService.getUser(Mockito.any())).thenReturn(Optional.of(user));
    Mockito.when(this.securityService.updateUser(Mockito.isA(UpdateUserParams.class))).thenAnswer(invocationOnMock -> invokeUpdate((UpdateUserParams) invocationOnMock.getArguments()[0], user));
    runScript("/lib/xp/examples/auth/modifyProfile.js");
}
Also used : User(com.enonic.xp.security.User) EditableUser(com.enonic.xp.security.EditableUser) UpdateUserParams(com.enonic.xp.security.UpdateUserParams) Test(org.junit.jupiter.api.Test)

Example 60 with User

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

the class ModifyUserHandlerTest method invokeUpdate.

private User invokeUpdate(final UpdateUserParams params) {
    final UserEditor editor = params.getEditor();
    assertNotNull(editor);
    final User user = TestDataFixtures.getTestUser();
    final EditableUser editable = new EditableUser(user);
    editor.edit(editable);
    return editable.build();
}
Also used : User(com.enonic.xp.security.User) EditableUser(com.enonic.xp.security.EditableUser) UserEditor(com.enonic.xp.security.UserEditor) EditableUser(com.enonic.xp.security.EditableUser)

Aggregations

User (com.enonic.xp.security.User)63 Test (org.junit.jupiter.api.Test)40 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)22 PropertyTree (com.enonic.xp.data.PropertyTree)17 PrincipalKey (com.enonic.xp.security.PrincipalKey)17 Context (com.enonic.xp.context.Context)14 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)11 CreateUserParams (com.enonic.xp.security.CreateUserParams)10 IdProviderKey (com.enonic.xp.security.IdProviderKey)10 Node (com.enonic.xp.node.Node)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)6 UpdateUserParams (com.enonic.xp.security.UpdateUserParams)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Mockito (org.mockito.Mockito)6 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)4 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)4 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)4 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)4 TaskId (com.enonic.xp.task.TaskId)4