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.
1111First 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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 )
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
33import nl.myndocs.oauth2.authenticator.Authorizer
44import nl.myndocs.oauth2.authenticator.Credentials
55import nl.myndocs.oauth2.request.CallContext
6+ import nl.myndocs.oauth2.request.headerCaseInsensitive
67
8+ // @TODO: BasicAuth should be injected instead of static call
79open 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
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 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments