Skip to content

Commit

Permalink
Revert "Upgrade to Micronaut 3.1.4 (#112)"
Browse files Browse the repository at this point in the history
This reverts commit 685eb2b
  • Loading branch information
twobeeb committed Dec 1, 2021
1 parent 0313c4a commit b69570a
Show file tree
Hide file tree
Showing 74 changed files with 218 additions and 241 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: DeLaGuardo/[email protected]
with:
graalvm: '21.3.0'
graalvm: '21.1.0'
java: 'java11'
- name: Install Native Image
run: gu install native-image
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/on_push_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: DeLaGuardo/[email protected]
with:
graalvm: '21.3.0'
graalvm: '21.1.0'
java: 'java11'
- name: Install Native Image
run: gu install native-image
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: DeLaGuardo/[email protected]
with:
graalvm: '21.3.0'
graalvm: '20.3.2'
java: 'java11'
- name: Install Native Image
run: ${{ env.JAVA_HOME }}\bin\gu.cmd install native-image
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/on_push_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: DeLaGuardo/[email protected]
with:
graalvm: '21.3.0'
graalvm: '21.1.0'
java: 'java11'
- name: Install Native Image
run: gu install native-image
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: DeLaGuardo/[email protected]
with:
graalvm: '21.3.0'
graalvm: '20.3.2'
java: 'java11'
- name: Install Native Image
run: ${{ env.JAVA_HOME }}\bin\gu.cmd install native-image
Expand Down
6 changes: 1 addition & 5 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ micronaut {

dependencies {
compileOnly 'org.projectlombok:lombok:1.18.20'
compileOnly("com.google.code.findbugs:jsr305")

annotationProcessor 'org.projectlombok:lombok:1.18.20'
annotationProcessor("io.micronaut.openapi:micronaut-openapi")
annotationProcessor("io.micronaut:micronaut-management")
annotationProcessor("io.micronaut.security:micronaut-security-annotations")
annotationProcessor("io.swagger.core.v3:swagger-annotations")
annotationProcessor("io.micronaut:micronaut-http-validation")

implementation("io.micronaut:micronaut-validation")
implementation("io.micronaut:micronaut-runtime")
implementation("io.micronaut.rxjava3:micronaut-rxjava3")
implementation("javax.annotation:javax.annotation-api")
implementation("io.micronaut:micronaut-http-client")
implementation("io.micronaut.openapi:micronaut-openapi")
Expand All @@ -47,7 +43,7 @@ dependencies {
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
testCompileOnly 'org.projectlombok:lombok:1.18.16'

testImplementation("io.micronaut.rxjava3:micronaut-rxjava3-http-client:2.0.0")

testImplementation 'org.testcontainers:kafka:1.15.3'
testImplementation "org.testcontainers:junit-jupiter"
testImplementation 'org.mockito:mockito-inline:3.7.7'
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/com/michelin/ns4kafka/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.micronaut.openapi.annotation.OpenAPIInclude;
import io.micronaut.runtime.Micronaut;
import io.reactivex.plugins.RxJavaPlugins;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
Expand Down Expand Up @@ -29,6 +30,7 @@
public class Application {

public static void main(String[] args) {
RxJavaPlugins.setErrorHandler(throwable -> {});
Micronaut.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import jakarta.inject.Inject;
import javax.inject.Inject;
import javax.validation.Valid;
import java.time.Instant;
import java.util.Comparator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import lombok.Getter;

import javax.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
import javax.inject.Inject;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.micronaut.scheduling.annotation.ExecuteOn;
import io.swagger.v3.oas.annotations.tags.Tag;

import jakarta.inject.Inject;
import javax.inject.Inject;
import javax.validation.Valid;
import java.time.Instant;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.kafka.common.TopicPartition;

import jakarta.inject.Inject;
import javax.inject.Inject;
import javax.validation.Valid;
import java.time.Instant;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;

import javax.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
import javax.inject.Inject;
import javax.validation.Valid;
import java.time.Instant;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.michelin.ns4kafka.models.Namespace;
import com.michelin.ns4kafka.services.NamespaceService;

import jakarta.inject.Inject;
import javax.inject.Inject;

/**
* Base Controller for all Namespaced resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.micronaut.http.HttpResponse;
import io.micronaut.security.utils.SecurityService;

import jakarta.inject.Inject;
import javax.inject.Inject;
import java.time.Instant;
import java.util.Date;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.micronaut.scheduling.annotation.ExecuteOn;
import io.swagger.v3.oas.annotations.tags.Tag;

import jakarta.inject.Inject;
import javax.inject.Inject;
import javax.validation.Valid;
import java.time.Instant;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.micronaut.http.annotation.*;
import io.swagger.v3.oas.annotations.tags.Tag;

import jakarta.inject.Inject;
import javax.inject.Inject;
import javax.validation.Valid;
import java.time.Instant;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.kafka.common.TopicPartition;

import jakarta.inject.Inject;
import javax.inject.Inject;
import javax.validation.Valid;
import java.time.Instant;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.micronaut.core.util.StringUtils;
import lombok.extern.slf4j.Slf4j;

import jakarta.inject.Singleton;
import javax.inject.Singleton;

@Slf4j
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import io.micronaut.core.util.StringUtils;
import io.micronaut.scheduling.annotation.Async;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
@Requires(property = "ns4kafka.log.kafka.enabled", value = StringUtils.TRUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.inject.Inject;
import javax.inject.Inject;
import java.util.List;

@Slf4j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.producer.Producer;

import jakarta.inject.Singleton;
import javax.inject.Singleton;
import java.util.Collection;
import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.producer.Producer;

import jakarta.inject.Singleton;
import javax.inject.Singleton;
import java.util.List;
import java.util.stream.Collectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.producer.Producer;

import jakarta.inject.Singleton;
import javax.inject.Singleton;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.producer.Producer;

import jakarta.inject.Singleton;
import javax.inject.Singleton;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.apache.kafka.common.errors.TopicExistsException;

import javax.annotation.PostConstruct;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import javax.inject.Inject;
import javax.inject.Named;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;
import java.util.stream.Collectors;

import jakarta.inject.Singleton;
import javax.inject.Singleton;

import com.michelin.ns4kafka.models.KafkaStream;
import com.michelin.ns4kafka.repositories.StreamRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.producer.Producer;

import jakarta.inject.Singleton;
import javax.inject.Singleton;
import java.util.List;
import java.util.stream.Collectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@
import com.michelin.ns4kafka.repositories.NamespaceRepository;
import com.michelin.ns4kafka.repositories.RoleBindingRepository;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.core.async.publisher.Publishers;
import io.micronaut.core.util.StringUtils;
import io.micronaut.http.HttpRequest;
import io.micronaut.security.authentication.Authentication;
import io.micronaut.security.rules.SecurityRule;
import io.micronaut.security.rules.SecurityRuleResult;
import io.micronaut.web.router.RouteMatch;
import jakarta.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import org.reactivestreams.Publisher;

import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand All @@ -41,24 +39,18 @@ public ResourceBasedSecurityRule(SecurityConfig securityConfig, RoleBindingRepos
this.roleBindingRepository = roleBindingRepository;
this.namespaceRepository = namespaceRepository;
}
@Override
public Publisher<SecurityRuleResult> check(HttpRequest<?> request, @Nullable RouteMatch<?> routeMatch, @Nullable Authentication authentication) {
return Publishers.just(check_security(request, routeMatch, authentication));
}

public SecurityRuleResult check_security(HttpRequest<?> request, @Nullable RouteMatch<?> routeMatch, @Nullable Authentication authentication) {
@Override
public SecurityRuleResult check(HttpRequest<?> request, @Nullable RouteMatch<?> routeMatch, @Nullable Map<String, Object> claims) {
//Unauthenticated request
if(authentication == null){
return SecurityRuleResult.UNKNOWN;
}
if (!authentication.getAttributes().keySet().containsAll( List.of("groups", "sub", "roles"))) {
if (claims == null || !claims.keySet().containsAll( List.of("groups", "sub", "roles"))) {
log.debug("No Authentication available for path [{}]. Returning unknown.",request.getPath());
return SecurityRuleResult.UNKNOWN;
}

String sub = authentication.getName();
List<String> groups = (List<String>) authentication.getAttributes().get("groups");
Collection<String> roles = authentication.getRoles();
String sub = claims.get("sub").toString();
List<String> groups = (List<String>) claims.get("groups");
List<String> roles = (List<String>) claims.get("roles");

//Request to a URL that is not in the scope of this SecurityRule
Matcher matcher = namespacedResourcePattern.matcher(request.getPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Header;
import io.micronaut.http.client.annotation.Client;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.Flowable;

import java.util.List;
import java.util.Map;

import static io.micronaut.http.HttpRequest.GET;

@Client("${micronaut.security.gitlab.url}")
public interface GitlabApiClient {
@Get("/api/v4/groups?min_access_level=10&sort=asc&page={page}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.michelin.ns4kafka.security.gitlab;

import com.michelin.ns4kafka.security.ResourceBasedSecurityRule;
import io.micronaut.core.annotation.Nullable;
import edu.umd.cs.findbugs.annotations.Nullable;
import io.micronaut.http.HttpRequest;
import io.micronaut.security.authentication.*;
import io.reactivex.rxjava3.core.BackpressureStrategy;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.schedulers.Schedulers;
import lombok.extern.slf4j.Slf4j;
import org.reactivestreams.Publisher;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;
import java.util.Map;

Expand All @@ -35,7 +35,8 @@ public Publisher<AuthenticationResponse> authenticate(@Nullable HttpRequest<?> h
String username = gitlabAuthenticationService.findUsername(token).blockingGet();
List<String> groups = gitlabAuthenticationService.findAllGroups(token).toList().blockingGet();

AuthenticationResponse user = AuthenticationResponse.success(username, resourceBasedSecurityRule.computeRolesFromGroups(groups), Map.of("groups", groups));
UserDetails user = new UserDetails(username, resourceBasedSecurityRule.computeRolesFromGroups(groups), Map.of("groups", groups));

emitter.onNext(user);
emitter.onComplete();
}catch (Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

import io.micronaut.core.util.StringUtils;
import io.micronaut.http.HttpResponse;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Maybe;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import lombok.extern.slf4j.Slf4j;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static io.micronaut.http.HttpRequest.GET;

@Slf4j
@Singleton
public class GitlabAuthenticationService {
Expand Down
Loading

0 comments on commit b69570a

Please sign in to comment.