Search in sources :

Example 1 with SecurityService

use of io.micronaut.security.utils.SecurityService in project akhq by tchiotludo.

the class ConnectRepository method getConnectFilterRegex.

private Optional<List<String>> getConnectFilterRegex() {
    List<String> connectFilterRegex = new ArrayList<>();
    if (applicationContext.containsBean(SecurityService.class)) {
        SecurityService securityService = applicationContext.getBean(SecurityService.class);
        Optional<Authentication> authentication = securityService.getAuthentication();
        if (authentication.isPresent()) {
            Authentication auth = authentication.get();
            connectFilterRegex.addAll(getConnectFilterRegexFromAttributes(auth.getAttributes()));
        }
    }
    // get Connect filter regex for default groups
    connectFilterRegex.addAll(getConnectFilterRegexFromAttributes(defaultGroupUtils.getDefaultAttributes()));
    return Optional.of(connectFilterRegex);
}
Also used : SecurityService(io.micronaut.security.utils.SecurityService) Authentication(io.micronaut.security.authentication.Authentication)

Example 2 with SecurityService

use of io.micronaut.security.utils.SecurityService in project akhq by tchiotludo.

the class TopicRepository method getTopicFilterRegex.

private Optional<List<String>> getTopicFilterRegex() {
    List<String> topicFilterRegex = new ArrayList<>();
    if (applicationContext.containsBean(SecurityService.class)) {
        SecurityService securityService = applicationContext.getBean(SecurityService.class);
        Optional<Authentication> authentication = securityService.getAuthentication();
        if (authentication.isPresent()) {
            Authentication auth = authentication.get();
            topicFilterRegex.addAll(getTopicFilterRegexFromAttributes(auth.getAttributes()));
        }
    }
    // get topic filter regex for default groups
    topicFilterRegex.addAll(getTopicFilterRegexFromAttributes(defaultGroupUtils.getDefaultAttributes()));
    return Optional.of(topicFilterRegex);
}
Also used : SecurityService(io.micronaut.security.utils.SecurityService) Authentication(io.micronaut.security.authentication.Authentication)

Example 3 with SecurityService

use of io.micronaut.security.utils.SecurityService in project akhq by tchiotludo.

the class ConsumerGroupRepository method getConsumerGroupFilterRegex.

private Optional<List<String>> getConsumerGroupFilterRegex() {
    List<String> consumerGroupFilterRegex = new ArrayList<>();
    if (applicationContext.containsBean(SecurityService.class)) {
        SecurityService securityService = applicationContext.getBean(SecurityService.class);
        Optional<Authentication> authentication = securityService.getAuthentication();
        if (authentication.isPresent()) {
            Authentication auth = authentication.get();
            consumerGroupFilterRegex.addAll(getConsumerGroupFilterRegexFromAttributes(auth.getAttributes()));
        }
    }
    // get consumer group filter regex for default groups
    consumerGroupFilterRegex.addAll(getConsumerGroupFilterRegexFromAttributes(defaultGroupUtils.getDefaultAttributes()));
    return Optional.of(consumerGroupFilterRegex);
}
Also used : SecurityService(io.micronaut.security.utils.SecurityService) Authentication(io.micronaut.security.authentication.Authentication)

Example 4 with SecurityService

use of io.micronaut.security.utils.SecurityService 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

SecurityService (io.micronaut.security.utils.SecurityService)4 Authentication (io.micronaut.security.authentication.Authentication)3 Get (io.micronaut.http.annotation.Get)1 Secured (io.micronaut.security.annotation.Secured)1 Operation (io.swagger.v3.oas.annotations.Operation)1