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

Fix token revocation for role deletion or user un-assignment from the role #2665

Merged
Merged
Show file tree
Hide file tree
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 @@ -715,7 +715,7 @@ private static AuthenticatedUser buildAuthenticatedUser(UserStoreManager userSto
AuthenticatedUser authenticatedUser = new AuthenticatedUser();
authenticatedUser.setUserStoreDomain(userStoreDomain);
authenticatedUser.setTenantDomain(tenantDomain);
authenticatedUser.setUserName(username);
authenticatedUser.setUserName(UserCoreUtil.removeDomainFromName(username));
boolean isOrganization;
try {
isOrganization = OrganizationManagementUtil.isOrganization(tenantDomain);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,23 +490,24 @@ private void terminateSession(List<String> userIDList, String roleId, String ten
throws IdentityEventException {

try {
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
UserStoreManager userStoreManager = getUserStoreManager(tenantId);

String userName;
if (CollectionUtils.isNotEmpty(userIDList)) {
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
UserStoreManager userStoreManager = getUserStoreManager(tenantId);

for (String userId : userIDList) {
try {
userName = FrameworkUtils.resolveUserNameFromUserId(userStoreManager, userId);
String userName = FrameworkUtils.resolveUserNameFromUserId(userStoreManager, userId);
if (userName == null) {
log.warn("User name is null for user id: " + userId + ". Hence skipping " +
"token revocation and session termination processes.");
continue;
}
UserStoreManager userStoreManagerOfUser = getUserStoreManagerOfUser(
userStoreManager, userName);
OAuth2ServiceComponentHolder.getInstance()
.getRevocationProcessor()
.revokeTokens(userName, userStoreManager, roleId);
OAuthUtil.removeUserClaimsFromCache(userName, userStoreManager);
.revokeTokens(userName, userStoreManagerOfUser, roleId);
OAuthUtil.removeUserClaimsFromCache(userName, userStoreManagerOfUser);
} catch (UserSessionException e) {
String errorMsg = "Error occurred while revoking access token for user Id: " + userId;
log.error(errorMsg, e);
Expand All @@ -520,4 +521,22 @@ private void terminateSession(List<String> userIDList, String roleId, String ten
throw new IdentityEventException(errorMsg, e);
}
}

/**
* Get the user store manager of the user.
*
* @param userStoreManager User store manager.
* @param userName Username of the user.
* @return User store manager of the user.
*/
private UserStoreManager getUserStoreManagerOfUser(UserStoreManager userStoreManager, String userName) {

String userStoreDomainOfUser = IdentityUtil.extractDomainFromName(userName);
UserStoreManager secondaryUserStoreManager = userStoreManager.getSecondaryUserStoreManager(
userStoreDomainOfUser);
if (secondaryUserStoreManager == null) {
return userStoreManager;
}
return secondaryUserStoreManager;
}
}
Loading