Search in sources :

Example 1 with UpdateUserParams

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

the class ModifyProfileHandlerTest method keep_original_value_types_when_not_touched.

@Test
public void keep_original_value_types_when_not_touched() {
    final User user = TestDataFixtures.getTestUserWithProfile();
    Mockito.when(securityService.getUser(Mockito.any())).thenReturn(Optional.of(user));
    Mockito.when(this.securityService.updateUser(Mockito.isA(UpdateUserParams.class))).thenAnswer(invocationOnMock -> {
        final User editedUser = invokeUpdate((UpdateUserParams) invocationOnMock.getArguments()[0], user);
        final PropertySet profile = editedUser.getProfile().getSet("myApp");
        assertTrue(profile.getProperty("untouchedString").getType().equals(ValueTypes.STRING));
        assertTrue(profile.getProperty("untouchedBoolean").getType().equals(ValueTypes.BOOLEAN));
        assertTrue(profile.getProperty("untouchedDouble").getType().equals(ValueTypes.DOUBLE));
        assertTrue(profile.getProperty("untouchedLong").getType().equals(ValueTypes.LONG));
        assertTrue(profile.getProperty("untouchedLink").getType().equals(ValueTypes.LINK));
        assertTrue(profile.getProperty("untouchedInstant").getType().equals(ValueTypes.DATE_TIME));
        assertTrue(profile.getProperty("untouchedGeoPoint").getType().equals(ValueTypes.GEO_POINT));
        assertTrue(profile.getProperty("untouchedLocalDate").getType().equals(ValueTypes.LOCAL_DATE));
        assertTrue(profile.getProperty("untouchedReference").getType().equals(ValueTypes.REFERENCE));
        assertTrue(profile.getProperty("untouchedBinaryRef").getType().equals(ValueTypes.BINARY_REFERENCE));
        return editedUser;
    });
    runScript("/test/modifyProfile-test.js");
}
Also used : User(com.enonic.xp.security.User) EditableUser(com.enonic.xp.security.EditableUser) UpdateUserParams(com.enonic.xp.security.UpdateUserParams) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 2 with UpdateUserParams

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

the class SecurityServiceImplTest method testUpdateUserDuplicatedEmailWithEditor.

