Skip to content

Commit f2c29e3

Browse files
authored
Hexagon toolkit support (#62)
* Hexagon toolkit support * Hexagon toolkit correct version * Update hexagon with new setup
1 parent 89ef5aa commit f2c29e3

File tree

5 files changed

+169
-0
lines changed

5 files changed

+169
-0
lines changed

oauth2-server-hexagon/pom.xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>kotlin-oauth2-server</artifactId>
7+
<groupId>nl.myndocs</groupId>
8+
<version>0.5.1-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>oauth2-server-hexagon</artifactId>
13+
14+
<properties>
15+
<hexagon.version>1.0.0</hexagon.version>
16+
</properties>
17+
<dependencies>
18+
<dependency>
19+
<groupId>nl.myndocs</groupId>
20+
<artifactId>oauth2-server-core</artifactId>
21+
<version>${project.version}</version>
22+
<scope>provided</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.hexagonkt</groupId>
26+
<artifactId>port_http_server</artifactId>
27+
<version>${hexagon.version}</version>
28+
<scope>provided</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>nl.myndocs</groupId>
32+
<artifactId>oauth2-server-json</artifactId>
33+
<version>${project.version}</version>
34+
<classifier>shaded</classifier>
35+
</dependency>
36+
<dependency>
37+
<groupId>com.hexagonkt</groupId>
38+
<artifactId>http_server_jetty</artifactId>
39+
<version>${hexagon.version}</version>
40+
<scope>test</scope>
41+
</dependency>
42+
43+
44+
<dependency>
45+
<groupId>nl.myndocs</groupId>
46+
<artifactId>oauth2-server-integration-base</artifactId>
47+
<version>${project.version}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
</dependencies>
51+
52+
<repositories>
53+
<repository>
54+
<id>jcenter</id>
55+
<url>https://jcenter.bintray.com/</url>
56+
</repository>
57+
</repositories>
58+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package nl.myndocs.oauth2.hexagon
2+
3+
import com.hexagonkt.http.server.Router
4+
import com.hexagonkt.http.server.Server
5+
import nl.myndocs.oauth2.config.ConfigurationBuilder
6+
import nl.myndocs.oauth2.hexagon.request.HexagonCallContext
7+
8+
9+
fun Router.enableOauthServer(configurationCallback: ConfigurationBuilder.Configuration.() -> Unit) {
10+
val configuration = ConfigurationBuilder.build(configurationCallback)
11+
12+
val callRouter = configuration.callRouter
13+
14+
post(callRouter.tokenEndpoint) {
15+
callRouter.route(HexagonCallContext(this))
16+
}
17+
18+
get(callRouter.authorizeEndpoint) {
19+
callRouter.route(HexagonCallContext(this))
20+
}
21+
22+
post(callRouter.authorizeEndpoint) {
23+
callRouter.route(HexagonCallContext(this))
24+
}
25+
26+
get(callRouter.tokenInfoEndpoint) {
27+
callRouter.route(HexagonCallContext(this))
28+
}
29+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package nl.myndocs.oauth2.hexagon.request
2+
3+
import com.hexagonkt.http.server.Call
4+
import nl.myndocs.oauth2.json.JsonMapper
5+
import nl.myndocs.oauth2.request.CallContext
6+
import java.net.URLDecoder
7+
import java.nio.charset.StandardCharsets
8+
9+
class HexagonCallContext(val call: Call) : CallContext {
10+
override val path: String = call.request.path
11+
override val method: String = call.request.method.name
12+
override val headers: Map<String, String> = call.request.headers
13+
.mapValues { it.value.joinToString(";") }
14+
15+
override val queryParameters: Map<String, String> = (call.request
16+
.runCatching { queryString }
17+
.getOrNull() ?: "")
18+
.split("&")
19+
.filter { it.contains("=") }
20+
.map {
21+
val (key, value) = it.split("=")
22+
Pair(
23+
key.toLowerCase(),
24+
URLDecoder.decode(value, StandardCharsets.UTF_8.name())
25+
)
26+
}
27+
.toMap()
28+
29+
override val formParameters: Map<String, String> = call.parameters
30+
.mapValues { it.value.lastOrNull() }
31+
.filterValues { it != null }
32+
.mapValues { it.value!! }
33+
34+
override fun respondStatus(statusCode: Int) {
35+
call.response.status = statusCode
36+
}
37+
38+
override fun respondHeader(name: String, value: String) {
39+
call.response.setHeader(name, value)
40+
}
41+
42+
override fun respondJson(content: Any) {
43+
call.response.body = JsonMapper.toJson(content)
44+
}
45+
46+
override fun redirect(uri: String) {
47+
call.redirect(uri)
48+
}
49+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package nl.myndocs.oauth2.hexagon.integration
2+
3+
import com.hexagonkt.http.server.Server
4+
import com.hexagonkt.http.server.ServerPort
5+
import com.hexagonkt.http.server.jetty.JettyServletAdapter
6+
import com.hexagonkt.injection.InjectionManager.bindObject
7+
import nl.myndocs.oauth2.hexagon.enableOauthServer
8+
import nl.myndocs.oauth2.integration.BaseIntegrationTest
9+
import org.junit.jupiter.api.AfterEach
10+
import org.junit.jupiter.api.BeforeEach
11+
12+
internal class HexagonIntegrationTest : BaseIntegrationTest() {
13+
val server: Server by lazy {
14+
Server {
15+
// @TODO: open random port?
16+
enableOauthServer { configBuilder(this) }
17+
}
18+
}
19+
20+
@BeforeEach
21+
fun before() {
22+
bindObject<ServerPort>(JettyServletAdapter())
23+
server.start()
24+
25+
localPort = server.bindPort
26+
}
27+
28+
@AfterEach
29+
fun after() {
30+
server.stop()
31+
}
32+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<module>oauth2-server-sparkjava</module>
2828
<module>oauth2-server-http4k</module>
2929
<module>oauth2-server-jwt</module>
30+
<module>oauth2-server-hexagon</module>
3031
</modules>
3132

3233
<dependencies>

0 commit comments

Comments
 (0)