Skip to content
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
9 changes: 5 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ jobs:
packages: "write"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/cache@v2
with:
path: ~/.m2
key: "${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}"
restore-keys: |
${{ runner.os }}-maven-
- uses: actions/setup-java@v1
- uses: actions/setup-java@v4
with:
java-version: 14
distribution: temurin
java-version: 21
- name: Build
shell: bash
run: |
Expand All @@ -43,7 +44,7 @@ jobs:
deploy:
permissions:
contents: "read"
id-token: "write"
id-token: "write"
name: Deploy to NAIS
needs: build
if: github.ref == 'refs/heads/main'
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/sandbox.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build, push, and deploy
name: Build, push, and deploy sandbox

on:
push:
Expand All @@ -18,16 +18,17 @@ jobs:
packages: "write"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/cache@v2
with:
path: ~/.m2
key: "${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}"
restore-keys: |
${{ runner.os }}-maven-
- uses: actions/setup-java@v1
- uses: actions/setup-java@v4
with:
java-version: 14
distribution: temurin
java-version: 21
- name: Build
shell: bash
run: |
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# FROM navikt/java:14
FROM eclipse-temurin:17-jre
FROM eclipse-temurin:21-jre

RUN apt-get update && apt-get install -y \
curl \
Expand Down
69 changes: 50 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<description>REST service for getting data about employees/NAV-ansatte</description>

<properties>
<kotlin.version>1.4.21</kotlin.version>
<ktor.version>1.5.1</ktor.version>
<kotlin.version>2.0.20</kotlin.version>
<ktor.version>2.3.12</ktor.version>
<serialization.version>1.0.1</serialization.version>
</properties>

Expand Down Expand Up @@ -47,6 +47,10 @@
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-core-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-core</artifactId>
Expand All @@ -57,35 +61,55 @@
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-netty</artifactId>
<artifactId>ktor-server-host-common-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-netty-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-locations-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-auth-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-auth-jwt-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-call-id-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-locations</artifactId>
<artifactId>ktor-server-content-negotiation-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-auth</artifactId>
<artifactId>ktor-server-status-pages-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-auth-jwt</artifactId>
<artifactId>ktor-serialization-kotlinx-json-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-serialization</artifactId>
<artifactId>ktor-client-apache-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-apache</artifactId>
<artifactId>ktor-client-content-negotiation-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-serialization-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-metrics-micrometer</artifactId>
<artifactId>ktor-server-metrics-micrometer-jvm</artifactId>
</dependency>


Expand Down Expand Up @@ -127,21 +151,21 @@
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.1.3</version>
<version>1.13.5</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
</dependency>


<!-- Logging -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<version>1.4.12</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
Expand All @@ -151,7 +175,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
<version>2.0.12</version>
</dependency>

<!-- Test scope -->
Expand All @@ -163,8 +187,8 @@
</dependency>
<dependency>
<groupId>io.mockk</groupId>
<artifactId>mockk</artifactId>
<version>1.10.5</version>
<artifactId>mockk-jvm</artifactId>
<version>1.13.12</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -179,7 +203,7 @@
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-tests</artifactId>
<artifactId>ktor-server-tests-jvm</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -202,12 +226,12 @@
<plugin>
<groupId>com.github.gantsign.maven</groupId>
<artifactId>ktlint-maven-plugin</artifactId>
<version>1.7.0</version>
<version>3.3.0</version>
<executions>
<execution>
<id>check-kotlin-code</id>
<goals>
<goal>check</goal>
<!-- <goal>check</goal>-->
</goals>
<!--
Unable to get plugin to exclude generated sources (using sourcesExcludes),
Expand Down Expand Up @@ -238,7 +262,7 @@
</execution>
</executions>
<configuration>
<jvmTarget>14</jvmTarget>
<jvmTarget>21</jvmTarget>
<compilerPlugins>
<plugin>kotlinx-serialization</plugin>
</compilerPlugins>
Expand Down Expand Up @@ -281,4 +305,11 @@
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
</project>
12 changes: 7 additions & 5 deletions src/main/kotlin/no/nav/navansatt/ActiveDirectoryClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.coroutines.withContext
import org.apache.commons.text.StringEscapeUtils
import org.slf4j.LoggerFactory
import java.util.Hashtable
import java.util.Locale
import java.util.regex.Pattern
import javax.naming.Context
import javax.naming.NamingEnumeration
Expand All @@ -22,13 +23,14 @@ data class User(
val firstName: String,
val lastName: String,
val email: String,
val groups: List<String>
val groups: List<String>,
)

