Search in sources :

Example 6 with PrincipalQueryResult

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

the class SecurityServiceImplTest method testQuery.

@Test
public void testQuery() throws Exception {
    runAsAdmin(() -> {
        final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
        final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("user1@enonic.com").login("User1").password("123456").build();
        refresh();
        final PrincipalQuery query = PrincipalQuery.create().idProvider(IdProviderKey.system()).build();
        PrincipalQueryResult queryResult = securityService.query(query);
        queryResult = securityService.query(query);
        assertEquals(2, queryResult.getTotalSize());
        final User user1 = securityService.createUser(createUser1);
        refresh();
        queryResult = securityService.query(query);
        assertEquals(3, queryResult.getTotalSize());
        assertEquals(user1, queryResult.getPrincipals().getPrincipal(userKey1));
    });
}
Also used : CreateUserParams(com.enonic.xp.security.CreateUserParams) PrincipalQuery(com.enonic.xp.security.PrincipalQuery) PrincipalQueryResult(com.enonic.xp.security.PrincipalQueryResult) User(com.enonic.xp.security.User) PrincipalKey(com.enonic.xp.security.PrincipalKey) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with PrincipalQueryResult

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

the class FindPrincipalsHandlerTest method testExamples.

@Test
public void testExamples() {
    final PrincipalQueryResult result = PrincipalQueryResult.create().addPrincipal(TestDataFixtures.getTestGroup()).addPrincipal(TestDataFixtures.getTestRole()).addPrincipal(TestDataFixtures.getTestUser()).totalSize(3).build();
    Mockito.when(securityService.query(Mockito.any(PrincipalQuery.class))).thenReturn(result);
    runScript("/lib/xp/examples/auth/findPrincipals.js");
}
Also used : PrincipalQueryResult(com.enonic.xp.security.PrincipalQueryResult) PrincipalQuery(com.enonic.xp.security.PrincipalQuery) Test(org.junit.jupiter.api.Test)

Example 8 with PrincipalQueryResult

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

the class FindPrincipalsHandlerTest method testFindPrincipalsUsers.

@Test
public void testFindPrincipalsUsers() {
    final PrincipalQuery expectedQuery = PrincipalQuery.create().includeUsers().idProvider(IdProviderKey.from("enonic")).from(2).size(3).build();
    final PrincipalQueryResult result = PrincipalQueryResult.create().addPrincipal(TestDataFixtures.getTestUser()).totalSize(3).build();
    Mockito.when(securityService.query(Mockito.eq(expectedQuery))).thenReturn(result);
    runFunction("/test/findPrincipals-test.js", "findPrincipalsUsers");
}
Also used : PrincipalQuery(com.enonic.xp.security.PrincipalQuery) PrincipalQueryResult(com.enonic.xp.security.PrincipalQueryResult) Test(org.junit.jupiter.api.Test)

Example 9 with PrincipalQueryResult

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

the class FindPrincipalsHandlerTest method testFindPrincipalsBySearchText.

@Test
public void testFindPrincipalsBySearchText() {
    final PrincipalQuery expectedQuery = PrincipalQuery.create().searchText("enonic").build();
    final PrincipalQueryResult result = PrincipalQueryResult.create().addPrincipal(TestDataFixtures.getTestUser()).totalSize(1).build();
    Mockito.when(securityService.query(Mockito.eq(expectedQuery))).thenReturn(result);
    runFunction("/test/findPrincipals-test.js", "findPrincipalsBySearchText");
}
Also used : PrincipalQuery(com.enonic.xp.security.PrincipalQuery) PrincipalQueryResult(com.enonic.xp.security.PrincipalQueryResult) Test(org.junit.jupiter.api.Test)

Example 10 with PrincipalQueryResult

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

the class FindPrincipalsHandlerTest method testFindPrincipalsGroups.

@Test
public void testFindPrincipalsGroups() {
    final PrincipalQuery expectedQuery = PrincipalQuery.create().includeGroups().idProvider(IdProviderKey.from("enonic")).from(2).size(3).build();
    final PrincipalQueryResult result = PrincipalQueryResult.create().addPrincipal(TestDataFixtures.getTestGroup()).totalSize(3).build();
    Mockito.when(securityService.query(Mockito.eq(expectedQuery))).thenReturn(result);
    runFunction("/test/findPrincipals-test.js", "findPrincipalsGroups");
}
Also used : PrincipalQuery(com.enonic.xp.security.PrincipalQuery) PrincipalQueryResult(com.enonic.xp.security.PrincipalQueryResult) Test(org.junit.jupiter.api.Test)

Aggregations

PrincipalQuery (com.enonic.xp.security.PrincipalQuery)10 PrincipalQueryResult (com.enonic.xp.security.PrincipalQueryResult)10 Test (org.junit.jupiter.api.Test)8 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)1 CreateUserParams (com.enonic.xp.security.CreateUserParams)1 PrincipalKey (com.enonic.xp.security.PrincipalKey)1 User (com.enonic.xp.security.User)1