001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/api-impl/src/java/org/theospi/portfolio/security/model/SimpleSitePermissionManager.java $
003: * $Id:SimpleSitePermissionManager.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.security.model;
021:
022: import java.util.ArrayList;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: import org.sakaiproject.metaobj.shared.model.Id;
027: import org.sakaiproject.site.api.Site;
028: import org.sakaiproject.site.api.ToolConfiguration;
029:
030: public class SimpleSitePermissionManager extends
031: SimpleToolPermissionManager {
032:
033: private String functionPrefix;
034:
035: /**
036: * sets up the default perms for a tool. Uses the site id as the qualifier.
037: * Assumes that if no perms exist for the tool, the perms should be set to the defaults.
038: * @param toolConfig
039: */
040: public void toolSiteChanged(ToolConfiguration toolConfig) {
041:
042: //Id toolId = getIdManager().getId(toolConfig.getId());
043: PermissionsEdit edit = new PermissionsEdit();
044: edit.setName(getPermissionEditName());
045: Site containingSite = toolConfig.getContainingPage()
046: .getContainingSite();
047:
048: if (!isSpecial(containingSite)) {
049: Id siteId = getIdManager().getId(containingSite.getId());
050: edit.setQualifier(siteId);
051: edit.setSiteId(containingSite.getId());
052: getPermissionManager().fillPermissions(edit);
053: List perms = filterPermissions(edit);
054: if (perms == null || perms.size() == 0) {
055: createDefaultPermissions(edit.getSiteId(), siteId,
056: containingSite.getType());
057: }
058: }
059: }
060:
061: /**
062: * sets up the default perms for a helper tool. Uses the site id as the qualifier.
063: * Assumes that if no perms exist for the tool, the perms should be set to the defaults.
064: * @param site
065: */
066: public void helperSiteChanged(Site site) {
067: if (!isSpecial(site)) {
068: Id siteId = getIdManager().getId(site.getId());
069: PermissionsEdit edit = new PermissionsEdit();
070: edit.setQualifier(siteId);
071: edit.setName(getPermissionEditName());
072: edit.setSiteId(site.getId());
073: getPermissionManager().fillPermissions(edit);
074: List perms = filterPermissions(edit);
075: if (perms == null || perms.size() == 0) {
076: createDefaultPermissions(edit.getSiteId(), siteId, site
077: .getType());
078: }
079: }
080: }
081:
082: protected List filterPermissions(PermissionsEdit edit) {
083: List filteredPermissions = new ArrayList();
084:
085: for (Iterator iter = edit.getPermissions().iterator(); iter
086: .hasNext();) {
087: Permission perm = (Permission) iter.next();
088: if (perm.getFunction().startsWith(functionPrefix))
089: filteredPermissions.add(perm);
090: }
091: return filteredPermissions;
092: }
093:
094: public String getFunctionPrefix() {
095: return functionPrefix;
096: }
097:
098: public void setFunctionPrefix(String functionPrefix) {
099: this.functionPrefix = functionPrefix;
100: }
101: }
|