Skip to content
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
21 changes: 15 additions & 6 deletions security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -3922,12 +3922,21 @@ private void createExternalUser() {
vXPortalUser.setLoginId(userName);
vXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);

List<String> headerRoles = getHeaderAuthRoles();
boolean trustedHeaderRoles = CollectionUtils.isNotEmpty(headerRoles);
ArrayList<String> roleList = new ArrayList<>();
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
boolean isSelfProvisioning = auth instanceof RangerAuthenticationToken && ((RangerAuthenticationToken) auth).getAuthType() == XXAuthSession.AUTH_TYPE_TRUSTED_PROXY && StringUtils.equalsIgnoreCase(auth.getName(), userName);
ArrayList<String> roleList = new ArrayList<>();
boolean useHeaderRoles = false;

if (trustedHeaderRoles) {
roleList.addAll(headerRoles);
if (isSelfProvisioning) {
List<String> headerRoles = getHeaderAuthRoles();

if (CollectionUtils.isNotEmpty(headerRoles)) {
useHeaderRoles = true;

roleList.addAll(headerRoles);
} else {
roleList.add(RangerConstants.ROLE_USER);
}
} else {
roleList.add(RangerConstants.ROLE_USER);
}
Expand All @@ -3937,7 +3946,7 @@ private void createExternalUser() {
xXPortalUser = userMgr.mapVXPortalUserToXXPortalUser(vXPortalUser);

try {
xXPortalUser = createExternalPortalUser(xXPortalUser, roleList, trustedHeaderRoles);
xXPortalUser = createExternalPortalUser(xXPortalUser, roleList, useHeaderRoles);

logger.debug("createExternalUser(): Successfully created user {} in x_portal_user table with roles {}", xXPortalUser.getLoginId(), roleList);
} catch (Exception ex) {
Expand Down