Skip to content

Commit 30f4671

Browse files
authored
Merge pull request #40 from myndocs/release/0.3.1
Release/0.3.1
2 parents 84c29b6 + d462020 commit 30f4671

File tree

15 files changed

+65
-13
lines changed

15 files changed

+65
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It encourages to adapt to existing implementations instead the other way around.
1111
First define the version to be used and set it as a property
1212
```xml
1313
<properties>
14-
<myndocs.oauth.version>0.3.0</myndocs.oauth.version>
14+
<myndocs.oauth.version>0.3.1</myndocs.oauth.version>
1515
</properties>
1616
```
1717

oauth2-server-client-inmemory/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>kotlin-oauth2-server</artifactId>
77
<groupId>nl.myndocs</groupId>
8-
<version>0.3.0</version>
8+
<version>0.3.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

oauth2-server-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>kotlin-oauth2-server</artifactId>
77
<groupId>nl.myndocs</groupId>
8-
<version>0.3.0</version>
8+
<version>0.3.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

oauth2-server-core/src/main/java/nl/myndocs/oauth2/CallRouter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class CallRouter(
213213
return
214214
}
215215

216-
val authorization = callContext.headers["Authorization"]
216+
val authorization = callContext.headerCaseInsensitive("Authorization")
217217

218218
if (authorization == null || !authorization.startsWith("bearer ", true)) {
219219
callContext.respondStatus(STATUS_UNAUTHORIZED)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package nl.myndocs.oauth2.request
2+
3+
fun CallContext.headerCaseInsensitive(key: String) =
4+
headers
5+
.filter { it.key.equals(key, true) }
6+
.values
7+
.firstOrNull()

oauth2-server-core/src/main/java/nl/myndocs/oauth2/request/auth/BasicAuthorizer.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ package nl.myndocs.oauth2.request.auth
33
import nl.myndocs.oauth2.authenticator.Authorizer
44
import nl.myndocs.oauth2.authenticator.Credentials
55
import nl.myndocs.oauth2.request.CallContext
6+
import nl.myndocs.oauth2.request.headerCaseInsensitive
67

8+
// @TODO: BasicAuth should be injected instead of static call
79
open class BasicAuthorizer(protected val context: CallContext) : Authorizer {
810
override fun extractCredentials(): Credentials? {
9-
val authorizationHeader = context.headers["authorization"] ?: ""
11+
val authorizationHeader = context.headerCaseInsensitive("authorization") ?: ""
12+
1013
return BasicAuth.parseCredentials(authorizationHeader)
1114
}
1215

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package nl.myndocs.oauth2.request.auth
2+
3+
import io.mockk.every
4+
import io.mockk.mockk
5+
import nl.myndocs.oauth2.request.CallContext
6+
import org.hamcrest.CoreMatchers.*
7+
import org.hamcrest.MatcherAssert.assertThat
8+
import org.junit.jupiter.api.Test
9+
import java.util.*
10+
11+
internal class BasicAuthorizerTest {
12+
13+
@Test
14+
fun `test authorization head is case insensitive with all uppercase input`() {
15+
`test authorization head is case insensitive with input`(
16+
"AUTHORIZATION"
17+
)
18+
}
19+
20+
@Test
21+
fun `test authorization head is case insensitive with all lowercase input`() {
22+
`test authorization head is case insensitive with input`(
23+
"authorization"
24+
)
25+
}
26+
27+
private fun `test authorization head is case insensitive with input`(authorizationKeyName: String) {
28+
val callContext = mockk<CallContext>()
29+
val username = "test"
30+
val password = "test-password"
31+
32+
val testCredentials = Base64.getEncoder().encodeToString("$username:$password".toByteArray())
33+
34+
every { callContext.headers } returns mapOf(authorizationKeyName to "basic $testCredentials")
35+
val credentials = BasicAuthorizer(callContext)
36+
.extractCredentials()
37+
38+
assertThat(credentials, `is`(notNullValue()))
39+
assertThat(credentials!!.username, `is`(equalTo(username)))
40+
assertThat(credentials.password, `is`(equalTo(password)))
41+
}
42+
}

oauth2-server-http4k/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>kotlin-oauth2-server</artifactId>
77
<groupId>nl.myndocs</groupId>
8-
<version>0.3.0</version>
8+
<version>0.3.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

oauth2-server-identity-inmemory/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>kotlin-oauth2-server</artifactId>
77
<groupId>nl.myndocs</groupId>
8-
<version>0.3.0</version>
8+
<version>0.3.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

oauth2-server-javalin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>kotlin-oauth2-server</artifactId>
77
<groupId>nl.myndocs</groupId>
8-
<version>0.3.0</version>
8+
<version>0.3.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

0 commit comments

Comments
 (0)