Passing Custom User Context in Row Level Security
How It Works
district_name = '{{ district() }}'Implementation Steps
1. Assign Custom Attributes in Keycloak
2. Extract Claims and Attach to Superset User
from superset.security import SupersetSecurityManager
class CustomSsoSecurityManager(SupersetSecurityManager):
def oauth_user_info(self, provider, response=None):
if provider == "keycloak":
me = self.appbuilder.sm.oauth_remotes[provider].get(
"openid-connect/userinfo"
)
me.raise_for_status()
data = me.json()
return {
...
"district": data.get("district", ""),
...
}
return {}
def auth_user_oauth(self, userinfo):
user = super().auth_user_oauth(userinfo)
if user and "district" in userinfo:
session["district"] = userinfo["district"]
return user
CUSTOM_SECURITY_MANAGER = CustomSsoSecurityManager3. Register Jinja Macro for the Attribute
4. Use the Attribute in RLS Filter
5. Validate the Configuration
Last updated
Was this helpful?

