Search in sources :

Example 1 with NotSignedInException

use of com.google.gerrit.exceptions.NotSignedInException in project gerrit by GerritCodeReview.

the class ThreadLocalRequestContext method module.

public static Module module() {
    return new AbstractModule() {

        @Override
        protected void configure() {
            bind(ThreadLocalRequestContext.class);
            bind(RequestContext.class).annotatedWith(Names.named(FALLBACK)).to(FallbackRequestContext.class);
        }

        @Provides
        RequestContext provideRequestContext(@Named(FALLBACK) RequestContext fallback) {
            return MoreObjects.firstNonNull(local.get(), fallback);
        }

        @Provides
        CurrentUser provideCurrentUser(RequestContext ctx) {
            return ctx.getUser();
        }

        @Provides
        IdentifiedUser provideCurrentUser(CurrentUser user) {
            if (user.isIdentifiedUser()) {
                return user.asIdentifiedUser();
            }
            throw new ProvisionException(NotSignedInException.MESSAGE, new NotSignedInException());
        }
    };
}
Also used : Named(com.google.inject.name.Named) ProvisionException(com.google.inject.ProvisionException) CurrentUser(com.google.gerrit.server.CurrentUser) NotSignedInException(com.google.gerrit.exceptions.NotSignedInException) AbstractModule(com.google.inject.AbstractModule)

Aggregations

NotSignedInException (com.google.gerrit.exceptions.NotSignedInException)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 AbstractModule (com.google.inject.AbstractModule)1 ProvisionException (com.google.inject.ProvisionException)1 Named (com.google.inject.name.Named)1