Skip to content

Commit

Permalink
MM-893: Modified logic to meet requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsereko committed Aug 4, 2021
1 parent c3dab7b commit 58becd0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Expand Up @@ -24,6 +24,7 @@ public class CoreAppsConstants {
public static final String PRIVILEGE_PATIENT_DASHBOARD = "App: coreapps.patientDashboard";
public static final String PRIVILEGE_SUMMARY_DASHBOARD = "App: coreapps.summaryDashboard";
public static final String PRIVILEGE_PATIENT_VISITS = "App: coreapps.patientVisits";
public static final String PRIVILEGE_SYSTEM_ADMINISTRATOR = "App: coreapps.systemAdministration";
public static final String PRIVILEGE_START_VISIT = "Task: coreapps.createVisit";
public static final String PRIVILEGE_END_VISIT = "Task: coreapps.endVisit";
public static final String PRIVILEGE_DELETE_PATIENT = "Task: coreapps.deletePatient";
Expand Down
Expand Up @@ -23,8 +23,7 @@

import org.openmrs.User;
import org.openmrs.api.context.Context;
import org.openmrs.module.Module;
import org.openmrs.module.ModuleFactory;
import org.openmrs.module.coreapps.CoreAppsConstants;
import org.openmrs.web.WebConstants;

import org.slf4j.Logger;
Expand All @@ -38,9 +37,7 @@
public class AdminAuthorisationFilter implements Filter {

private static final Logger log = LoggerFactory.getLogger(AdminAuthorisationFilter.class);

private static final String COREAPPS_SYSTEM_ADMINISTRATOR_PRIVELEGE = "App: coreapps.systemAdministration";


/**
* @see Filter#init(FilterConfig)
*/
Expand All @@ -55,11 +52,12 @@ public void init(FilterConfig filterConfig) throws ServletException {
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) req;
User user = Context.getAuthenticatedUser();
if (user != null && !user.hasPrivilege(COREAPPS_SYSTEM_ADMINISTRATOR_PRIVELEGE)) {
if (user != null && !user.hasPrivilege(CoreAppsConstants.PRIVILEGE_SYSTEM_ADMINISTRATOR)) {
httpReq.getSession().setAttribute(WebConstants.DENIED_PAGE, httpReq.getRequestURI());
HttpServletResponse httpRes = (HttpServletResponse) res;
log.info("User " + user + " has no privilage \"" + COREAPPS_SYSTEM_ADMINISTRATOR_PRIVELEGE + "\"");
log.info("User {} lacks the privilege {}", user, CoreAppsConstants.PRIVILEGE_SYSTEM_ADMINISTRATOR);
httpRes.sendRedirect(httpReq.getContextPath() + "/login.htm");
return;
}
chain.doFilter(req, res);
}
Expand All @@ -70,4 +68,4 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
public void destroy() {

}
}
}

0 comments on commit 58becd0

Please sign in to comment.