aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/build.gradle2
-rw-r--r--app/src/main/java/org/onap/portal/prefs/util/IdTokenExchange.java43
-rw-r--r--app/src/test/java/org/onap/portal/prefs/BaseIntegrationTest.java12
-rw-r--r--app/src/test/java/org/onap/portal/prefs/TokenGenerator.java6
-rw-r--r--openapi/build.gradle4
5 files changed, 27 insertions, 40 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 6fa8258..a640b59 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -35,7 +35,6 @@ repositories {
}
ext {
- vavrVersion = '0.10.4'
problemVersion = '0.27.1'
logstashLogbackVersion = '7.2'
embedMongoVersion = '3.2.8'
@@ -51,7 +50,6 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-validation'
- implementation "io.vavr:vavr:$vavrVersion"
implementation "org.zalando:problem:$problemVersion"
implementation "net.logstash.logback:logstash-logback-encoder:$logstashLogbackVersion"
diff --git a/app/src/main/java/org/onap/portal/prefs/util/IdTokenExchange.java b/app/src/main/java/org/onap/portal/prefs/util/IdTokenExchange.java
index 20f1581..9ac2794 100644
--- a/app/src/main/java/org/onap/portal/prefs/util/IdTokenExchange.java
+++ b/app/src/main/java/org/onap/portal/prefs/util/IdTokenExchange.java
@@ -21,12 +21,12 @@
package org.onap.portal.prefs.util;
+import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.JWTParser;
-import io.vavr.control.Option;
-import io.vavr.control.Try;
+
+import java.text.ParseException;
+
import org.springframework.web.server.ServerWebExchange;
-import org.zalando.problem.Problem;
-import org.zalando.problem.Status;
import reactor.core.publisher.Mono;
/**
@@ -49,11 +49,9 @@ public final class IdTokenExchange {
* @return the identity header in the form of <code>Bearer {@literal <Token>}<c/ode>
*/
private static Mono<String> extractIdentityHeader(ServerWebExchange exchange) {
- return io.vavr.collection.List.ofAll(
- exchange.getRequest().getHeaders().getOrEmpty(X_AUTH_IDENTITY_HEADER))
- .headOption()
- .map(Mono::just)
- .getOrElse(Mono.error(Problem.valueOf(Status.FORBIDDEN, "ID token is missing")));
+ return Mono.just(exchange.getRequest().getHeaders().getOrEmpty(X_AUTH_IDENTITY_HEADER))
+ .map(headers -> headers.get(0))
+ .onErrorResume(Exception.class, ex -> Mono.error(ex));
}
/**
@@ -73,19 +71,18 @@ public final class IdTokenExchange {
* @return the id of the user
*/
public static Mono<String> extractUserId(ServerWebExchange exchange) {
- return extractIdToken(exchange)
- .flatMap(
- idToken ->
- Try.of(() -> JWTParser.parse(idToken))
- .mapTry(jwt -> Option.of(jwt.getJWTClaimsSet()))
- .map(
- optionJwtClaimSet ->
- optionJwtClaimSet
- .flatMap(
- jwtClaimSet ->
- Option.of(jwtClaimSet.getClaim(JWT_CLAIM_USERID)))
- .map(String.class::cast)
- .map( Mono::just).get())
- .getOrElseGet(Mono::error));
+ return extractIdToken(exchange)
+ .flatMap(idToken -> extractUserClaim(idToken));
+ }
+
+ private static Mono<String> extractUserClaim(String idToken) {
+ JWTClaimsSet jwtClaimSet;
+ try {
+ jwtClaimSet = JWTParser.parse(idToken).getJWTClaimsSet();
+ } catch (ParseException e) {
+ return Mono.error(e);
+ }
+ return Mono.just(String.class.cast(jwtClaimSet.getClaim(JWT_CLAIM_USERID)));
}
}
+
diff --git a/app/src/test/java/org/onap/portal/prefs/BaseIntegrationTest.java b/app/src/test/java/org/onap/portal/prefs/BaseIntegrationTest.java
index 7852c41..104b683 100644
--- a/app/src/test/java/org/onap/portal/prefs/BaseIntegrationTest.java
+++ b/app/src/test/java/org/onap/portal/prefs/BaseIntegrationTest.java
@@ -30,16 +30,16 @@ import io.restassured.RestAssured;
import io.restassured.filter.log.RequestLoggingFilter;
import io.restassured.filter.log.ResponseLoggingFilter;
import io.restassured.specification.RequestSpecification;
-import io.vavr.collection.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
import org.springframework.http.MediaType;
+import java.util.List;
import java.util.UUID;
/** Base class for all tests that has the common config including port, realm, logging and auth. */
@@ -47,14 +47,6 @@ import java.util.UUID;
@AutoConfigureWireMock(port = 0)
public abstract class BaseIntegrationTest {
-// @TestConfiguration
-// public static class Config {
-// @Bean
-// WireMockConfigurationCustomizer optionsCustomizer() {
-// return options -> options.extensions(new ResponseTemplateTransformer(true));
-// }
-// }
-
@LocalServerPort protected int port;
@Value("${portal-prefs.realm}")
protected String realm;
diff --git a/app/src/test/java/org/onap/portal/prefs/TokenGenerator.java b/app/src/test/java/org/onap/portal/prefs/TokenGenerator.java
index 6883064..fb3a522 100644
--- a/app/src/test/java/org/onap/portal/prefs/TokenGenerator.java
+++ b/app/src/test/java/org/onap/portal/prefs/TokenGenerator.java
@@ -24,7 +24,9 @@ package org.onap.portal.prefs;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
+import java.util.Collections;
import java.util.Date;
+import java.util.List;
import java.util.UUID;
import com.nimbusds.jose.JOSEObjectType;
@@ -42,7 +44,6 @@ import com.nimbusds.jwt.SignedJWT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import io.vavr.collection.List;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
@@ -58,7 +59,6 @@ public class TokenGenerator {
private final JWKSet jwkSet;
private final JWSSigner signer;
- @Autowired
public TokenGenerator(Clock clock) {
try {
this.clock = clock;
@@ -121,7 +121,7 @@ public class TokenGenerator {
@NonNull @Builder.Default private final Duration expireIn = Duration.ofMinutes(5);
- @Builder.Default private final List<String> roles = List.empty();
+ @Builder.Default private final List<String> roles = Collections.emptyList();
public String issuer() {
return String.format("http://localhost:%d/auth/realms/%s", port, realm);
diff --git a/openapi/build.gradle b/openapi/build.gradle
index f1e04b3..11c0592 100644
--- a/openapi/build.gradle
+++ b/openapi/build.gradle
@@ -26,14 +26,14 @@ openApiGenerate {
inputSpec = "$projectDir/src/main/resources/api/api.yml"
outputDir = "$buildDir/openapi"
configOptions = [
+ hideGenerationTimestamp: "true",
openApiNullable: "false",
skipDefaultInterface: "true",
dateLibrary: "java8",
interfaceOnly: "true",
useTags: "true",
useOptional: "true",
- reactive: "true",
- hideGenerationTimestamp: "true"
+ reactive: "true"
]
generateApiTests = false
generateApiDocumentation = false