01: /**********************************************************************************
02: *
03: * $Id: EntryServlet.java 11302 2006-06-28 23:14:29Z jholtzman@berkeley.edu $
04: *
05: ***********************************************************************************
06: *
07: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
08: *
09: * Licensed under the Educational Community License, Version 1.0 (the "License");
10: * you may not use this file except in compliance with the License.
11: * You may obtain a copy of the License at
12: *
13: * http://www.opensource.org/licenses/ecl1.php
14: *
15: * Unless required by applicable law or agreed to in writing, software
16: * distributed under the License is distributed on an "AS IS" BASIS,
17: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18: * See the License for the specific language governing permissions and
19: * limitations under the License.
20: *
21: **********************************************************************************/package org.sakaiproject.tool.gradebook.ui;
22:
23: import java.io.IOException;
24:
25: import javax.servlet.ServletException;
26: import javax.servlet.http.HttpServlet;
27: import javax.servlet.http.HttpServletRequest;
28: import javax.servlet.http.HttpServletResponse;
29:
30: import org.apache.commons.logging.Log;
31: import org.apache.commons.logging.LogFactory;
32:
33: import org.springframework.web.context.WebApplicationContext;
34: import org.springframework.web.context.support.WebApplicationContextUtils;
35:
36: import org.sakaiproject.tool.gradebook.facades.Authn;
37: import org.sakaiproject.tool.gradebook.facades.Authz;
38: import org.sakaiproject.tool.gradebook.facades.ContextManagement;
39:
40: /**
41: * Redirects the request to the role-appropriate initial view of the gradebook.
42: */
43: public class EntryServlet extends HttpServlet {
44: private static final Log logger = LogFactory
45: .getLog(EntryServlet.class);
46:
47: public void doPost(HttpServletRequest req, HttpServletResponse resp)
48: throws ServletException, java.io.IOException {
49: doGet(req, resp);
50: }
51:
52: public void doGet(HttpServletRequest request,
53: HttpServletResponse response) {
54: WebApplicationContext appContext = WebApplicationContextUtils
55: .getWebApplicationContext(this .getServletContext());
56:
57: Authn authnService = (Authn) appContext
58: .getBean("org_sakaiproject_tool_gradebook_facades_Authn");
59: Authz authzService = (Authz) appContext
60: .getBean("org_sakaiproject_tool_gradebook_facades_Authz");
61: ContextManagement contextMgm = (ContextManagement) appContext
62: .getBean("org_sakaiproject_tool_gradebook_facades_ContextManagement");
63:
64: authnService.setAuthnContext(request);
65: String gradebookUid = contextMgm.getGradebookUid(request);
66:
67: try {
68: if (gradebookUid != null) {
69: StringBuffer path = new StringBuffer(request
70: .getContextPath());
71: if (authzService.isUserAbleToGrade(gradebookUid)) {
72: if (logger.isDebugEnabled())
73: logger
74: .debug("Sending user to the overview page");
75: path.append("/overview.jsf");
76: } else if (authzService
77: .isUserAbleToViewOwnGrades(gradebookUid)) {
78: if (logger.isDebugEnabled())
79: logger
80: .debug("Sending user to the student view page");
81: path.append("/studentView.jsf");
82: } else {
83: // The role filter has not been invoked yet, so this could happen here
84: // throw new RuntimeException("User " + authnService.getUserUid() + " attempted to access gradebook " + gradebookUid + " without any role");
85: path.append("/noRole.jsp");
86: }
87: String queryString = request.getQueryString();
88: if (queryString != null) {
89: path.append("?").append(queryString);
90: }
91: response.sendRedirect(path.toString());
92: }
93: } catch (IOException ioe) {
94: logger.fatal("Could not redirect user: " + ioe);
95: }
96: }
97:
98: }
|