01: package org.sakaiproject.tool.section;
02:
03: import java.io.IOException;
04:
05: import javax.servlet.ServletException;
06: import javax.servlet.http.HttpServlet;
07: import javax.servlet.http.HttpServletRequest;
08: import javax.servlet.http.HttpServletResponse;
09:
10: import org.apache.commons.logging.Log;
11: import org.apache.commons.logging.LogFactory;
12: import org.sakaiproject.section.api.facade.manager.Authn;
13: import org.sakaiproject.section.api.facade.manager.Authz;
14: import org.sakaiproject.section.api.facade.manager.Context;
15: import org.springframework.context.ApplicationContext;
16: import org.springframework.web.context.WebApplicationContext;
17:
18: public class EntryServlet extends HttpServlet {
19: private static final long serialVersionUID = 1L;
20: private static final Log log = LogFactory
21: .getLog(EntryServlet.class);
22:
23: public void doPost(HttpServletRequest req, HttpServletResponse resp)
24: throws ServletException, java.io.IOException {
25: doGet(req, resp);
26: }
27:
28: public void doGet(HttpServletRequest request,
29: HttpServletResponse response) {
30: if (log.isDebugEnabled())
31: log
32: .debug("Entering sections tool... determining role appropriate view");
33:
34: ApplicationContext ac = (ApplicationContext) getServletContext()
35: .getAttribute(
36: WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
37: Authn authnService = (Authn) ac
38: .getBean("org.sakaiproject.section.api.facade.manager.Authn");
39: Authz authzService = (Authz) ac
40: .getBean("org.sakaiproject.section.api.facade.manager.Authz");
41: Context contextService = (Context) ac
42: .getBean("org.sakaiproject.section.api.facade.manager.Context");
43:
44: String userUid = authnService.getUserUid(null);
45: String siteContext = contextService.getContext(null);
46:
47: boolean viewAllSections = authzService
48: .isViewAllSectionsAllowed(userUid, siteContext);
49: boolean viewOwnSections = authzService
50: .isViewOwnSectionsAllowed(userUid, siteContext);
51:
52: StringBuffer path = new StringBuffer(request.getContextPath());
53: if (viewAllSections) {
54: if (log.isDebugEnabled())
55: log.debug("Sending user to the overview page");
56: path.append("/overview.jsf");
57: } else if (viewOwnSections) {
58: if (log.isDebugEnabled())
59: log.debug("Sending user to the student view page");
60: path.append("/studentView.jsf");
61: } else {
62: // The role filter has not been invoked yet, so this could happen here
63: path.append("/noRole.jsp");
64: }
65: String queryString = request.getQueryString();
66: if (queryString != null) {
67: path.append("?").append(queryString);
68: }
69: try {
70: response.sendRedirect(path.toString());
71: } catch (IOException e) {
72: log.error("Could not redirect user: " + e);
73: }
74:
75: }
76:
77: }
|