class ActiveDirectoryClient(
val url: String,
val base: String,
val username: String,
val password: String?
val password: String?,
) {
companion object {
private val LOG = LoggerFactory.getLogger(ActiveDirectoryClient::class.java)
Expand Down Expand Up @@ -71,7 +73,7 @@ class ActiveDirectoryClient(
firstName = readAttribute(entry.attributes, "givenname"),
lastName = readAttribute(entry.attributes, "sn"),
email = readEmail(entry.attributes),
groups = entry.attributes["memberof"]?.getAll()?.let { getAllGroups(it) } ?: emptyList()
groups = entry.attributes["memberof"]?.all?.let { getAllGroups(it) } ?: emptyList()
)
)
}
Expand Down Expand Up @@ -108,7 +110,7 @@ class ActiveDirectoryClient(

val returnedIdent = readAttribute(entry.attributes, "cn")

if (ident.toLowerCase() != returnedIdent.toLowerCase()) {
if (ident.lowercase(Locale.getDefault()) != returnedIdent.lowercase(Locale.getDefault())) {
LOG.warn("Mismatch in ident: Asked for ident $ident but a user with CN $returnedIdent was found.")
}

Expand All @@ -118,7 +120,7 @@ class ActiveDirectoryClient(
firstName = readAttribute(entry.attributes, "givenname"),
lastName = readAttribute(entry.attributes, "sn"),
email = readEmail(entry.attributes),
groups = entry.attributes["memberof"]?.getAll()?.let { getAllGroups(it) } ?: emptyList()
groups = entry.attributes["memberof"]?.all?.let { getAllGroups(it) } ?: emptyList()
)
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/no/nav/navansatt/AxsysClient.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package no.nav.navansatt

import io.ktor.client.HttpClient
import io.ktor.client.features.ResponseException
import io.ktor.client.call.body
import io.ktor.client.plugins.ResponseException
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.get
import io.ktor.client.request.header
Expand Down Expand Up @@ -44,9 +45,9 @@ class AxsysClient(val httpClient: HttpClient, val axsysUrl: String) {
suspend fun hentTilganger(ident: String): TilgangResponse {
try {
return httpClient.get {
url(axsysUrl + "/api/v1/tilgang/" + ident + "?inkluderAlleEnheter=false")
url("$axsysUrl/api/v1/tilgang/$ident?inkluderAlleEnheter=false")
axsysHeaders()
}
}.body()
} catch (e: ResponseException) {
if (e.response.status == HttpStatusCode.NotFound) {
throw NAVAnsattNotFoundError("Fant ikke NAV-ansatt med id $ident")
Expand All @@ -60,9 +61,9 @@ class AxsysClient(val httpClient: HttpClient, val axsysUrl: String) {
suspend fun hentAnsattIdenter(enhetId: String): List<Ident> {
try {
return httpClient.get {
url(axsysUrl + "/api/v1/enhet/$enhetId/brukere")
url("$axsysUrl/api/v1/enhet/$enhetId/brukere")
axsysHeaders()
}
}.body()
} catch (e: ResponseException) {
if (e.response.status == HttpStatusCode.NotFound) {
throw EnhetNotFoundError("Fant ikke NAV-enhet med id $enhetId")
Expand Down
16 changes: 7 additions & 9 deletions src/main/kotlin/no/nav/navansatt/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package no.nav.navansatt

import io.ktor.client.HttpClient
import io.ktor.client.engine.apache.Apache
import io.ktor.client.features.cache.HttpCache
import io.ktor.client.features.json.JsonFeature
import io.ktor.client.features.json.serializer.KotlinxSerializer
import io.ktor.client.plugins.cache.HttpCache
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.serialization.kotlinx.json.json
import io.ktor.server.engine.embeddedServer
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
Expand Down Expand Up @@ -32,12 +32,10 @@ fun main() {
}
}
install(HttpCache)
install(JsonFeature) {
serializer = KotlinxSerializer(
Json {
ignoreUnknownKeys = true
}
)
install(ContentNegotiation) {
json(Json {
ignoreUnknownKeys = true
})
}
}
embeddedServer(io.ktor.server.netty.Netty, port = 7000) {
Expand Down
11 changes: 4 additions & 7 deletions src/main/kotlin/no/nav/navansatt/Norg2Client.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package no.nav.navansatt

import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.request.url
import io.ktor.http.URLBuilder
import kotlinx.serialization.Serializable
import org.slf4j.LoggerFactory

@Serializable
data class Norg2Enhet(
Expand All @@ -15,18 +15,15 @@ data class Norg2Enhet(
)

class Norg2Client(val httpClient: HttpClient, val norg2Url: String) {
companion object {
private val LOG = LoggerFactory.getLogger(Norg2Client::class.java)
}

suspend fun hentEnheter(nummer: List<String>): List<Norg2Enhet> {
val response = httpClient.get<List<Norg2Enhet>> {
val response = httpClient.get {
url(
URLBuilder(norg2Url + "/api/v1/enhet").apply {
URLBuilder("$norg2Url/api/v1/enhet").apply {
parameters.appendAll("enhetsnummerListe", nummer)
}.buildString()
)
}
return response
return response.body()
}
}
Loading