public abstract class IgfsUserContext extends Object
Constructor and Description |
---|
IgfsUserContext() |
Modifier and Type | Method and Description |
---|---|
static @Nullable String |
currentUser()
Gets the current context user.
|
static <T> T |
doAs(String user,
Callable<T> c)
Same contract that
doAs(String, IgniteOutClosure) has, but accepts
callable that throws checked Exception. |
static <T> T |
doAs(String user,
IgniteOutClosure<T> c)
Executes given callable in the given user context.
|
public static <T> T doAs(String user, IgniteOutClosure<T> c)
currentUser()
method invoked
inside closure always returns 'user' this callable executed with.T
- The type of closure result.user
- the user name to invoke closure on behalf of.c
- the closure to executeIllegalArgumentException
- if user name is null or empty String or if the closure is null.public static <T> T doAs(String user, Callable<T> c) throws Exception
doAs(String, IgniteOutClosure)
has, but accepts
callable that throws checked Exception.
The Exception is not ever wrapped anyhow.
If your Callable throws Some specific checked Exceptions, the recommended usage pattern is:
public Foo myOperation() throws MyCheckedException1, MyCheckedException2 { try { return IgfsUserContext.doAs(user, new Callable() { @Override public Foo call() throws MyCheckedException1, MyCheckedException2 { return makeSomeFoo(); // do the job } }); } catch (MyCheckedException1 | MyCheckedException2 | RuntimeException | Error e) { throw e; } catch (Exception e) { throw new AssertionError("Must never go there."); } }
T
- The type of callable result.user
- the user name to invoke closure on behalf of.c
- the Callable to executeIllegalArgumentException
- if user name is null or empty String or if the closure is null.Exception
@Nullable public static @Nullable String currentUser()
doAs(String, IgniteOutClosure)
on the call stack, it will
return null. Otherwise it will return the user name set in the most lower
doAs(String, IgniteOutClosure)
call on the call stack.
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.7.2 Release Date : February 6 2019