org.camunda.bpm.engine.identity.TenantQuery Java Examples

The following examples show how to use org.camunda.bpm.engine.identity.TenantQuery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IdentityServiceTenantTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteTenantUserMembership() {
  Tenant tenant = identityService.newTenant(TENANT_ONE);
  identityService.saveTenant(tenant);

  User user = identityService.newUser(USER_ONE);
  identityService.saveUser(user);

  identityService.createTenantUserMembership(TENANT_ONE, USER_ONE);

  TenantQuery query = identityService.createTenantQuery().userMember(USER_ONE);
  assertThat(query.count(), is(1L));

  identityService.deleteTenantUserMembership("nonExisting", USER_ONE);
  assertThat(query.count(), is(1L));

  identityService.deleteTenantUserMembership(TENANT_ONE, "nonExisting");
  assertThat(query.count(), is(1L));

  identityService.deleteTenantUserMembership(TENANT_ONE, USER_ONE);
  assertThat(query.count(), is(0L));
}
 
Example #2
Source File: IdentityServiceTenantTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteTenantGroupMembership() {
  Tenant tenant = identityService.newTenant(TENANT_ONE);
  identityService.saveTenant(tenant);

  Group group = identityService.newGroup(GROUP_ONE);
  identityService.saveGroup(group);

  identityService.createTenantGroupMembership(TENANT_ONE, GROUP_ONE);

  TenantQuery query = identityService.createTenantQuery().groupMember(GROUP_ONE);
  assertThat(query.count(), is(1L));

  identityService.deleteTenantGroupMembership("nonExisting", GROUP_ONE);
  assertThat(query.count(), is(1L));

  identityService.deleteTenantGroupMembership(TENANT_ONE, "nonExisting");
  assertThat(query.count(), is(1L));

  identityService.deleteTenantGroupMembership(TENANT_ONE, GROUP_ONE);
  assertThat(query.count(), is(0L));
}
 
Example #3
Source File: IdentityServiceTenantTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteTenantMembershipsWileDeleteUser() {
  Tenant tenant = identityService.newTenant(TENANT_ONE);
  identityService.saveTenant(tenant);

  User user = identityService.newUser(USER_ONE);
  identityService.saveUser(user);

  identityService.createTenantUserMembership(TENANT_ONE, USER_ONE);

  TenantQuery query = identityService.createTenantQuery().userMember(USER_ONE);
  assertThat(query.count(), is(1L));

  identityService.deleteUser(USER_ONE);
  assertThat(query.count(), is(0L));
}
 
Example #4
Source File: IdentityServiceTenantTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteTenantMembershipsWhileDeleteGroup() {
  Tenant tenant = identityService.newTenant(TENANT_ONE);
  identityService.saveTenant(tenant);

  Group group = identityService.newGroup(GROUP_ONE);
  identityService.saveGroup(group);

  identityService.createTenantGroupMembership(TENANT_ONE, GROUP_ONE);

  TenantQuery query = identityService.createTenantQuery().groupMember(GROUP_ONE);
  assertThat(query.count(), is(1L));

  identityService.deleteGroup(GROUP_ONE);
  assertThat(query.count(), is(0L));
}
 
Example #5
Source File: TenantQueryDto.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void applyFilters(TenantQuery query) {
  if (id != null) {
    query.tenantId(id);
  }
  if (name != null) {
    query.tenantName(name);
  }
  if (nameLike != null) {
    query.tenantNameLike(nameLike);
  }
  if (userId != null) {
    query.userMember(userId);
  }
  if (groupId != null) {
    query.groupMember(groupId);
  }
  if (Boolean.TRUE.equals(includingGroupsOfUser)) {
    query.includingGroupsOfUser(true);
  }
}
 
Example #6
Source File: TenantQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void queryByUserIncludingGroups() {
  TenantQuery query = identityService.createTenantQuery().userMember(USER);

  assertThat(query.includingGroupsOfUser(false).count(), is(1L));
  assertThat(query.includingGroupsOfUser(true).count(), is(2L));
}
 
Example #7
Source File: TenantQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void queryById() {
  TenantQuery query = identityService.createTenantQuery().tenantId(TENANT_ONE);

  assertThat(query.count(), is(1L));
  assertThat(query.list().size(), is(1));

  Tenant tenant = query.singleResult();
  assertThat(tenant, is(notNullValue()));
  assertThat(tenant.getName(), is("Tenant_1"));
}
 
Example #8
Source File: TenantQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void queryByIdIn() {
  TenantQuery query = identityService.createTenantQuery();

  assertThat(query.tenantIdIn("non", "existing").count(), is(0L));
  assertThat(query.tenantIdIn(TENANT_ONE, TENANT_TWO).count(), is(2L));
}
 
Example #9
Source File: TenantQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void queryByName() {
  TenantQuery query = identityService.createTenantQuery();

  assertThat(query.tenantName("nonExisting").count(), is(0L));
  assertThat(query.tenantName("Tenant_1").count(), is(1L));
  assertThat(query.tenantName("Tenant_2").count(), is(1L));
}
 
