Skip to content

Commit

Permalink
Moved to sessionManager instance instead of the cover
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish committed Oct 19, 2023
1 parent bbf2288 commit b6b372f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import org.sakaiproject.time.api.Time;
import org.sakaiproject.time.cover.TimeService;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.tool.cover.SessionManager;
import org.sakaiproject.tool.api.SessionManager;
import org.sakaiproject.tool.cover.ToolManager;
import org.sakaiproject.user.cover.PreferencesService;

Expand All @@ -75,12 +75,14 @@ public class PASystemServlet extends HttpServlet {

private PASystem paSystem;
private ClusterService clusterService;
private SessionManager sessionManager;

public void init(ServletConfig config) throws ServletException {
super.init(config);

paSystem = ComponentManager.get(PASystem.class);
clusterService = ComponentManager.get(ClusterService.class);
sessionManager = ComponentManager.get(SessionManager.class);
}

private Handler handlerForRequest(HttpServletRequest request) {
Expand All @@ -93,7 +95,7 @@ private Handler handlerForRequest(HttpServletRequest request) {
if (path.contains("/popups/")) {
return new PopupsHandler(paSystem);
} else if (path.contains("/banners/")) {
return new BannersHandler(paSystem, clusterService);
return new BannersHandler(paSystem, clusterService, sessionManager);
} else {
return new IndexHandler(paSystem);
}
Expand Down Expand Up @@ -149,18 +151,18 @@ private void checkAccessControl() {
String siteId = ToolManager.getCurrentPlacement().getContext();

if (!SecurityService.unlock("pasystem.manage", "/site/" + siteId)) {
log.error("Access denied to PA System management tool for user " + SessionManager.getCurrentSessionUserId());
log.error("Access denied to PA System management tool for user " + sessionManager.getCurrentSessionUserId());
throw new PASystemException("Access denied");
}
}

private void storeFlashMessages(Map<String, List<String>> messages) {
Session session = SessionManager.getCurrentSession();
Session session = sessionManager.getCurrentSession();
session.setAttribute(FLASH_MESSAGE_KEY, messages);
}

private Map<String, List<String>> loadFlashMessages() {
Session session = SessionManager.getCurrentSession();
Session session = sessionManager.getCurrentSession();

if (session.getAttribute(FLASH_MESSAGE_KEY) != null) {
Map<String, List<String>> flashErrors = (Map<String, List<String>>) session.getAttribute(FLASH_MESSAGE_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
import org.sakaiproject.pasystem.api.Banner;
import org.sakaiproject.pasystem.api.PASystem;
import org.sakaiproject.pasystem.tool.forms.BannerForm;
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.cover.UserDirectoryService;
import org.sakaiproject.tool.api.SessionManager;

/**
* A handler for creating and updating banners in the PA System administration tool.
Expand All @@ -47,11 +46,13 @@
public class BannersHandler extends CrudHandler {

private final PASystem paSystem;
private final ClusterService clusterService;
private final ClusterService clusterService;
private final SessionManager sessionManager;

public BannersHandler(PASystem pasystem, ClusterService clusterService) {
public BannersHandler(PASystem pasystem, ClusterService clusterService, SessionManager sessionManager) {
this.paSystem = pasystem;
this.clusterService = clusterService;
this.sessionManager = sessionManager;
}

@Override
Expand Down Expand Up @@ -91,11 +92,11 @@ protected void handleCreateOrUpdate(HttpServletRequest request, Map<String, Obje
String uuid = extractId(request);
BannerForm bannerForm = BannerForm.fromRequest(uuid, request);

User currentUser = UserDirectoryService.getCurrentUser();
if (currentUser == null) {
String userId = sessionManager.getCurrentSessionUserId();
if (userId == null) {
log.warn("No userid for current session. Returning ...");
return;
}
String userId = currentUser.getId();

this.addErrors(bannerForm.validate());

Expand Down

0 comments on commit b6b372f

Please sign in to comment.