001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/DefaultPermissionsManagerImpl.java $
003: * $Id: DefaultPermissionsManagerImpl.java 9227 2006-05-15 15:02:42Z cwen@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 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.sakaiproject.component.app.messageforums;
021:
022: import java.util.ArrayList;
023: import java.util.Collection;
024: import java.util.Set;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028: import org.sakaiproject.api.app.messageforums.DefaultPermissionsManager;
029: import org.sakaiproject.authz.api.AuthzGroup;
030: import org.sakaiproject.authz.api.AuthzGroupService;
031: import org.sakaiproject.authz.api.FunctionManager;
032: import org.sakaiproject.tool.cover.ToolManager;
033:
034: /**
035: * @author <a href="mailto:rshastri@iupui.edu">Rashmi Shastri</a>
036: *
037: */
038: public class DefaultPermissionsManagerImpl implements
039: DefaultPermissionsManager {
040: private static final Log LOG = LogFactory
041: .getLog(DefaultPermissionsManagerImpl.class);
042: //Dependency injected
043: private FunctionManager functionManager;
044: private AuthzGroupService authzGroupService;
045:
046: public void init() {
047: LOG.info("init()");
048: /* functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_NEW_FORUM);
049: functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_NEW_TOPIC);
050: functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_NEW_RESPONSE);
051: functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_NEW_RESPONSE_TO_RESPONSE);
052: functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_MOVE_POSTINGS);
053: functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_CHANGE_SETTINGS);
054: functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_POST_TO_GRADEBOOK);
055: functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_READ);
056: functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_REVISE_ANY);
057: functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_REVISE_OWN);
058: functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_DELETE_ANY);
059: functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_DELETE_OWN);
060: functionManager.registerFunction(DefaultPermissionsManager.FUNCTION_MARK_AS_READ);*/
061: }
062:
063: /**
064: * @param functionManager The functionManager to set.
065: */
066: public void setFunctionManager(FunctionManager functionManager) {
067: this .functionManager = functionManager;
068: }
069:
070: /**
071: * @param authzGroupService The authzGroupService to set.
072: */
073: public void setAuthzGroupService(AuthzGroupService authzGroupService) {
074: this .authzGroupService = authzGroupService;
075: }
076:
077: /* (non-Javadoc)
078: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isNewForum(java.lang.String)
079: */
080: public boolean isNewForum(String role) {
081: return hasPermission(role,
082: DefaultPermissionsManager.FUNCTION_NEW_FORUM);
083: }
084:
085: /* (non-Javadoc)
086: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isNewTopic(java.lang.String)
087: */
088: public boolean isNewTopic(String role) {
089: return hasPermission(role,
090: DefaultPermissionsManager.FUNCTION_NEW_TOPIC);
091: }
092:
093: /* (non-Javadoc)
094: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isNewResponse(java.lang.String)
095: */
096: public boolean isNewResponse(String role) {
097: return hasPermission(role,
098: DefaultPermissionsManager.FUNCTION_NEW_RESPONSE);
099: }
100:
101: /* (non-Javadoc)
102: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isResponseToResponse(java.lang.String)
103: */
104: public boolean isResponseToResponse(String role) {
105: return hasPermission(
106: role,
107: DefaultPermissionsManager.FUNCTION_NEW_RESPONSE_TO_RESPONSE);
108: }
109:
110: /* (non-Javadoc)
111: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isMovePostings(java.lang.String)
112: */
113: public boolean isMovePostings(String role) {
114: return hasPermission(role,
115: DefaultPermissionsManager.FUNCTION_MOVE_POSTINGS);
116: }
117:
118: /* (non-Javadoc)
119: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isChangeSettings(java.lang.String)
120: */
121: public boolean isChangeSettings(String role) {
122: return hasPermission(role,
123: DefaultPermissionsManager.FUNCTION_CHANGE_SETTINGS);
124: }
125:
126: /* (non-Javadoc)
127: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isPostToGradeBook(java.lang.String)
128: */
129: public boolean isPostToGradebook(String role) {
130: return hasPermission(role,
131: DefaultPermissionsManager.FUNCTION_POST_TO_GRADEBOOK);
132: }
133:
134: /* (non-Javadoc)
135: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isRead(java.lang.String)
136: */
137: public boolean isRead(String role) {
138: return hasPermission(role,
139: DefaultPermissionsManager.FUNCTION_READ);
140: }
141:
142: /* (non-Javadoc)
143: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isReviseAny(java.lang.String)
144: */
145: public boolean isReviseAny(String role) {
146: return hasPermission(role,
147: DefaultPermissionsManager.FUNCTION_REVISE_ANY);
148: }
149:
150: /* (non-Javadoc)
151: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isReviseOwn(java.lang.String)
152: */
153: public boolean isReviseOwn(String role) {
154: return hasPermission(role,
155: DefaultPermissionsManager.FUNCTION_REVISE_OWN);
156: }
157:
158: /* (non-Javadoc)
159: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isDeleteAny(java.lang.String)
160: */
161: public boolean isDeleteAny(String role) {
162: return hasPermission(role,
163: DefaultPermissionsManager.FUNCTION_DELETE_ANY);
164: }
165:
166: /* (non-Javadoc)
167: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isDeleteOwn(java.lang.String)
168: */
169: public boolean isDeleteOwn(String role) {
170: return hasPermission(role,
171: DefaultPermissionsManager.FUNCTION_DELETE_OWN);
172: }
173:
174: /* (non-Javadoc)
175: * @see org.sakaiproject.api.app.messageforums.DefaultPermissionsManager#isMarkAsRead(java.lang.String)
176: */
177: public boolean isMarkAsRead(String role) {
178: return hasPermission(role,
179: DefaultPermissionsManager.FUNCTION_MARK_AS_READ);
180: }
181:
182: private boolean hasPermission(String role, String permission) {
183: Collection realmList = new ArrayList();
184: realmList.add(getContextSiteId());
185: AuthzGroup authzGroup = null;
186: try {
187: authzGroup = authzGroupService
188: .getAuthzGroup("!site.helper");
189: } catch (Exception e) {
190: LOG.info("No site helper template found");
191: }
192: if (authzGroup != null) {
193: realmList.add(authzGroup.getId());
194: }
195: Set allowedFunctions = authzGroupService.getAllowedFunctions(
196: role, realmList);
197: return allowedFunctions.contains(permission);
198: }
199:
200: /**
201: * @return siteId
202: */
203: private String getContextSiteId() {
204: LOG.debug("getContextSiteId()");
205: return ("/site/" + ToolManager.getCurrentPlacement()
206: .getContext());
207: }
208: }
|