org.apache.ignite.igfs

## Class IgfsUserContext

- java.lang.Object
- - org.apache.ignite.igfs.IgfsUserContext

    public abstract class IgfsUserContext
    extends Object

Provides ability to execute IGFS code in a context of a specific user.

### Constructor Summary

Constructors
Constructor and Description
`IgfsUserContext()`

### Method Summary

Methods
`static 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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### IgfsUserContext

    public IgfsUserContext()

### Method Detail

#### doAs

    public static <T> T doAs(String user,
             IgniteOutClosure<T> c)

Executes given callable in the given user context. The main contract of this method is that `currentUser()` method invoked inside closure always returns 'user' this callable executed with.

Type Parameters:
  `T` - The type of closure result.
Parameters:
  `user` - the user name to invoke closure on behalf of.
  `c` - the closure to execute
Returns:
  the result of closure execution.
Throws:
  `IllegalArgumentException` - if user name is null or empty String or if the closure is null.

#### doAs

    public static <T> T doAs(String user,
             Callable<T> c)
                  throws Exception

Same contract that `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<Foo>() {
                  @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.");
          }
      }

Type Parameters:
  `T` - The type of callable result.
Parameters:
  `user` - the user name to invoke closure on behalf of.
  `c` - the Callable to execute
Returns:
  the result of closure execution.
Throws:
  `IllegalArgumentException` - if user name is null or empty String or if the closure is null.
  `Exception`

#### currentUser

    @Nullable
    public static String currentUser()

Gets the current context user. If this method is invoked outside of any `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.

Returns:
  The current user, may be null.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.8.0
Release Date | : December 5 2016