Example #10
Source File: TenantQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void queryByNameLike() {
  TenantQuery query = identityService.createTenantQuery();

  assertThat(query.tenantNameLike("%nonExisting%").count(), is(0L));
  assertThat(query.tenantNameLike("%Tenant\\_1%").count(), is(1L));
  assertThat(query.tenantNameLike("%Tenant%").count(), is(2L));
}
 
Example #11
Source File: TenantQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void queryByUser() {
  TenantQuery query = identityService.createTenantQuery();

  assertThat(query.userMember("nonExisting").count(), is(0L));
  assertThat(query.userMember(USER).count(), is(1L));
  assertThat(query.userMember(USER).tenantId(TENANT_ONE).count(), is(1L));
}
 
Example #12
Source File: TenantQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void queryByGroup() {
  TenantQuery query = identityService.createTenantQuery();

  assertThat(query.groupMember("nonExisting").count(), is(0L));
  assertThat(query.groupMember(GROUP).count(), is(1L));
  assertThat(query.groupMember(GROUP).tenantId(TENANT_TWO).count(), is(1L));
}
 
Example #13
Source File: IdentityServiceTenantTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void deleteTenant() {
  // create
  Tenant tenant = identityService.newTenant(TENANT_ONE);
  identityService.saveTenant(tenant);

  TenantQuery query = identityService.createTenantQuery();
  assertThat(query.count(), is(1L));

  identityService.deleteTenant("nonExisting");
  assertThat(query.count(), is(1L));

  identityService.deleteTenant(TENANT_ONE);
  assertThat(query.count(), is(0L));
}
 
Example #14
Source File: FetchAndLockRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private List<String> setupTenantQueryMock(List<Tenant> tenants) {
  TenantQuery mockTenantQuery = mock(TenantQuery.class);

  when(identityServiceMock.createTenantQuery()).thenReturn(mockTenantQuery);
  when(mockTenantQuery.userMember(anyString())).thenReturn(mockTenantQuery);
  when(mockTenantQuery.includingGroupsOfUser(anyBoolean())).thenReturn(mockTenantQuery);
  when(mockTenantQuery.list()).thenReturn(tenants);

  List<String> tenantIds = new ArrayList<String>();
  for(Tenant tenant: tenants) {
    tenantIds.add(tenant.getId());
  }
  return tenantIds;
}
 
Example #15
Source File: TenantQueryDto.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected void applySortBy(TenantQuery query, String sortBy, Map<String, Object> parameters, ProcessEngine engine) {
  if (sortBy.equals(SORT_BY_TENANT_ID_VALUE)) {
    query.orderByTenantId();
  } else if (sortBy.equals(SORT_BY_TENANT_NAME_VALUE)) {
    query.orderByTenantName();
  }
}
 
Example #16
Source File: TenantRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public List<TenantDto> queryTenants(UriInfo uriInfo, Integer firstResult, Integer maxResults) {
  TenantQueryDto queryDto = new TenantQueryDto(getObjectMapper(), uriInfo.getQueryParameters());

  TenantQuery query = queryDto.toQuery(getProcessEngine());

  List<Tenant> tenants;
  if (firstResult != null || maxResults != null) {
    tenants = executePaginatedQuery(query, firstResult, maxResults);
  } else {
    tenants = query.list();
  }

  return TenantDto.fromTenantList(tenants );
}
 
Example #17
Source File: TenantRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public CountResultDto getTenantCount(UriInfo uriInfo) {
  TenantQueryDto queryDto = new TenantQueryDto(getObjectMapper(), uriInfo.getQueryParameters());

  TenantQuery query = queryDto.toQuery(getProcessEngine());
  long count = query.count();

  return new CountResultDto(count);
}
 
Example #18
Source File: TenantRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected List<Tenant> executePaginatedQuery(TenantQuery query, Integer firstResult, Integer maxResults) {
  if (firstResult == null) {
    firstResult = 0;
  }
  if (maxResults == null) {
    maxResults = Integer.MAX_VALUE;
  }
  return query.listPage(firstResult, maxResults);
}
 
Example #19
Source File: TenantRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected TenantQuery setUpMockQuery(Tenant tenant) {
  TenantQuery query = mock(TenantQuery.class);
  when(query.tenantId(anyString())).thenReturn(query);
  when(query.singleResult()).thenReturn(tenant);

  when(identityServiceMock.createTenantQuery()).thenReturn(query);

  return query;
}
 
Example #20
Source File: AuthenticationFilterPathMatchingTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected List<String> setupTenantQueryMock(List<Tenant> tenants) {
  TenantQuery mockTenantQuery = mock(TenantQuery.class);

  when(identityServiceMock.createTenantQuery()).thenReturn(mockTenantQuery);
  when(mockTenantQuery.userMember(anyString())).thenReturn(mockTenantQuery);
  when(mockTenantQuery.includingGroupsOfUser(anyBoolean())).thenReturn(mockTenantQuery);
  when(mockTenantQuery.list()).thenReturn(tenants);

  List<String> tenantIds = new ArrayList<String>();
  for(Tenant tenant: tenants) {
    tenantIds.add(tenant.getId());
  }
  return tenantIds;
}
 
