Skip to main content
summaryrefslogtreecommitdiffstats
blob: 492d95a16cf7dc3ade5c1cf1b4360defc6052e23 (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
/*
 * Copyright (c) 2013 Eike Stepper (Berlin, Germany) and others.
 * 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:
 *    Christian W. Damus (CEA LIST) - initial API and implementation
 */
package org.eclipse.emf.cdo.security.ui;

import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.security.User;
import org.eclipse.emf.cdo.security.internal.ui.bundle.OM;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOView;

import org.eclipse.core.runtime.IAdaptable;

/**
 * An optional security-management context that may be provided as an {@linkplain IAdaptable adapter}
 * by the view part to which the "Manage Security" command is contributed.
 * 
 * @author Christian W. Damus (CEA LIST)
 */
public interface ISecurityManagementContext
{

  public static final ISecurityManagementContext DEFAULT = new Default();

  /**
   * Obtains a view in which to open the security resource for editing.  If at all possible, this
   * should be a writable {@linkplain CDOTransaction transaction}.  If necessary, implementors are
   * welcome to open a new session logged in as the Administrator for this purpose.
   * 
   * @see #getSecurityResource(CDOView)
   * @see #disconnect(CDOView)
   */
  public CDOView connect(CDOSession session);

  /**
   * Releases a {@code view} previously {@linkplain #connect(CDOSession) obtained} from this context.
   * The caller must not attempt to use the {@code view} after this point because in all likelihood
   * it will be closed.
   * 
   * @see #connect(CDOSession)
   */
  public void disconnect(CDOView view);

  /**
   * Obtains the resource containing the security model for presentation in the Security Management
   * editor.
   */
  public CDOResource getSecurityResource(CDOView view);

  //
  // Nested types
  //

  public static class Default implements ISecurityManagementContext
  {
    public CDOView connect(CDOSession session)
    {
      if (session.isClosed())
      {
        return null;
      }
      if (User.ADMINISTRATOR.equals(session.getUserID()))
      {
        return session.openTransaction();
      }
      return session.openView();
    }

    public void disconnect(CDOView view)
    {
      view.close();
    }

    public CDOResource getSecurityResource(CDOView view)
    {
      CDOResource result = null;

      try
      {
        result = view.getResource("/security"); //$NON-NLS-1$
      }
      catch (Exception e)
      {
        OM.LOG.warn("Security model resource not available.", e); //$NON-NLS-1$
      }

      return result;
    }
  }
}

Back to the top