com.atlassian.crucible.spi.services
Interface ImpersonationService


public interface ImpersonationService

Plugins may wish to perform operations as particular users.

This interface allows them to discover what they are allowed to do, and to choose which user they want to operate as.


Method Summary
 boolean canImpersonate(PluginId id, java.lang.String userName)
          Are we allowed to impersonate this user?
<T,E extends java.lang.Throwable>
T
doAsDefaultUser(PluginId id, Operation<T,E> operation)
          Execute an Operation as the default user.
<T,E extends java.lang.Throwable>
T
doAsUser(PluginId id, java.lang.String userName, Operation<T,E> operation)
          Execute an Operation as a particular user.
 UserData getCurrentUser(PluginId id)
          Get the current user, if any.
 UserData getDefaultUser(PluginId id)
          Get the name of the default user configured for this plugin, if any
 

Method Detail

doAsUser

<T,E extends java.lang.Throwable> T doAsUser(PluginId id,
                                             java.lang.String userName,
                                             Operation<T,E> operation)
           throws E extends java.lang.Throwable
Execute an Operation as a particular user.

Type Parameters:
T - the Type returned by the operation.
E - the type of Exception thrown by the Operation.
Parameters:
id - the PluginId of the calling plugin.
userName - a String naming the user to impersonate.
operation - the Operation to perform.
Returns:
the return value of Operation.perform()
Throws:
E - when thrown by Operation.perform()
NotPermittedException - when the given plugin is not allowed to impersonate the given user.
E extends java.lang.Throwable

doAsDefaultUser

<T,E extends java.lang.Throwable> T doAsDefaultUser(PluginId id,
                                                    Operation<T,E> operation)
                  throws E extends java.lang.Throwable
Execute an Operation as the default user. If the current user is *not* anonymous, this operation will be performed as the current user. If the current user *is* anonymous, this Operation will be performed as the default user configured for this plugin. If no default user is configured for this plugin, and there is no current user, the operation will be performed as the anonymous user.

Type Parameters:
T - the Type returned by the operation.
E - the type of Exception thrown by the Operation.
Parameters:
id - the PluginId of the calling plugin.
operation - the Operation to perform.
Returns:
the return value of Operation.perform()
Throws:
E
E extends java.lang.Throwable

canImpersonate

boolean canImpersonate(PluginId id,
                       java.lang.String userName)
Are we allowed to impersonate this user?

Parameters:
id - the PluginId of the calling plugin.
userName - a String naming the user we wish to impersonate.
Returns:

getDefaultUser

UserData getDefaultUser(PluginId id)
Get the name of the default user configured for this plugin, if any

Parameters:
id - the PluginId of the calling plugin.
Returns:
the UserData structure for the default user, or null if none is configured.

getCurrentUser

UserData getCurrentUser(PluginId id)
                        throws ServerException
Get the current user, if any.

Parameters:
id - the PluginId of the calling plugin.
Returns:
the UserData for the current user, or null if there is no current user (either Crucible is being used anonymously, or this method is not being called from a request context)
Throws:
ServerException