Skip to content

Commit

Permalink
Merge pull request #405 from opexdev/dev
Browse files Browse the repository at this point in the history
Fix whitelist config
  • Loading branch information
Marchosiax authored Dec 5, 2023
2 parents 7da2e81 + f079714 commit 38cb89e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ class UserManagementResource(private val session: KeycloakSession) : RealmResour
private val forgotUrl by lazy {
ApplicationContextHolder.getCurrentContext()!!.environment.resolvePlaceholders("\${forgot-redirect-url}")
}
private val registerWhitelistIsEnable by lazy {
ApplicationContextHolder.getCurrentContext()!!
.environment
.resolvePlaceholders("\${app.whitelist.register.enabled}")
.toBoolean()
}
private val kafkaTemplate by lazy {
ApplicationContextHolder.getCurrentContext()!!.getBean("authKafkaTemplate") as KafkaTemplate<String, AuthEvent>
}

@Value("\${app.whitelist.register.enable}")
private var registerWhitelistIsEnable: Boolean? = true

@POST
@Path("user")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
fun registerUser(request: RegisterUserRequest): Response {
if (registerWhitelistIsEnable == true) {
if (registerWhitelistIsEnable) {
logger.info("register whitelist is enable, going to filter register requests ........")
val em: EntityManager = session.getProvider(JpaConnectionProvider::class.java).entityManager
val result: List<WhiteListModel> = em.createQuery("from whitelist", WhiteListModel::class.java).resultList
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.nilin.opex.auth.gateway.providers

import co.nilin.opex.auth.gateway.ApplicationContextHolder
import co.nilin.opex.auth.gateway.model.WhiteListModel
import co.nilin.opex.utility.error.data.OpexError
import co.nilin.opex.utility.error.data.OpexException
Expand All @@ -22,16 +23,19 @@ import java.util.stream.Collectors
import javax.persistence.EntityManager
import javax.ws.rs.core.Response

class CustomOIDCProtocolMapper() : AbstractOIDCProtocolMapper(), OIDCAccessTokenMapper, OIDCIDTokenMapper,
class CustomOIDCProtocolMapper : AbstractOIDCProtocolMapper(), OIDCAccessTokenMapper, OIDCIDTokenMapper,
UserInfoTokenMapper {
private val logger = LoggerFactory.getLogger(CustomOIDCProtocolMapper::class.java)

private val PROVIDER_ID = "oidc-customprotocolmapper"
private val configProperties: List<ProviderConfigProperty> = ArrayList()

@Value("\${app.whitelist.login.enable}")
private var loginWhitelistIsEnable: Boolean? = true

private val loginWhitelistIsEnable by lazy {
ApplicationContextHolder.getCurrentContext()!!
.environment
.resolvePlaceholders("\${app.whitelist.login.enabled}")
.toBoolean()
}

override fun getConfigProperties(): List<ProviderConfigProperty>? {
return configProperties
Expand Down Expand Up @@ -63,7 +67,7 @@ class CustomOIDCProtocolMapper() : AbstractOIDCProtocolMapper(), OIDCAccessToken
token.otherClaims["kyc_level"] = userSession?.user?.attributes?.get("kycLevel")
setClaim(token, mappingModel, userSession, keycloakSession, clientSessionCtx)

if (loginWhitelistIsEnable == true && !userIsAdmin(userSession)) {
if (loginWhitelistIsEnable && !userIsAdmin(userSession)) {
logger.info("login whitelist is enable and user is not admin; going to filter login requests ........")
val em: EntityManager = keycloakSession!!.getProvider(JpaConnectionProvider::class.java).entityManager
val result: List<WhiteListModel> = em.createQuery("from whitelist", WhiteListModel::class.java).resultList
Expand Down

0 comments on commit 38cb89e

Please sign in to comment.