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");
}
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");
}
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");
}
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();
}
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));
});
}
Aggregations