Search in sources :

Example 1 with PrincipalQueryResult

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

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

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

the class FindPrincipalsHandler method findPrincipals.

public PrincipalsResultMapper findPrincipals() {
    final PrincipalQuery.Builder query = PrincipalQuery.create();
    if (this.type != null) {
        query.includeTypes(this.type);
    }
    if (this.idProvider != null) {
        query.idProvider(this.idProvider);
    }
    query.name(this.name);
    query.from(this.start);
    query.size(this.count);
    query.searchText(this.searchText);
    final PrincipalQueryResult result = this.securityService.get().query(query.build());
    return new PrincipalsResultMapper(result.getPrincipals(), result.getTotalSize());
}
Also used : PrincipalQuery(com.enonic.xp.security.PrincipalQuery) PrincipalQueryResult(com.enonic.xp.security.PrincipalQueryResult)

Example 4 with PrincipalQueryResult

use of com.enonic.xp.security.PrincipalQueryResult 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 5 with PrincipalQueryResult

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

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