001: /**********************************************************************************
002: *
003: * $Id: AuthzSakai2Impl.java 18134 2006-11-14 18:59:25Z jholtzman@berkeley.edu $
004: *
005: ***********************************************************************************
006: *
007: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
008: *
009: * Licensed under the Educational Community License, Version 1.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.opensource.org/licenses/ecl1.php
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: *
021: **********************************************************************************/package org.sakaiproject.tool.gradebook.facades.sakai2impl;
022:
023: import java.util.Collection;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027:
028: import org.sakaiproject.authz.cover.FunctionManager;
029: import org.sakaiproject.authz.cover.SecurityService;
030: import org.sakaiproject.site.cover.SiteService;
031:
032: import org.sakaiproject.section.api.facade.Role;
033:
034: import org.sakaiproject.tool.gradebook.facades.Authz;
035: import org.sakaiproject.tool.gradebook.facades.sections.AuthzSectionsImpl;
036:
037: /**
038: * An implementation of Gradebook-specific authorization needs based
039: * on a combination of fine-grained site-scoped Sakai permissions and the
040: * shared Section Awareness API. This is a transtional stage between
041: * coarse-grained site-and-role-based authz and our hoped-for fine-grained
042: * role-determined group-scoped authz.
043: */
044: public class AuthzSakai2Impl extends AuthzSectionsImpl implements Authz {
045: private static final Log log = LogFactory
046: .getLog(AuthzSakai2Impl.class);
047:
048: public static final String PERMISSION_GRADE_ALL = "gradebook.gradeAll",
049: PERMISSION_GRADE_SECTION = "gradebook.gradeSection",
050: PERMISSION_EDIT_ASSIGNMENTS = "gradebook.editAssignments",
051: PERMISSION_VIEW_OWN_GRADES = "gradebook.viewOwnGrades";
052:
053: /**
054: * Perform authorization-specific framework initializations for the Gradebook.
055: */
056: public void init() {
057: Collection registered = FunctionManager.getInstance()
058: .getRegisteredFunctions("gradebook");
059: if (!registered.contains(PERMISSION_GRADE_ALL)) {
060: FunctionManager.registerFunction(PERMISSION_GRADE_ALL);
061: }
062:
063: if (!registered.contains(PERMISSION_GRADE_SECTION)) {
064: FunctionManager.registerFunction(PERMISSION_GRADE_SECTION);
065: }
066:
067: if (!registered.contains(PERMISSION_EDIT_ASSIGNMENTS)) {
068: FunctionManager
069: .registerFunction(PERMISSION_EDIT_ASSIGNMENTS);
070: }
071:
072: if (!registered.contains(PERMISSION_VIEW_OWN_GRADES)) {
073: FunctionManager
074: .registerFunction(PERMISSION_VIEW_OWN_GRADES);
075: }
076: }
077:
078: public boolean isUserAbleToGrade(String gradebookUid) {
079: return (hasPermission(gradebookUid, PERMISSION_GRADE_ALL) || hasPermission(
080: gradebookUid, PERMISSION_GRADE_SECTION));
081: }
082:
083: public boolean isUserAbleToGradeAll(String gradebookUid) {
084: return hasPermission(gradebookUid, PERMISSION_GRADE_ALL);
085: }
086:
087: /**
088: * When group-scoped permissions are available, this is where
089: * they will go. My current assumption is that the call will look like:
090: *
091: * return hasPermission(sectionUid, PERMISSION_GRADE_ALL);
092: */
093: public boolean isUserAbleToGradeSection(String sectionUid) {
094: return getSectionAwareness().isSectionMemberInRole(sectionUid,
095: getAuthn().getUserUid(), Role.TA);
096: }
097:
098: public boolean isUserAbleToEditAssessments(String gradebookUid) {
099: return hasPermission(gradebookUid, PERMISSION_EDIT_ASSIGNMENTS);
100: }
101:
102: public boolean isUserAbleToViewOwnGrades(String gradebookUid) {
103: return hasPermission(gradebookUid, PERMISSION_VIEW_OWN_GRADES);
104: }
105:
106: private boolean hasPermission(String gradebookUid, String permission) {
107: return SecurityService.unlock(permission, SiteService
108: .siteReference(gradebookUid));
109: }
110:
111: }
|