public interface

ImpersonationService

com.atlassian.crucible.spi.services.ImpersonationService

Class Overview

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.

Summary

Public Methods
abstract boolean canDoPrivilegedAction(PluginId id)
Can the plugin do a privleged action
abstract boolean canImpersonate(PluginId id, String userName)
Are we allowed to impersonate this user?
abstract <T, E extends Throwable> T doAsDefaultUser(PluginId id, Operation<T, E> operation)
abstract <T, E extends Throwable> T doAsUser(PluginId id, String userName, Operation<T, E> operation)
Execute an Operation as a particular user.
abstract <T, E extends Throwable> T doPrivilegedAction(PluginId id, Operation<T, E> operation)
Execute an Operation in a privileged mode.
abstract UserData getCurrentUser(PluginId id)
Get the current user, if any.
abstract UserData getDefaultUser(PluginId id)
Get the name of the default user configured for this plugin, if any

Public Methods

public abstract boolean canDoPrivilegedAction (PluginId id)

Can the plugin do a privleged action

Parameters
id the PluginId of the calling plugin
Returns
  • true if the plugin can to a privileged action, false otherwise

public abstract boolean canImpersonate (PluginId id, 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
  • true if we are allowed to impersonate this user, false otherwise

public abstract T doAsDefaultUser (PluginId id, Operation<T, E> operation)

This method is deprecated.
use doAsUser(com.atlassian.crucible.spi.PluginId, String, Operation) for impersonating a user or doPrivilegedAction(com.atlassian.crucible.spi.PluginId, Operation) for a privileged mode

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.

Parameters
id the PluginId of the calling plugin.
operation the Operation to perform.
Returns
  • the return value of Operation.perform()
Throws
if the operation throws an exception while executing.
Throwable

public abstract T doAsUser (PluginId id, String userName, Operation<T, E> operation)

Execute an Operation as a particular user.

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
when thrown by Operation.perform()
NotPermittedException when the given plugin is not allowed to impersonate the given user.
Throwable

public abstract T doPrivilegedAction (PluginId id, Operation<T, E> operation)

Execute an Operation in a privileged mode. Use this if your plugin requires access to data without having the context of a user. This is useful when running background tasks or listening to events. Use with precaution though, as you may expose a security vulnerability in your plugin and/or FishEye & Crucible

Parameters
id the PluginId of the calling plugin.
operation the Operation to perform.
Returns
  • the return value of Operation.perform()
Throws
if the operation throws an exception while executing.
Throwable

public abstract UserData getCurrentUser (PluginId id)

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)

public abstract 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.