Skip to content

Commit

Permalink
refactor: tightens up type definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
outofcoffee committed Jul 1, 2024
1 parent 5f6fec6 commit 36982d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ interface SecurityService {
/**
* Find a plugin configuration with a 'security' block if one is non-null.
*
*
* Only zero or one configurations can specify the 'security' block.
* If none are found, the first configuration is returned, indicating no security policy is specified.
* If more than one configuration has a security block, an [IllegalStateException] is thrown.
Expand All @@ -66,13 +65,12 @@ interface SecurityService {
/**
* Enforces the given security policy on the current request.
*
*
* If the request is to be denied, then this method sends HTTP 401 to the [HttpExchange].
* If the request is to be permitted, no modification is made to the [HttpExchange].
*
* @param security the security policy
* @param httpExchange the current request
* @return `true` of the request is permitted to continue, otherwise `false`
*/
fun enforce(security: SecurityConfig?, httpExchange: HttpExchange): Boolean
fun enforce(security: SecurityConfig, httpExchange: HttpExchange): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import io.gatehill.imposter.util.HttpUtil
import io.gatehill.imposter.util.LogUtil
import io.gatehill.imposter.util.MatchUtil.conditionMatches
import org.apache.logging.log4j.LogManager
import java.util.Locale
import java.util.*
import javax.inject.Inject

/**
Expand Down Expand Up @@ -98,8 +98,8 @@ class SecurityServiceImpl @Inject constructor(
/**
* {@inheritDoc}
*/
override fun enforce(security: SecurityConfig?, httpExchange: HttpExchange): Boolean {
val outcome: PolicyOutcome = if (security!!.conditions.isEmpty()) {
override fun enforce(security: SecurityConfig, httpExchange: HttpExchange): Boolean {
val outcome: PolicyOutcome = if (security.conditions.isEmpty()) {
PolicyOutcome(security.defaultEffect, "default effect")
} else {
evaluatePolicy(security, httpExchange)
Expand Down

0 comments on commit 36982d4

Please sign in to comment.