Search in sources :

Example 1 with Secured

use of io.micronaut.security.annotation.Secured in project akhq by tchiotludo.

the class TopicController method data.

@Secured(Role.ROLE_TOPIC_DATA_READ)
@Get("api/{cluster}/topic/{topicName}/data")
@Operation(tags = { "topic data" }, summary = "Read datas from a topic")
public ResultNextList<Record> data(HttpRequest<?> request, String cluster, String topicName, Optional<String> after, Optional<Integer> partition, Optional<RecordRepository.Options.Sort> sort, Optional<String> timestamp, Optional<String> searchByKey, Optional<String> searchByValue, Optional<String> searchByHeaderKey, Optional<String> searchByHeaderValue) throws ExecutionException, InterruptedException {
    Topic topic = this.topicRepository.findByName(cluster, topicName);
    RecordRepository.Options options = dataSearchOptions(cluster, topicName, after, partition, sort, timestamp, searchByKey, searchByValue, searchByHeaderKey, searchByHeaderValue);
    URIBuilder uri = URIBuilder.fromURI(request.getUri());
    List<Record> data = this.recordRepository.consume(cluster, options);
    return TopicDataResultNextList.of(data, options.after(data, uri), (options.getPartition() == null ? topic.getSize() : topic.getSize(options.getPartition())), this.isAllowed(Role.ROLE_TOPIC_DATA_DELETE) && topic.canDeleteRecords(cluster, configRepository));
}
Also used : URIBuilder(org.codehaus.httpcache4j.uri.URIBuilder) Secured(io.micronaut.security.annotation.Secured) Operation(io.swagger.v3.oas.annotations.Operation)

Example 2 with Secured

use of io.micronaut.security.annotation.Secured in project akhq by tchiotludo.

the class AkhqController method users.

@Secured(SecurityRule.IS_ANONYMOUS)
@Get("api/me")
@Operation(tags = { "AKHQ" }, summary = "Get current user")
public AuthUser users() {
    AuthUser authUser = new AuthUser();
    if (applicationContext.containsBean(SecurityService.class)) {
        SecurityService securityService = applicationContext.getBean(SecurityService.class);
        securityService.getAuthentication().ifPresent(authentication -> {
            authUser.logged = true;
            authUser.username = authentication.getName();
        });
    }
    authUser.roles = this.getRights();
    return authUser;
}
Also used : SecurityService(io.micronaut.security.utils.SecurityService) Secured(io.micronaut.security.annotation.Secured) Get(io.micronaut.http.annotation.Get) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

Secured (io.micronaut.security.annotation.Secured)2 Operation (io.swagger.v3.oas.annotations.Operation)2 Get (io.micronaut.http.annotation.Get)1 SecurityService (io.micronaut.security.utils.SecurityService)1 URIBuilder (org.codehaus.httpcache4j.uri.URIBuilder)1