01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-app/src/java/org/sakaiproject/tool/section/jsf/JsfTool.java $
03: * $Id: JsfTool.java 18134 2006-11-14 18:59:25Z jholtzman@berkeley.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.tool.section.jsf;
21:
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24: import org.sakaiproject.section.api.facade.manager.Authn;
25: import org.sakaiproject.section.api.facade.manager.Authz;
26: import org.sakaiproject.section.api.facade.manager.Context;
27: import org.springframework.context.ApplicationContext;
28: import org.springframework.web.context.WebApplicationContext;
29:
30: /**
31: * Extension to the Sakai JsfTool servlet, computing the default page view
32: * depending on the user's role (permissions).
33: *
34: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
35: *
36: */
37: public class JsfTool extends org.sakaiproject.jsf.util.JsfTool {
38:
39: private static final long serialVersionUID = 1L;
40: private static final Log log = LogFactory.getLog(JsfTool.class);
41:
42: /**
43: * @inheritDoc
44: */
45: protected String computeDefaultTarget() {
46: if (log.isDebugEnabled())
47: log
48: .debug("Entering sections tool... determining role appropriate view");
49:
50: ApplicationContext ac = (ApplicationContext) getServletContext()
51: .getAttribute(
52: WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
53: Authn authnService = (Authn) ac
54: .getBean("org.sakaiproject.section.api.facade.manager.Authn");
55: Authz authzService = (Authz) ac
56: .getBean("org.sakaiproject.section.api.facade.manager.Authz");
57: Context contextService = (Context) ac
58: .getBean("org.sakaiproject.section.api.facade.manager.Context");
59:
60: String userUid = authnService.getUserUid(null);
61: String siteContext = contextService.getContext(null);
62:
63: boolean viewAllSections = authzService
64: .isViewAllSectionsAllowed(userUid, siteContext);
65: boolean viewOwnSections = authzService
66: .isViewOwnSectionsAllowed(userUid, siteContext);
67:
68: String target;
69: if (viewAllSections) {
70: if (log.isDebugEnabled())
71: log.debug("Sending user to the overview page");
72: target = "/overview";
73: } else if (viewOwnSections) {
74: if (log.isDebugEnabled())
75: log.debug("Sending user to the student view page");
76: target = "/studentView";
77: } else {
78: // The role filter has not been invoked yet, so this could happen here
79: throw new RuntimeException("User " + userUid
80: + " attempted to access sections in site "
81: + siteContext + " without any role");
82: }
83: return target;
84: }
85: }
|