Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: jans-linux-setup include permission of all user roles #3009

Merged
merged 1 commit into from
Nov 16, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def getApiVersion(self):
# context is reference of io.jans.as.service.external.context.ExternalIntrospectionContext (in https://github.com/JanssenFederation/oxauth project, )
def modifyResponse(self, responseAsJsonObject, context):
print "Inside modifyResponse method of introspection script ...."
scopes = []
try:
# Getting user-info-jwt
ujwt = context.getHttpRequest().getParameter("ujwt")
Expand All @@ -55,7 +56,7 @@ def modifyResponse(self, responseAsJsonObject, context):
adminConf = AdminConf()
adminUIConfig = entryManager.find(adminConf.getClass(), "ou=admin-ui,ou=configuration,o=jans")
permissions = adminUIConfig.getDynamic().getPermissions()
scopes = []

for ele in permissions:
if ele.getDefaultPermissionInToken() is not None and ele.getDefaultPermissionInToken():
scopes.append(ele.getPermission())
Expand All @@ -77,18 +78,19 @@ def modifyResponse(self, responseAsJsonObject, context):
if validJwt == True:
# Get claims from parsed JWT
jwtClaims = userInfoJwt.getClaims()
jansAdminUIRole = jwtClaims.getClaim("jansAdminUIRole")
jansAdminUIRole = list(jwtClaims.getClaim("jansAdminUIRole"))
# fetch role-scope mapping from database
scopes = None
try:
entryManager = CdiUtil.bean(PersistenceEntryManager)
adminConf = AdminConf()
adminUIConfig = entryManager.find(adminConf.getClass(), "ou=admin-ui,ou=configuration,o=jans")
roleScopeMapping = adminUIConfig.getDynamic().getRolePermissionMapping()

for ele in roleScopeMapping:
if ele.getRole() == jansAdminUIRole.getString(0):
scopes = ele.getPermissions()
if ele.getRole() in jansAdminUIRole:
for scope in ele.getPermissions():
if not scope in scopes:
scopes.append(scope)
except Exception as e:
print "Error: Failed to fetch/parse Admin UI roleScopeMapping from DB"
print e
Expand All @@ -99,4 +101,4 @@ def modifyResponse(self, responseAsJsonObject, context):
except Exception as e:
print "Exception occured. Unable to resolve role/scope mapping."
print e
return True
return True