use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class JdbcRoleRepository method search.
@Override
public Single<Page<Role>> search(ReferenceType referenceType, String referenceId, String query, int page, int size) {
LOGGER.debug("search({}, {}, {}, {}, {})", referenceType, referenceId, query, page, size);
boolean wildcardSearch = query.contains("*");
String wildcardValue = query.replaceAll("\\*+", "%");
String search = this.databaseDialectHelper.buildSearchRoleQuery(wildcardSearch, page, size);
String count = this.databaseDialectHelper.buildCountRoleQuery(wildcardSearch);
return fluxToFlowable(template.getDatabaseClient().sql(search).bind("value", wildcardSearch ? wildcardValue : query).bind("refId", referenceId).bind("refType", referenceType.name()).map(row -> rowMapper.read(JdbcRole.class, row)).all()).map(this::toEntity).flatMap(role -> completeWithScopes(Maybe.just(role), role.getId()).toFlowable()).toList().flatMap(data -> monoToSingle(template.getDatabaseClient().sql(count).bind("value", wildcardSearch ? wildcardValue : query).bind("refId", referenceId).bind("refType", referenceType.name()).map(row -> row.get(0, Long.class)).first()).map(total -> new Page<Role>(data, page, total)));
}
use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class GroupServiceTest method shouldFindByDomainPagination.
@Test
public void shouldFindByDomainPagination() {
Page pagedGroups = new Page(Collections.singleton(new Group()), 1, 1);
when(groupRepository.findAll(ReferenceType.DOMAIN, DOMAIN, 1, 1)).thenReturn(Single.just(pagedGroups));
TestObserver<Page<Group>> testObserver = groupService.findByDomain(DOMAIN, 1, 1).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertValue(extensionGrants -> extensionGrants.getData().size() == 1);
}
use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class DomainServiceTest method shouldDeleteWithoutRelatedData.
@Test
public void shouldDeleteWithoutRelatedData() {
when(domainRepository.findById(DOMAIN_ID)).thenReturn(Maybe.just(domain));
when(domainRepository.delete(DOMAIN_ID)).thenReturn(Completable.complete());
when(applicationService.findByDomain(DOMAIN_ID)).thenReturn(Single.just(Collections.emptySet()));
when(certificateService.findByDomain(DOMAIN_ID)).thenReturn(Flowable.empty());
when(identityProviderService.findByDomain(DOMAIN_ID)).thenReturn(Flowable.empty());
when(extensionGrantService.findByDomain(DOMAIN_ID)).thenReturn(Flowable.empty());
when(roleService.findByDomain(DOMAIN_ID)).thenReturn(Single.just(Collections.emptySet()));
when(scopeService.findByDomain(DOMAIN_ID, 0, Integer.MAX_VALUE)).thenReturn(Single.just(new Page<>(Collections.emptySet(), 0, 1)));
when(userService.deleteByDomain(DOMAIN_ID)).thenReturn(Completable.complete());
when(groupService.findByDomain(DOMAIN_ID)).thenReturn(Flowable.empty());
when(formService.findByDomain(DOMAIN_ID)).thenReturn(Flowable.empty());
when(emailTemplateService.findAll(ReferenceType.DOMAIN, DOMAIN_ID)).thenReturn(Flowable.empty());
when(reporterService.findByDomain(DOMAIN_ID)).thenReturn(Flowable.empty());
when(flowService.findAll(ReferenceType.DOMAIN, DOMAIN_ID)).thenReturn(Flowable.empty());
when(membershipService.findByReference(DOMAIN_ID, ReferenceType.DOMAIN)).thenReturn(Flowable.empty());
when(factorService.findByDomain(DOMAIN_ID)).thenReturn(Flowable.empty());
when(resourceService.findByDomain(DOMAIN_ID)).thenReturn(Single.just(Collections.emptySet()));
when(alertTriggerService.findByDomainAndCriteria(DOMAIN_ID, new AlertTriggerCriteria())).thenReturn(Flowable.empty());
when(alertNotifierService.findByDomainAndCriteria(DOMAIN_ID, new AlertNotifierCriteria())).thenReturn(Flowable.empty());
when(authenticationDeviceNotifierService.findByDomain(DOMAIN_ID)).thenReturn(Flowable.empty());
when(eventService.create(any())).thenReturn(Single.just(new Event()));
TestObserver testObserver = domainService.delete(DOMAIN_ID).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
verify(applicationService, never()).delete(anyString());
verify(certificateService, never()).delete(anyString());
verify(identityProviderService, never()).delete(anyString(), anyString());
verify(extensionGrantService, never()).delete(anyString(), anyString());
verify(roleService, never()).delete(eq(ReferenceType.DOMAIN), eq(DOMAIN_ID), anyString());
verify(scopeService, never()).delete(anyString(), anyBoolean());
verify(formService, never()).delete(anyString(), anyString());
verify(emailTemplateService, never()).delete(anyString());
verify(reporterService, never()).delete(anyString());
verify(flowService, never()).delete(anyString());
verify(membershipService, never()).delete(anyString());
verify(factorService, never()).delete(anyString(), anyString());
verify(alertTriggerService, never()).delete(any(ReferenceType.class), anyString(), anyString(), any(io.gravitee.am.identityprovider.api.User.class));
verify(alertNotifierService, never()).delete(any(ReferenceType.class), anyString(), anyString(), any(io.gravitee.am.identityprovider.api.User.class));
verify(eventService, times(1)).create(any());
}
use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class ApplicationsResource method list.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List registered applications for a security domain", notes = "User must have the APPLICATION[LIST] permission on the specified domain, environment or organization " + "AND either APPLICATION[READ] permission on each domain's application " + "or APPLICATION[READ] permission on the specified domain " + "or APPLICATION[READ] permission on the specified environment " + "or APPLICATION[READ] permission on the specified organization. " + "Each returned application is filtered and contains only basic information such as id, name, description and isEnabled.")
@ApiResponses({ @ApiResponse(code = 200, message = "List registered applications for a security domain", response = Application.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
public void list(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @QueryParam("page") @DefaultValue("0") int page, @QueryParam("size") @DefaultValue(MAX_APPLICATIONS_SIZE_PER_PAGE_STRING) int size, @QueryParam("q") String query, @Suspended final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domain, Permission.APPLICATION, Acl.LIST).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(__ -> {
if (query != null) {
return applicationService.search(domain, query, 0, Integer.MAX_VALUE);
} else {
return applicationService.findByDomain(domain, 0, Integer.MAX_VALUE);
}
}).flatMap(pagedApplications -> Maybe.concat(pagedApplications.getData().stream().map(application -> hasAnyPermission(authenticatedUser, organizationId, environmentId, domain, application.getId(), Permission.APPLICATION, Acl.READ).filter(Boolean::booleanValue).map(__ -> filterApplicationInfos(application))).collect(Collectors.toList())).sorted((a1, a2) -> a2.getUpdatedAt().compareTo(a1.getUpdatedAt())).toList().map(applications -> new Page<>(applications.stream().skip(page * size).limit(size).collect(Collectors.toList()), page, applications.size())))).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class AuditsResource method list.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List audit logs for the organization", notes = "User must have the ORGANIZATION_AUDIT[LIST] permission on the specified organization. " + "Except if user has ORGANIZATION_AUDIT[READ] permission on the organization, each returned audit is filtered and contains only basic information such as id, date, event, actor, target and status.")
@ApiResponses({ @ApiResponse(code = 200, message = "List audit logs for the platform", response = Audit.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
public void list(@PathParam("organizationId") String organizationId, @BeanParam AuditParam param, @Suspended final AsyncResponse response) {
AuditReportableCriteria.Builder queryBuilder = new AuditReportableCriteria.Builder().from(param.getFrom()).to(param.getTo()).status(param.getStatus()).user(param.getUser());
if (param.getType() != null) {
queryBuilder.types(Collections.singletonList(param.getType()));
}
User authenticatedUser = getAuthenticatedUser();
checkPermission(ReferenceType.ORGANIZATION, organizationId, Permission.ORGANIZATION_AUDIT, Acl.LIST).andThen(auditService.search(ReferenceType.ORGANIZATION, organizationId, queryBuilder.build(), param.getPage(), param.getSize()).flatMap(auditPage -> hasPermission(authenticatedUser, ReferenceType.ORGANIZATION, organizationId, Permission.ORGANIZATION_AUDIT, Acl.READ).map(hasPermission -> {
if (hasPermission) {
return auditPage;
} else {
return new Page<>(auditPage.getData().stream().map(FilterUtils::filterAuditInfos).collect(Collectors.toList()), auditPage.getCurrentPage(), auditPage.getTotalCount());
}
}))).subscribe(response::resume, response::resume);
}
Aggregations