01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/common/api-impl/src/java/org/theospi/portfolio/style/impl/StyleAuthorizerImpl.java $
03: * $Id: StyleAuthorizerImpl.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2006 The Sakai Foundation.
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.theospi.portfolio.style.impl;
21:
22: import java.util.List;
23:
24: import org.sakaiproject.metaobj.shared.mgt.IdManager;
25: import org.sakaiproject.metaobj.shared.model.Agent;
26: import org.sakaiproject.metaobj.shared.model.Id;
27: import org.theospi.portfolio.security.AuthorizationFacade;
28: import org.theospi.portfolio.security.app.ApplicationAuthorizer;
29: import org.theospi.portfolio.style.StyleFunctionConstants;
30: import org.theospi.portfolio.style.mgt.StyleManager;
31: import org.theospi.portfolio.style.model.Style;
32:
33: public class StyleAuthorizerImpl implements ApplicationAuthorizer {
34:
35: private StyleManager styleManager;
36: private IdManager idManager;
37: private List functions;
38:
39: public Boolean isAuthorized(AuthorizationFacade facade,
40: Agent agent, String function, Id id) {
41: if (function.equals(StyleFunctionConstants.CREATE_STYLE)) {
42: return new Boolean(facade.isAuthorized(agent, function, id));
43: } else if (function.equals(StyleFunctionConstants.EDIT_STYLE)) {
44: return isStyleAuth(facade, id, agent, function);
45: } else if (function
46: .equals(StyleFunctionConstants.PUBLISH_STYLE)) {
47: return isStyleAuth(facade, id, agent, function);
48: } else if (function
49: .equals(StyleFunctionConstants.GLOBAL_PUBLISH_STYLE)) {
50: return isStyleAuth(facade, id, agent, function);
51: } else if (function
52: .equals(StyleFunctionConstants.SUGGEST_GLOBAL_PUBLISH_STYLE)) {
53: return isStyleAuth(facade, id, agent, function);
54: } else if (function.equals(StyleFunctionConstants.DELETE_STYLE)) {
55: return isStyleAuth(facade, id, agent, function);
56: } else {
57: return null;
58: }
59: }
60:
61: protected Boolean isStyleAuth(AuthorizationFacade facade,
62: Id qualifier, Agent agent, String function) {
63: Style style = getStyleManager().getLightWeightStyle(qualifier);
64: if (style == null) {
65: return new Boolean(facade.isAuthorized(function, qualifier));
66: }
67: //owner can do anything
68: if (agent.equals(style.getOwner())) {
69: return new Boolean(true);
70: }
71: Id siteId = getIdManager().getId(style.getSiteId());
72: return new Boolean(facade.isAuthorized(function, siteId));
73: }
74:
75: public List getFunctions() {
76: return functions;
77: }
78:
79: public void setFunctions(List functions) {
80: this .functions = functions;
81: }
82:
83: public IdManager getIdManager() {
84: return idManager;
85: }
86:
87: public void setIdManager(IdManager idManager) {
88: this .idManager = idManager;
89: }
90:
91: public StyleManager getStyleManager() {
92: return styleManager;
93: }
94:
95: public void setStyleManager(StyleManager styleManager) {
96: this.styleManager = styleManager;
97: }
98:
99: }
|