Example #21
Source File: AbstractAuthenticationFilterTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected List<String> setupTenantQueryMock(List<Tenant> tenants) {
  TenantQuery mockTenantQuery = mock(TenantQuery.class);

  when(identityServiceMock.createTenantQuery()).thenReturn(mockTenantQuery);
  when(mockTenantQuery.userMember(anyString())).thenReturn(mockTenantQuery);
  when(mockTenantQuery.includingGroupsOfUser(anyBoolean())).thenReturn(mockTenantQuery);
  when(mockTenantQuery.list()).thenReturn(tenants);

  List<String> tenantIds = new ArrayList<String>();
  for(Tenant tenant: tenants) {
    tenantIds.add(tenant.getId());
  }
  return tenantIds;
}
 
Example #22
Source File: TenantRestServiceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private TenantQuery setUpMockQuery(List<Tenant> tenants) {
  TenantQuery query = mock(TenantQuery.class);
  when(query.list()).thenReturn(tenants);
  when(query.count()).thenReturn((long) tenants.size());

  when(processEngine.getIdentityService().createTenantQuery()).thenReturn(query);

  return query;
}
 
Example #23
Source File: IdentityServiceAuthorizationsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testTenantAuthorizationAfterDeleteUser() {
  // given jonny2 who is allowed to do user operations
  User jonny = identityService.newUser(jonny2);
  identityService.saveUser(jonny);

  grantPermissions();

  // turn on authorization
  processEngineConfiguration.setAuthorizationEnabled(true);
  identityService.setAuthenticatedUserId(jonny2);

  // create user
  User jonny1 = identityService.newUser("jonny1");
  identityService.saveUser(jonny1);
  String jonny1Id = jonny1.getId();

  // and tenant
  String tenant1 = "tenant1";
  Tenant tenant = identityService.newTenant(tenant1);
  identityService.saveTenant(tenant);
  identityService.createTenantUserMembership(tenant1, jonny1Id);

  // assume
  TenantQuery query = identityService.createTenantQuery().userMember(jonny1Id);
  assertThat(query.count(), is(1L));

  // when
  identityService.deleteUser(jonny1Id);

  // turn off authorization
  processEngineConfiguration.setAuthorizationEnabled(false);

  // then
  assertThat(query.count(), is(0L));
  assertThat(authorizationService.createAuthorizationQuery().resourceType(TENANT).userIdIn(jonny1Id).count(), is(0L));
}
 
Example #24
Source File: IdentityServiceAuthorizationsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testTenantAuthorizationAfterDeleteGroup() {
  // given jonny2 who is allowed to do group operations
  User jonny = identityService.newUser(jonny2);
  identityService.saveUser(jonny);

  grantPermissions();

  // turn on authorization
  processEngineConfiguration.setAuthorizationEnabled(true);
  identityService.setAuthenticatedUserId(jonny2);

  // create group
  Group group1 = identityService.newGroup("group1");
  identityService.saveGroup(group1);

  // and tenant
  String tenant1 = "tenant1";
  Tenant tenant = identityService.newTenant(tenant1);
  identityService.saveTenant(tenant);
  identityService.createTenantGroupMembership(tenant1, "group1");

  // assume
  TenantQuery query = identityService.createTenantQuery().groupMember("group1");
  assertThat(query.count(), is(1L));

  // when
  identityService.deleteGroup("group1");

  // turn off authorization
  processEngineConfiguration.setAuthorizationEnabled(false);

  // then
  assertThat(query.count(), is(0L));
  assertThat(authorizationService.createAuthorizationQuery().resourceType(TENANT).groupIdIn("group1").count(), is(0L));
}
 
Example #25
Source File: TenantQueryImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public TenantQuery groupMember(String groupId) {
  ensureNotNull("group id", groupId);
  this.groupId = groupId;
  return this;
}
 
Example #26
Source File: KeycloakIdentityProviderSession.java    From camunda-bpm-identity-keycloak with Apache License 2.0 4 votes vote down vote up
@Override
public TenantQuery createTenantQuery(CommandContext commandContext) {
	return new KeycloakTenantQuery();
}
 
Example #27
Source File: TenantQueryMock.java    From camunda-bpm-mockito with Apache License 2.0 4 votes vote down vote up
public TenantQueryMock() {
 super(TenantQuery.class, IdentityService.class);
}
 
Example #28
Source File: LdapIdentityProviderSession.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public TenantQuery createTenantQuery() {
  return new LdapTenantQuery(org.camunda.bpm.engine.impl.context.Context.getProcessEngineConfiguration().getCommandExecutorTxRequired());
}
 
Example #29
Source File: LdapIdentityProviderSession.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public TenantQuery createTenantQuery(CommandContext commandContext) {
  return new LdapTenantQuery();
}
 
Example #30
Source File: IdentityServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public TenantQuery createTenantQuery() {
  return commandExecutor.execute(new CreateTenantQueryCmd());
}