01: /*
02: * Copyright 2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: */
13: package org.pentaho.repository.cwm;
14:
15: import org.pentaho.core.session.IPentahoSession;
16: import org.pentaho.core.system.IPentahoInitializer;
17: import org.pentaho.pms.factory.CwmSchemaFactory;
18: import org.pentaho.pms.factory.CwmSchemaFactoryInterface;
19: import org.pentaho.pms.schema.concept.ConceptUtilityInterface;
20:
21: import com.pentaho.security.SecurityUtils;
22: import com.pentaho.security.acls.IAclHolder;
23:
24: public class SecurityAwareCwmSchemaFactory extends
25: PlatformCWMSchemaFactory implements IPentahoInitializer {
26:
27: IPentahoSession session;
28:
29: public SecurityAwareCwmSchemaFactory() {
30:
31: }
32:
33: public void init(IPentahoSession inSession) {
34: this .session = inSession;
35: }
36:
37: public void setSession(IPentahoSession value) {
38: this .session = value;
39: }
40:
41: public IPentahoSession getSession() {
42: return this .session;
43: }
44:
45: public static final int[] AccessTypeMap = new int[] {
46: IAclHolder.ACCESS_TYPE_READ, IAclHolder.ACCESS_TYPE_WRITE,
47: IAclHolder.ACCESS_TYPE_UPDATE,
48: IAclHolder.ACCESS_TYPE_DELETE,
49: IAclHolder.ACCESS_TYPE_ADMIN, IAclHolder.ACCESS_TYPE_ADMIN };
50:
51: public boolean hasAccess(int accessType,
52: ConceptUtilityInterface aclHolder) {
53: if (aclHolder != null) {
54: CWMAclHolder newHolder = new CWMAclHolder(aclHolder);
55: int mappedActionOperation = AccessTypeMap[accessType];
56: return SecurityUtils.hasAccess(newHolder,
57: mappedActionOperation, session);
58: } else {
59: if (accessType == CwmSchemaFactoryInterface.ACCESS_TYPE_SCHEMA_ADMIN) {
60: return SecurityUtils.isPentahoAdministrator(session);
61: }
62: }
63: return true;
64: }
65:
66: }
|