• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.server
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • Last Change
  • Annotate
  • Revision Log

root/trunk/components/server/src/ome/security/SecuritySystem.java

Revision 2665, 8.6 kB (checked in by jmoore, 5 months ago)

OmeroSecurity : Refactoring

  • Removed unused setEventContext
  • Moved remaining logic on addLog into CurrentDetails
  • Property svn:keywords set to
    Date
    Revision
    Id
    URL
Line 
1/*
2 * ome.security.SecuritySystem
3 *
4 *   Copyright 2006 University of Dundee. All rights reserved.
5 *   Use is subject to license terms supplied in LICENSE.txt
6 */
7
8package ome.security;
9
10// Java imports
11
12// Third-party libraries
13
14// Application-internal dependencies
15import ome.annotations.RevisionDate;
16import ome.annotations.RevisionNumber;
17import ome.conditions.ApiUsageException;
18import ome.conditions.SecurityViolation;
19import ome.model.IObject;
20import ome.model.internal.Details;
21import ome.model.internal.Permissions;
22import ome.model.internal.Token;
23import ome.system.EventContext;
24import ome.system.Principal;
25import ome.system.Roles;
26
27/**
28 * central security interface. All queries and actions that deal with a secure
29 * context should pass through an implementation of this interface.
30 *
31 * @author Josh Moore, josh.moore at gmx.de
32 * @version $Revision$, $Date$
33 * @see Token
34 * @see Details
35 * @see Permissions
36 * @see ACLEventListener
37 * @since 3.0-M3
38 */
39@RevisionDate("$Date$")
40@RevisionNumber("$Revision$")
41public interface SecuritySystem {
42
43    // ~ Login/logout
44    // =========================================================================
45
46    /**
47     * stores this {@link Principal} instance in the current thread context for
48     * authenticating and authorizing all actions. This method does <em>not</em>
49     * make any queries and is only a conduit for login information from the
50     * outer-most levels. Session bean implementations and other in-JVM clients
51     * can fill the {@link Principal}. Note, however, a call must first be made
52     * to {@link #loadEventContext(boolean)} or
53     * {@link #setEventContext(EventContext)} for some calls to be made to the
54     * {@link SecuritySystem}. In general, this means that execution must pass
55     * through the {@link ome.security.basic.EventHandler}
56     */
57    void login(Principal principal);
58
59    /**
60     * clears the top {@link Principal} instance from the current thread
61     * context.
62     *
63     * @return the number of remaining instances.
64     */
65    int logout();
66
67    /**
68     * Returns the current {@link EventContext}. This
69     *
70     * @return
71     */
72    EventContext getEventContext();
73
74    /**
75     * Prepares the current {@link EventContext} instance with the current
76     * {@link Principal}. An exception is thrown if there is none.
77     *
78     * @param isReadyOnly
79     */
80    void loadEventContext(boolean isReadyOnly);
81
82    /**
83     * Clears the content of the {@link EventContext}so that the
84     * {@link SecuritySystem} will no longer return true for {@link #isReady()}.
85     * The {@link Principal} set during {@link #login(Principal)} is retained.
86     */
87    void invalidateEventContext();
88
89    // ~ Checks
90    // =========================================================================
91    /**
92     * checks if this {@link SecuritySystem} instance is in a valid state. This
93     * includes that a user is properly logged in and that a connection is
94     * available to all necessary resources, e.g. database handle and mapping
95     * session.
96     *
97     * Not all methods require that the instance is ready.
98     *
99     * @return true if all methods on this interface are ready to be called.
100     */
101    boolean isReady();
102
103    /**
104     * checks if instances of the given type are "System-Types". Security logic
105     * for all system types is significantly different. In general, system types
106     * cannot be created, updated, or deleted by regular users, and are visible
107     * to all users.
108     *
109     * @param klass
110     *            A class which extends from {@link IObject}
111     * @return true if instances of the class argument can be considered system
112     *         types.
113     */
114    boolean isSystemType(Class<? extends IObject> klass);
115
116    /**
117     * checks that the {@link IObject} argument has been granted a {@link Token}
118     * by the {@link SecuritySystem}.
119     */
120    boolean hasPrivilegedToken(IObject obj);
121
122    // ~ Subsystem disabling
123    // =========================================================================
124
125    /**
126     * disables components of the backend for the current Thread. Further checks
127     * to {@link #isDisabled(String)} will return false. It is the
128     * responsibility of various security system components to then throw
129     * exceptions.
130     *
131     * @param ids
132     *            Non-null, non-empty array of String ids to disable.
133     */
134    void disable(String... ids);
135
136    /**
137     * enables components of the backend for the current Thread. Further checks
138     * to {@link #isDisabled(String)} will return true.
139     *
140     * @param ids
141     *            possibly null array of String ids. A null array specifies that
142     *            all subsystems are to be enabled. Otherwise, only those
143     *            subsystems specified by the ids.
144     */
145    void enable(String... ids);
146
147    /**
148     * checks if the listed id is disabled for the current Thread.
149     *
150     * @param id
151     *            non-null String representing a backend subsystem.
152     * @return true if the backend subsystem has been previously disabled by
153     *         calls to {@link #disable(String[])}
154     */
155    boolean isDisabled(String id);
156
157    // ~ Details checking (prime responsibility)
158    // =========================================================================
159
160    /**
161     * creates a new secure {@link IObject#getDetails() details} for transient
162     * entities. Non-privileged users can only edit the
163     * {@link Details#getPermissions() Permissions} field. Privileged users can
164     * use the {@link Details} object as a single-step <code>chmod</code> and
165     * <code>chgrp</code>.
166     *
167     * {@link #newTransientDetails(IObject) newTransientDetails} always returns
168     * a non-null Details that is not equivalent (==) to the Details argument.
169     *
170     * This method can be used from anywhere in the codebase to obtain a valid
171     * {@link Details}, but passing in an {@link IObject} instance with a null
172     * {@link Details}. However, if the {@link Details} is non-null, there is
173     * the possibility that this method will throw an exception.
174     *
175     * @throws ApiUsageException
176     *             if {@link SecuritySystem} is not {@link #isReady() ready}
177     * @throws SecurityViolation
178     *             if {@link Details} instance contains illegal values.
179     */
180    Details newTransientDetails(IObject iObject) throws ApiUsageException,
181            SecurityViolation;
182
183    /**
184     * checks that a non-privileged user has not attempted to edit the entity's
185     * {@link IObject#getDetails() security details}. Privileged users can set
186     * fields on {@link Details} as a single-step <code>chmod</code> and
187     * <code>chgrp</code>.
188     *
189     * {@link #checkManagedDetails(IObject, Details) managedDetails} may create
190     * a new Details instance and return that if needed. If the returned Details
191     * is not equivalent (==) to the argument Details, then values have been
192     * changed.
193     *
194     * @param iObject
195     *            non-null {@link IObject} instance. {@link Details} for that
196     *            instance can be null.
197     * @param trustedDetails
198     *            possibly null {@link Details} instance. These {@link Details}
199     *            are trusted in the sense that they have already once passed
200     *            through the {@link SecuritySystem}.
201     * @throws ApiUsageException
202     *             if {@link SecuritySystem} is not {@link #isReady() ready}
203     * @throws SecurityViolation
204     *             if {@link Details} instance contains illegal values.
205     */
206    Details checkManagedDetails(IObject iObject, Details trustedDetails)
207            throws ApiUsageException, SecurityViolation;
208
209    // ~ Actions
210    // =========================================================================
211    /**
212     * Allows actions to be performed with the
213     * {@link EventContext#isCurrentUserAdmin()} flag enabled but
214     * <em>without</em> changing the value of
215     * {@link EventContext#getCurrentUserId()}, so that ownerships are properly
216     * handled. The merging of detached entity graphs should be disabled for the
217     * extent of the execution.
218     *
219     * Note: the {@link ome.api.IUpdate} save methods should not be used, since
220     * they also accept detached entities, which could pose security risks.
221     * Instead load an entity from the database via {@link ome.api.IQuery},
222     * make changes, and save the changes with {@link ome.api.IUpdate#flush()}.
223     */
224    void runAsAdmin(AdminAction action);
225
226    <T extends IObject> T doAction(SecureAction action, T... objs);
227
228    // TODO do these need checks to isReady()?
229
230    // ~ Configured Elements
231    // =========================================================================
232    Roles getSecurityRoles();
233
234}
Note: See TracBrowser for help on using the browser.

Download in other formats:

  • Plain Text
  • Original Format

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/