Skip to content

Commit

Permalink
bli kvitt noen advarsler
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-olaveide committed Dec 1, 2023
1 parent 48b74c9 commit e977740
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal class OAuth2AccessTokenServiceTest {

@BeforeEach
fun setup() {
MockitoAnnotations.initMocks(this)
MockitoAnnotations.openMocks(this)
val oboCache = accessTokenResponseCache<OnBehalfOfGrantRequest>(10, 1)
val clientCredentialsCache = accessTokenResponseCache<ClientCredentialsGrantRequest>(10, 1)
val exchangeTokenCache = accessTokenResponseCache<TokenExchangeGrantRequest>(10, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class OnBehalfOfTokenClientTest {
@BeforeEach
@Throws(IOException::class)
fun setup() {
MockitoAnnotations.initMocks(this)
MockitoAnnotations.openMocks(this)
server = MockWebServer()
server!!.start()
tokenEndpointUrl = server!!.url(TOKEN_ENDPOINT).toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import org.springframework.web.client.RestOperations
constructor(builder: RestTemplateBuilder) :this(builder.build())


override fun post(req: OAuth2HttpRequest) =
override fun post(oAuth2HttpRequest: OAuth2HttpRequest) =
try {
restOperations.exchange(convert(req), OAuth2AccessTokenResponse::class.java).body
restOperations.exchange(convert(oAuth2HttpRequest), OAuth2AccessTokenResponse::class.java).body
} catch (e: HttpStatusCodeException) {
throw OAuth2ClientException("Received $e.statusCode from tokenendpoint $req.tokenEndpointUrl with responsebody $e.responseBodyAsString", e)
throw OAuth2ClientException("Received $e.statusCode from tokenendpoint $oAuth2HttpRequest.tokenEndpointUrl with responsebody $e.responseBodyAsString", e)
}

private fun convert(req: OAuth2HttpRequest) =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.security.token.support.core.validation;

import com.nimbusds.jose.jwk.source.JWKSourceBuilder;
import com.nimbusds.jose.jwk.source.RemoteJWKSet;
import com.nimbusds.jwt.JWT;
import no.nav.security.token.support.core.exceptions.JwtTokenValidatorException;
Expand Down Expand Up @@ -36,10 +37,10 @@ private ConfigurableJwtTokenValidator tokenValidator(String issuer, List<String>
return new ConfigurableJwtTokenValidator(
issuer,
optionalClaims,
new RemoteJWKSet<>(URI.create("https://someurl").toURL(), new MockResourceRetriever())
);
// JWKSourceBuilder.create(URI.create("https://someurl").toURL(),new MockResourceRetriever()).build());
new RemoteJWKSet<>(URI.create("https://someurl").toURL(), new MockResourceRetriever()));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.Objects;

@Path("local")
public class TestTokenGeneratorResource {
Expand Down Expand Up @@ -63,7 +64,7 @@ public Response addCookie(
SignedJWT token = JwtTokenGenerator.createSignedJWT(subject);
return Response.status(redirect == null ? Response.Status.OK : Response.Status.FOUND)
.location(redirect == null ? null : URI.create(redirect))
.cookie(new NewCookie(cookieName, token.serialize(), "/", "localhost", "", -1, false))
.cookie(new NewCookie.Builder(cookieName).value(token.serialize()).path("/").domain("localhost").maxAge(-1).secure(false).build())
.build();
}

Expand All @@ -72,7 +73,7 @@ public Response addCookie(
@Path("/jwks")
public String jwks() throws IOException {
return IOUtils.readInputStreamToString(
getClass().getResourceAsStream(JwkGenerator.DEFAULT_JWKSET_FILE),
Objects.requireNonNull(getClass().getResourceAsStream(JwkGenerator.DEFAULT_JWKSET_FILE)),
Charset.defaultCharset());
}

Expand All @@ -87,7 +88,7 @@ public JWKSet jwkSet() {
@GET
@Path("/metadata")
public String metadata() throws IOException {
return IOUtils.readInputStreamToString(getClass().getResourceAsStream("/metadata.json"),
return IOUtils.readInputStreamToString(Objects.requireNonNull(getClass().getResourceAsStream("/metadata.json")),
Charset.defaultCharset());
}

Expand Down Expand Up @@ -117,4 +118,4 @@ public String[] getParams() {
return params;
}
}
}
}

0 comments on commit e977740

Please sign in to comment.