Search in sources :

Example 1 with PrincipalQuery

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

the class FindPrincipalsHandlerTest method testFindPrincipalsDefaultParameters.

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

Example 2 with PrincipalQuery

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

the class FindPrincipalsHandlerTest method testFindPrincipalsByName.

@Test
public void testFindPrincipalsByName() {
    final PrincipalQuery expectedQuery = PrincipalQuery.create().idProvider(IdProviderKey.from("enonic")).name("user1").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", "findPrincipalsByName");
}
Also used : PrincipalQuery(com.enonic.xp.security.PrincipalQuery) PrincipalQueryResult(com.enonic.xp.security.PrincipalQueryResult) Test(org.junit.jupiter.api.Test)

Example 3 with PrincipalQuery

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

the class FindPrincipalsHandlerTest method testFindPrincipalsRoles.

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

Example 4 with PrincipalQuery

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

the class SecurityServiceImpl method findPrincipals.

@Override
@Deprecated
public Principals findPrincipals(final IdProviderKey idProvider, final List<PrincipalType> types, final String query) {
    final PrincipalQuery.Builder principalQuery = PrincipalQuery.create().getAll().includeTypes(types).searchText(query);
    if (idProvider != null) {
        principalQuery.idProvider(idProvider);
    }
    final PrincipalQueryResult result = query(principalQuery.build());
    return result.getPrincipals();
}
Also used : PrincipalQuery(com.enonic.xp.security.PrincipalQuery) PrincipalQueryResult(com.enonic.xp.security.PrincipalQueryResult)

Example 5 with PrincipalQuery

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

Aggregations

PrincipalQuery (com.enonic.xp.security.PrincipalQuery)8 PrincipalQueryResult (com.enonic.xp.security.PrincipalQueryResult)8 Test (org.junit.jupiter.api.Test)7 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