@Test
public void testUpdateUserDuplicatedEmailWithEditor() {
    try {
        runAsAdmin(() -> {
            final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
            final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("same_email@enonic.com").login("User1").password("123456").build();
            final PrincipalKey userKey2 = PrincipalKey.ofUser(SYSTEM, "user2");
            final CreateUserParams createUser2 = CreateUserParams.create().userKey(userKey2).displayName("User 2").email("same_email@enonic.com").login("user2").build();
            final User user1 = securityService.createUser(createUser1);
            securityService.createUser(createUser2);
            final UpdateUserParams updateUserParams = UpdateUserParams.create(user1).editor(editableUser -> editableUser.email = "same_email@enonic.com").build();
            securityService.updateUser(updateUserParams);
            refresh();
        });
        fail("Expected exception");
    } catch (IllegalArgumentException e) {
        assertEquals("A user with email 'same_email@enonic.com' already exists in id provider 'system'", e.getMessage());
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IdProviderKey(com.enonic.xp.security.IdProviderKey) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) IndexServiceInternalImpl(com.enonic.xp.repo.impl.elasticsearch.IndexServiceInternalImpl) CreateGroupParams(com.enonic.xp.security.CreateGroupParams) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) NodeRepositoryServiceImpl(com.enonic.xp.repo.impl.repository.NodeRepositoryServiceImpl) Role(com.enonic.xp.security.Role) IndexDataServiceImpl(com.enonic.xp.repo.impl.storage.IndexDataServiceImpl) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) IndexServiceImpl(com.enonic.xp.repo.impl.index.IndexServiceImpl) AuthenticationException(com.enonic.xp.security.auth.AuthenticationException) ContextBuilder(com.enonic.xp.context.ContextBuilder) VerifiedEmailAuthToken(com.enonic.xp.security.auth.VerifiedEmailAuthToken) UpdateIdProviderParams(com.enonic.xp.security.UpdateIdProviderParams) StorageDaoImpl(com.enonic.xp.repo.impl.elasticsearch.storage.StorageDaoImpl) SystemConstants(com.enonic.xp.security.SystemConstants) UpdateRoleParams(com.enonic.xp.security.UpdateRoleParams) CreateUserParams(com.enonic.xp.security.CreateUserParams) User(com.enonic.xp.security.User) PrincipalRelationship(com.enonic.xp.security.PrincipalRelationship) CREATE_USERS(com.enonic.xp.security.acl.IdProviderAccess.CREATE_USERS) Test(org.junit.jupiter.api.Test) SearchDaoImpl(com.enonic.xp.repo.impl.elasticsearch.search.SearchDaoImpl) SecurityConstants(com.enonic.xp.security.SecurityConstants) VersionServiceImpl(com.enonic.xp.repo.impl.version.VersionServiceImpl) NodeStorageServiceImpl(com.enonic.xp.repo.impl.storage.NodeStorageServiceImpl) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BinaryServiceImpl(com.enonic.xp.repo.impl.binary.BinaryServiceImpl) NodeSearchServiceImpl(com.enonic.xp.repo.impl.search.NodeSearchServiceImpl) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) IdProvider(com.enonic.xp.security.IdProvider) IdProviderAccessControlEntry(com.enonic.xp.security.acl.IdProviderAccessControlEntry) ADMINISTRATOR(com.enonic.xp.security.acl.IdProviderAccess.ADMINISTRATOR) CreateRoleParams(com.enonic.xp.security.CreateRoleParams) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) EventPublisher(com.enonic.xp.event.EventPublisher) UpdateUserParams(com.enonic.xp.security.UpdateUserParams) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Callable(java.util.concurrent.Callable) UsernamePasswordAuthToken(com.enonic.xp.security.auth.UsernamePasswordAuthToken) NodeServiceImpl(com.enonic.xp.repo.impl.node.NodeServiceImpl) RepositoryServiceImpl(com.enonic.xp.repo.impl.repository.RepositoryServiceImpl) VerifiedUsernameAuthToken(com.enonic.xp.security.auth.VerifiedUsernameAuthToken) PrincipalQuery(com.enonic.xp.security.PrincipalQuery) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PrincipalNotFoundException(com.enonic.xp.security.PrincipalNotFoundException) EmailPasswordAuthToken(com.enonic.xp.security.auth.EmailPasswordAuthToken) RepositoryEntryServiceImpl(com.enonic.xp.repo.impl.repository.RepositoryEntryServiceImpl) Group(com.enonic.xp.security.Group) AuthenticationToken(com.enonic.xp.security.auth.AuthenticationToken) UpdateGroupParams(com.enonic.xp.security.UpdateGroupParams) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) WRITE_USERS(com.enonic.xp.security.acl.IdProviderAccess.WRITE_USERS) Mockito(org.mockito.Mockito) PrincipalQueryResult(com.enonic.xp.security.PrincipalQueryResult) NodeVersionServiceImpl(com.enonic.xp.repo.impl.node.dao.NodeVersionServiceImpl) CreateIdProviderParams(com.enonic.xp.security.CreateIdProviderParams) IdProviderAlreadyExistsException(com.enonic.xp.security.IdProviderAlreadyExistsException) PrincipalKey(com.enonic.xp.security.PrincipalKey) PrincipalAlreadyExistsException(com.enonic.xp.security.PrincipalAlreadyExistsException) MemoryBlobStore(com.enonic.xp.internal.blobstore.MemoryBlobStore) BranchServiceImpl(com.enonic.xp.repo.impl.branch.storage.BranchServiceImpl) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) CreateUserParams(com.enonic.xp.security.CreateUserParams) User(com.enonic.xp.security.User) UpdateUserParams(com.enonic.xp.security.UpdateUserParams) PrincipalKey(com.enonic.xp.security.PrincipalKey) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with UpdateUserParams

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

