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: session vs token issue #151

Merged
merged 2 commits into from
Aug 1, 2024
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
17 changes: 3 additions & 14 deletions src/main/java/org/ohdsi/webapi/shiro/PermissionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class PermissionManager {

private ThreadLocal<ConcurrentHashMap<String, UserSimpleAuthorizationInfo>> authorizationInfoCache = ThreadLocal.withInitial(ConcurrentHashMap::new);

private Map<AbstractMap.SimpleEntry<String,String>, String> teamProjectRoles = new HashMap<>();
private Map<String, String> teamProjectRoles = new HashMap<>();

public static class PermissionsDTO {

Expand Down Expand Up @@ -658,25 +658,14 @@ public boolean roleExists(String roleName) {
return this.roleRepository.existsByName(roleName);
}

private String getCurrentUserSessionId() {
Subject subject = SecurityUtils.getSubject();
return subject.getSession(false).getId().toString();
}

private AbstractMap.SimpleEntry<String,String> getCurrentUserAndSessionTuple() {
AbstractMap.SimpleEntry<String, String> userAndSessionTuple = new AbstractMap.SimpleEntry<>
(getCurrentUser().getLogin(), getCurrentUserSessionId());
return userAndSessionTuple;
}

public void setCurrentTeamProjectRoleForCurrentUser(String teamProjectRole, String login) {
logger.debug("Current user in setCurrentTeamProjectRoleForCurrentUser() {}", login);
this.teamProjectRoles.put(getCurrentUserAndSessionTuple(), teamProjectRole);
this.teamProjectRoles.put(getCurrentUser().getLogin(), teamProjectRole);
}

public RoleEntity getCurrentTeamProjectRoleForCurrentUser() {
logger.debug("Current user in getCurrentTeamProjectRoleForCurrentUser(): {}", getCurrentUser().getLogin());
String teamProjectRole = this.teamProjectRoles.get(getCurrentUserAndSessionTuple());
String teamProjectRole = this.teamProjectRoles.get(getCurrentUser().getLogin());
if (teamProjectRole == null) {
return null;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ protected boolean preHandle(ServletRequest request, ServletResponse response) th

login = UserUtils.toLowerCase(login);

// stop session to make logout of OAuth users possible
Session session = SecurityUtils.getSubject().getSession(false);
if (session != null) {
session.stop();
}
Comment on lines +118 to +122
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (jwt == null) {
if (name == null) {
Expand Down Expand Up @@ -169,4 +174,4 @@ private Date getExpirationDate(final int expirationIntervalInSeconds) {
calendar.add(Calendar.SECOND, expirationIntervalInSeconds);
return calendar.getTime();
}
}
}
Loading