You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
637 B
26 lines
637 B
package de.joshavg
|
|
|
|
import javax.enterprise.context.ApplicationScoped
|
|
import javax.inject.Inject
|
|
import javax.ws.rs.core.Response
|
|
|
|
@ApplicationScoped
|
|
class Security(@Inject
|
|
val builds: Builds) {
|
|
|
|
fun requireKey(build: String, key: String?, block: (BuildConfig) -> Any): Response {
|
|
val buildConfig = builds.buildConfig(build)
|
|
if (buildConfig.key != key) {
|
|
return Response.status(Response.Status.UNAUTHORIZED).build()
|
|
}
|
|
|
|
val entity = block(buildConfig)
|
|
if(entity is Response) {
|
|
return entity
|
|
}
|
|
|
|
return Response.ok(entity).build()
|
|
}
|
|
|
|
}
|