the class SecurityServiceImplTest method testUpdateUserDuplicatedEmail.

@Test
public void testUpdateUserDuplicatedEmail() {
    try {
        runAsAdmin(() -> {
            final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
            final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("same_email@enonic.com").login("User1").password("123456").build();
            final PrincipalKey userKey2 = PrincipalKey.ofUser(SYSTEM, "user2");
            final CreateUserParams createUser2 = CreateUserParams.create().userKey(userKey2).displayName("User 2").email("same_email@enonic.com").login("user2").build();
            final User user1 = securityService.createUser(createUser1);
            securityService.createUser(createUser2);
            final UpdateUserParams updateUserParams = UpdateUserParams.create(user1).email("same_email@enonic.com").build();
            securityService.updateUser(updateUserParams);
            refresh();
        });
        fail("Expected exception");
    } catch (IllegalArgumentException e) {
        assertEquals("A user with email 'same_email@enonic.com' already exists in id provider 'system'", e.getMessage());
    }
}
Also used : CreateUserParams(com.enonic.xp.security.CreateUserParams) User(com.enonic.xp.security.User) UpdateUserParams(com.enonic.xp.security.UpdateUserParams) PrincipalKey(com.enonic.xp.security.PrincipalKey) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with UpdateUserParams

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

the class SecurityServiceImplTest method testUpdateUser.

@Test
public void testUpdateUser() throws Exception {
    runAsAdmin(() -> {
        final CreateUserParams createUser = CreateUserParams.create().userKey(PrincipalKey.ofUser(SYSTEM, "User1")).displayName("User 1").email("user1@enonic.com").login("User1").build();
        final User user = securityService.createUser(createUser);
        refresh();
        final UpdateUserParams updateUserParams = UpdateUserParams.create(user).email("u2@enonic.net").build();
        final User updateUserResult = securityService.updateUser(updateUserParams);
        refresh();
        final User updatedUser = securityService.getUser(user.getKey()).get();
        assertEquals("u2@enonic.net", updateUserResult.getEmail());
        assertEquals("u2@enonic.net", updatedUser.getEmail());
        assertEquals("User1", updatedUser.getLogin());
        assertEquals("User 1", updatedUser.getDisplayName());
        assertEquals(PrincipalKey.ofUser(SYSTEM, "User1"), updatedUser.getKey());
    });
}
Also used : CreateUserParams(com.enonic.xp.security.CreateUserParams) User(com.enonic.xp.security.User) UpdateUserParams(com.enonic.xp.security.UpdateUserParams) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with UpdateUserParams

use of com.enonic.xp.security.UpdateUserParams 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)

Aggregations

UpdateUserParams (com.enonic.xp.security.UpdateUserParams)6 User (com.enonic.xp.security.User)6 Test (org.junit.jupiter.api.Test)5 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)3 CreateUserParams (com.enonic.xp.security.CreateUserParams)3 EditableUser (com.enonic.xp.security.EditableUser)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)2 Context (com.enonic.xp.context.Context)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 PropertySet (com.enonic.xp.data.PropertySet)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 EventPublisher (com.enonic.xp.event.EventPublisher)1 MemoryBlobStore (com.enonic.xp.internal.blobstore.MemoryBlobStore)1 BinaryServiceImpl (com.enonic.xp.repo.impl.binary.BinaryServiceImpl)1 BranchServiceImpl (com.enonic.xp.repo.impl.branch.storage.BranchServiceImpl)1 IndexServiceInternalImpl (com.enonic.xp.repo.impl.elasticsearch.IndexServiceInternalImpl)1 SearchDaoImpl (com.enonic.xp.repo.impl.elasticsearch.search.SearchDaoImpl)1 StorageDaoImpl (com.enonic.xp.repo.impl.elasticsearch.storage.StorageDaoImpl)1 IndexServiceImpl (com.enonic.xp.repo.impl.index.IndexServiceImpl)1 NodeServiceImpl (com.enonic.xp.repo.impl.node.NodeServiceImpl)1