Skip to main content
summaryrefslogtreecommitdiffstats
blob: 56d1d3bc6687fed17c075c93577ce10c3328d609 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*******************************************************************************
 * Copyright (c) 2010 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.access.internal;

import java.util.Collection;
import java.util.logging.Level;
import org.eclipse.osee.framework.access.IAccessProvider;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.enums.PermissionEnum;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.IBasicArtifact;
import org.eclipse.osee.framework.core.model.access.AccessData;
import org.eclipse.osee.framework.core.model.access.AccessDetail;
import org.eclipse.osee.framework.core.model.access.Scope;
import org.eclipse.osee.framework.core.services.IAccessControlService;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.relation.RelationLink;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public final class ObjectAccessProviderProxy implements IAccessProvider {

   private BundleContext bundleContext;

   public void start(BundleContext bundleContext) {
      this.bundleContext = bundleContext;
   }

   public void stop() {
      bundleContext = null;
   }

   private AccessControlService getAccessService() {
      AccessControlService toReturn = null;

      ServiceReference<IAccessControlService> reference =
         bundleContext.getServiceReference(IAccessControlService.class);
      IAccessControlService service = bundleContext.getService(reference);
      if (service instanceof AccessControlServiceProxy) {
         AccessControlServiceProxy proxy = (AccessControlServiceProxy) service;
         toReturn = proxy.getProxiedObject();
      } else {
         OseeLog.log(AccessControlHelper.class, Level.SEVERE, "Error initializing ObjectAccessProvider");
      }
      return toReturn;
   }

   @Override
   public void computeAccess(IBasicArtifact<?> userArtifact, Collection<?> objToCheck, AccessData accessData) throws OseeCoreException {
      for (Object object : objToCheck) {
         if (object instanceof Artifact) {
            setArtifactAccessData(userArtifact, (Artifact) object, accessData);
         } else if (object instanceof Branch) {
            setBranchAccessData(userArtifact, (Branch) object, accessData);
         } else if (object instanceof RelationLink) {
            RelationLink relation = (RelationLink) object;
            Artifact artifactA = relation.getArtifactA();
            Artifact artifactB = relation.getArtifactB();
            setArtifactAccessData(userArtifact, artifactA, accessData);
            setArtifactAccessData(userArtifact, artifactB, accessData);
         }
      }
   }

   private void setArtifactAccessData(IBasicArtifact<?> userArtifact, Artifact artifact, AccessData accessData) throws OseeCoreException {
      setBranchAccessData(userArtifact, artifact.getBranch(), accessData);
      String reason = "Legacy Artifact Permission";
      PermissionEnum userPermission = getAccessService().getArtifactPermission(userArtifact, artifact);

      if (userPermission == null) {
         reason = "User Permission was null in setArtifactAccessData  - artifact is read only";
         userPermission = PermissionEnum.READ;
      } else if (artifact.isHistorical()) {
         userPermission = PermissionEnum.READ;
         reason = "User Permission set to Read - artifact is historical  - artifact is read only";
      } else if (!BranchManager.isEditable(artifact.getBranch())) {
         userPermission = PermissionEnum.READ;
         reason = "User Permission set to Read - artifact's branch is not editable - artifact is read only";
      }
      //artifact.isDeleted()
      accessData.add(artifact,
         new AccessDetail<IBasicArtifact<Artifact>>(artifact, userPermission, Scope.createLegacyScope(), reason));
   }

   private void setBranchAccessData(IBasicArtifact<?> userArtifact, IOseeBranch branch, AccessData accessData) throws OseeCoreException {
      String reason = "Legacy Branch Permission";
      PermissionEnum userPermission = getAccessService().getBranchPermission(userArtifact, branch);
      accessData.add(branch, new AccessDetail<IOseeBranch>(branch, userPermission, Scope.createLegacyScope(), reason));
   }

}

Back to the top