Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upped deps and formatted according to new linter rules #6

Merged
merged 1 commit into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import java.time.Duration

val assertjVersion = "3.14.0"
val kotlinLoggingVersion = "1.7.8"
val assertjVersion = "3.17.2"
val kotlinLoggingVersion = "1.8.3"
val logbackVersion = "1.2.3"
val nimbusSdkVersion = "6.23"
val mockWebServerVersion = "4.3.1"
val jacksonVersion = "2.10.1"
val junitJupiterVersion = "5.5.2"
val nimbusSdkVersion = "8.19.1"
val mockWebServerVersion = "4.8.1"
val jacksonVersion = "2.11.2"
val junitJupiterVersion = "5.7.0-RC1"
val konfigVersion = "1.6.10.0"
val kotlinVersion = "1.3.61"
val freemarkerVersion = "2.3.29"
val kotlinVersion = "1.4.0"
val freemarkerVersion = "2.3.30"
val mavenRepoBaseUrl = "https://oss.sonatype.org"
val mainClassKt = "no.nav.security.mock.oauth2.StandaloneMockOAuth2ServerKt"

plugins {
application
kotlin("jvm") version "1.3.61"
id("org.jmailen.kotlinter") version "2.2.0"
id("com.google.cloud.tools.jib") version "2.0.0"
id("com.github.johnrengelman.shadow") version "5.2.0"
kotlin("jvm") version "1.4.0"
id("org.jmailen.kotlinter") version "3.0.2"
id("com.google.cloud.tools.jib") version "2.5.0"
id("com.github.johnrengelman.shadow") version "6.0.0"
id("net.researchgate.release") version "2.8.1"
id("io.codearte.nexus-staging") version "0.21.2"
id("io.codearte.nexus-staging") version "0.22.0"
id("de.marcphilipp.nexus-publish") version "0.4.0"
`java-library`
`maven-publish`
Expand Down Expand Up @@ -206,6 +206,10 @@ tasks {
}
}

withType<Wrapper> {
gradleVersion = "6.6.1"
}

/*withType<PublishToMavenRepository> {
finalizedBy("closeAndReleaseRepository")
}*/
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 2 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Sun Jan 26 20:25:21 CET 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 2 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
189 changes: 89 additions & 100 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,100 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@ private fun HttpUrl.resolvePath(path: String): HttpUrl {
.host(this.host)
.port(this.port)
.build()
.resolve(path.removePrefix("/")) ?: throw OAuth2Exception(
OAuth2Error.INVALID_REQUEST,
"cannot resolve path $path"
)
.resolve(path.removePrefix("/")) ?: throw OAuth2Exception(OAuth2Error.INVALID_REQUEST, "cannot resolve path $path")
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fun TokenRequest.authorizationCode(): AuthorizationCode =

fun TokenRequest.clientIdAsString(): String =
this.clientAuthentication?.clientID?.value ?: this.clientID?.value
?: throw OAuth2Exception(OAuth2Error.INVALID_CLIENT, "client_id cannot be null")
?: throw OAuth2Exception(OAuth2Error.INVALID_CLIENT, "client_id cannot be null")

fun SignedJWT.expiresIn(): Int =
Duration.between(Instant.now(), this.jwtClaimsSet.expirationTime.toInstant()).seconds.toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class AuthorizationCodeHandler(
)
}
else -> throw OAuth2Exception(
OAuth2Error.INVALID_GRANT, "hybrid og implicit flow not supported (yet)."
OAuth2Error.INVALID_GRANT,
"hybrid og implicit flow not supported (yet)."
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ class OAuth2HttpRequestHandler(
log.error("received exception when handling request.", error)
val errorObject: ErrorObject = when (error) {
is OAuth2Exception -> error.errorObject
is ParseException -> error.errorObject
?: OAuth2Error.INVALID_REQUEST
.appendDescription(". received exception message: ${error.message}")
is ParseException ->
error.errorObject
?: OAuth2Error.INVALID_REQUEST
.appendDescription(". received exception message: ${error.message}")
is GeneralException -> error.errorObject
else -> null
} ?: OAuth2Error.SERVER_ERROR
Expand All @@ -143,12 +144,14 @@ class OAuth2HttpRequestHandler(
if (authenticationRequest.responseType.impliesCodeFlow()) {
(grantHandlers[GrantType.AUTHORIZATION_CODE] as AuthorizationCodeHandler)
} else throw OAuth2Exception(
OAuth2Error.INVALID_GRANT, "hybrid og implicit flow not supported (yet)."
OAuth2Error.INVALID_GRANT,
"hybrid og implicit flow not supported (yet)."
)

private fun grantHandler(tokenRequest: TokenRequest): GrantHandler =
grantHandlers[tokenRequest.grantType()] ?: throw OAuth2Exception(
OAuth2Error.INVALID_GRANT, "grant_type ${tokenRequest.grantType()} not supported."
OAuth2Error.INVALID_GRANT,
"grant_type ${tokenRequest.grantType()} not supported."
)

private fun wellKnown(request: OAuth2HttpRequest): WellKnown =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,23 @@ data class OAuth2TokenResponse(

fun json(anyObject: Any): OAuth2HttpResponse = OAuth2HttpResponse(
headers = Headers.headersOf(
OAuth2HttpResponse.ContentType.HEADER, OAuth2HttpResponse.ContentType.JSON
OAuth2HttpResponse.ContentType.HEADER,
OAuth2HttpResponse.ContentType.JSON
),
status = 200,
body = when (anyObject) {
is String -> anyObject
else -> objectMapper
.enable(SerializationFeature.INDENT_OUTPUT)
.writeValueAsString(anyObject)
else ->
objectMapper
.enable(SerializationFeature.INDENT_OUTPUT)
.writeValueAsString(anyObject)
}
)

fun html(content: String): OAuth2HttpResponse = OAuth2HttpResponse(
headers = Headers.headersOf(
OAuth2HttpResponse.ContentType.HEADER, OAuth2HttpResponse.ContentType.HTML
OAuth2HttpResponse.ContentType.HEADER,
OAuth2HttpResponse.ContentType.HTML
),
status = 200,
body = content
Expand Down Expand Up @@ -109,7 +112,8 @@ fun oauth2Error(error: ErrorObject): OAuth2HttpResponse {
val responseCode = error.httpStatusCode.takeUnless { it == 302 } ?: 400
return OAuth2HttpResponse(
headers = Headers.headersOf(
OAuth2HttpResponse.ContentType.HEADER, OAuth2HttpResponse.ContentType.JSON
OAuth2HttpResponse.ContentType.HEADER,
OAuth2HttpResponse.ContentType.JSON
),
status = responseCode,
body = objectMapper
Expand Down
Loading