File tree Expand file tree Collapse file tree 15 files changed +65
-13
lines changed
oauth2-server-client-inmemory
main/java/nl/myndocs/oauth2
test/java/nl/myndocs/oauth2/request/auth
oauth2-server-identity-inmemory
oauth2-server-token-store-inmemory Expand file tree Collapse file tree 15 files changed +65
-13
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ It encourages to adapt to existing implementations instead the other way around.
11
11
First define the version to be used and set it as a property
12
12
``` xml
13
13
<properties >
14
- <myndocs .oauth.version>0.3.0 </myndocs .oauth.version>
14
+ <myndocs .oauth.version>0.3.1 </myndocs .oauth.version>
15
15
</properties >
16
16
```
17
17
Original file line number Diff line number Diff line change 5
5
<parent >
6
6
<artifactId >kotlin-oauth2-server</artifactId >
7
7
<groupId >nl.myndocs</groupId >
8
- <version >0.3.0 </version >
8
+ <version >0.3.1 </version >
9
9
</parent >
10
10
<modelVersion >4.0.0</modelVersion >
11
11
Original file line number Diff line number Diff line change 5
5
<parent >
6
6
<artifactId >kotlin-oauth2-server</artifactId >
7
7
<groupId >nl.myndocs</groupId >
8
- <version >0.3.0 </version >
8
+ <version >0.3.1 </version >
9
9
</parent >
10
10
<modelVersion >4.0.0</modelVersion >
11
11
Original file line number Diff line number Diff line change @@ -213,7 +213,7 @@ class CallRouter(
213
213
return
214
214
}
215
215
216
- val authorization = callContext.headers[ " Authorization" ]
216
+ val authorization = callContext.headerCaseInsensitive( " Authorization" )
217
217
218
218
if (authorization == null || ! authorization.startsWith(" bearer " , true )) {
219
219
callContext.respondStatus(STATUS_UNAUTHORIZED )
Original file line number Diff line number Diff line change
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()
Original file line number Diff line number Diff line change @@ -3,10 +3,13 @@ package nl.myndocs.oauth2.request.auth
3
3
import nl.myndocs.oauth2.authenticator.Authorizer
4
4
import nl.myndocs.oauth2.authenticator.Credentials
5
5
import nl.myndocs.oauth2.request.CallContext
6
+ import nl.myndocs.oauth2.request.headerCaseInsensitive
6
7
8
+ // @TODO: BasicAuth should be injected instead of static call
7
9
open class BasicAuthorizer (protected val context : CallContext ) : Authorizer {
8
10
override fun extractCredentials (): Credentials ? {
9
- val authorizationHeader = context.headers[" authorization" ] ? : " "
11
+ val authorizationHeader = context.headerCaseInsensitive(" authorization" ) ? : " "
12
+
10
13
return BasicAuth .parseCredentials(authorizationHeader)
11
14
}
12
15
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 5
5
<parent >
6
6
<artifactId >kotlin-oauth2-server</artifactId >
7
7
<groupId >nl.myndocs</groupId >
8
- <version >0.3.0 </version >
8
+ <version >0.3.1 </version >
9
9
</parent >
10
10
<modelVersion >4.0.0</modelVersion >
11
11
Original file line number Diff line number Diff line change 5
5
<parent >
6
6
<artifactId >kotlin-oauth2-server</artifactId >
7
7
<groupId >nl.myndocs</groupId >
8
- <version >0.3.0 </version >
8
+ <version >0.3.1 </version >
9
9
</parent >
10
10
<modelVersion >4.0.0</modelVersion >
11
11
Original file line number Diff line number Diff line change 5
5
<parent >
6
6
<artifactId >kotlin-oauth2-server</artifactId >
7
7
<groupId >nl.myndocs</groupId >
8
- <version >0.3.0 </version >
8
+ <version >0.3.1 </version >
9
9
</parent >
10
10
<modelVersion >4.0.0</modelVersion >
11
11
You can’t perform that action at this time.
0 commit comments