Search in sources :

Example 1 with AnonymousUser

use of com.google.gerrit.server.AnonymousUser in project gerrit by GerritCodeReview.

the class RestApiServlet method checkUserSession.

private void checkUserSession(HttpServletRequest req) throws AuthException {
    CurrentUser user = globals.currentUser.get();
    if (isRead(req)) {
        user.setAccessPath(AccessPath.REST_API);
        user.setLastLoginExternalIdKey(globals.webSession.get().getLastLoginExternalId());
    } else if (user instanceof AnonymousUser) {
        throw new AuthException("Authentication required");
    } else if (!globals.webSession.get().isAccessPathOk(AccessPath.REST_API)) {
        throw new AuthException("Invalid authentication method. In order to authenticate, " + "prefix the REST endpoint URL with /a/ (e.g. http://example.com/a/projects/).");
    }
}
Also used : CurrentUser(com.google.gerrit.server.CurrentUser) AuthException(com.google.gerrit.extensions.restapi.AuthException) AnonymousUser(com.google.gerrit.server.AnonymousUser)

Example 2 with AnonymousUser

use of com.google.gerrit.server.AnonymousUser in project gerrit by GerritCodeReview.

the class PRED_current_user_1 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    CurrentUser curUser = StoredValues.CURRENT_USER.getOrNull(engine);
    if (curUser == null) {
        throw new EvaluationException("Current user not available in this rule type");
    }
    Term resultTerm;
    if (curUser.isIdentifiedUser()) {
        Account.Id id = curUser.getAccountId();
        resultTerm = new IntegerTerm(id.get());
    } else if (curUser instanceof AnonymousUser) {
        resultTerm = anonymous;
    } else if (curUser instanceof PeerDaemonUser) {
        resultTerm = peerDaemon;
    } else {
        throw new EvaluationException("Unknown user type");
    }
    if (!a1.unify(new StructureTerm(user, resultTerm), engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) CurrentUser(com.google.gerrit.server.CurrentUser) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) AnonymousUser(com.google.gerrit.server.AnonymousUser) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) EvaluationException(com.googlecode.prolog_cafe.exceptions.EvaluationException) PeerDaemonUser(com.google.gerrit.server.PeerDaemonUser)

Example 3 with AnonymousUser

use of com.google.gerrit.server.AnonymousUser in project gerrit by GerritCodeReview.

the class GroupsCollection method parse.

@Override
public GroupResource parse(TopLevelResource parent, IdString id) throws AuthException, ResourceNotFoundException {
    final CurrentUser user = self.get();
    if (user instanceof AnonymousUser) {
        throw new AuthException("Authentication required");
    } else if (!(user.isIdentifiedUser())) {
        throw new ResourceNotFoundException(id);
    }
    GroupDescription.Basic group = parseId(id.get());
    if (group == null) {
        throw new ResourceNotFoundException(id.get());
    }
    GroupControl ctl = groupControlFactory.controlFor(group);
    if (!ctl.isVisible()) {
        throw new ResourceNotFoundException(id);
    }
    return new GroupResource(ctl);
}
Also used : GroupDescription(com.google.gerrit.common.data.GroupDescription) GroupControl(com.google.gerrit.server.account.GroupControl) CurrentUser(com.google.gerrit.server.CurrentUser) AuthException(com.google.gerrit.extensions.restapi.AuthException) AnonymousUser(com.google.gerrit.server.AnonymousUser) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 4 with AnonymousUser

use of com.google.gerrit.server.AnonymousUser in project gerrit by GerritCodeReview.

the class AccountsCollection method parseIdOnBehalfOf.

private IdentifiedUser parseIdOnBehalfOf(@Nullable CurrentUser caller, String id) throws AuthException, OrmException {
    if (id.equals("self")) {
        CurrentUser user = self.get();
        if (user.isIdentifiedUser()) {
            return user.asIdentifiedUser();
        } else if (user instanceof AnonymousUser) {
            throw new AuthException("Authentication required");
        } else {
            return null;
        }
    }
    Account match = resolver.find(db.get(), id);
    if (match == null) {
        return null;
    }
    CurrentUser realUser = caller != null ? caller.getRealUser() : null;
    return userFactory.runAs(null, match.getId(), realUser);
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) CurrentUser(com.google.gerrit.server.CurrentUser) AuthException(com.google.gerrit.extensions.restapi.AuthException) AnonymousUser(com.google.gerrit.server.AnonymousUser)

Example 5 with AnonymousUser

use of com.google.gerrit.server.AnonymousUser in project gerrit by GerritCodeReview.

the class GroupsCollection method parse.

@Override
public GroupResource parse(TopLevelResource parent, IdString id) throws AuthException, ResourceNotFoundException {
    final CurrentUser user = self.get();
    if (user instanceof AnonymousUser) {
        throw new AuthException("Authentication required");
    } else if (!(user.isIdentifiedUser() || user.isInternalUser())) {
        throw new ResourceNotFoundException(id);
    }
    GroupDescription.Basic group = groupResolver.parseId(id.get());
    if (group == null) {
        throw new ResourceNotFoundException(id.get());
    }
    GroupControl ctl = groupControlFactory.controlFor(group);
    if (!ctl.isVisible()) {
        throw new ResourceNotFoundException(id);
    }
    return new GroupResource(ctl);
}
Also used : GroupDescription(com.google.gerrit.entities.GroupDescription) GroupControl(com.google.gerrit.server.account.GroupControl) CurrentUser(com.google.gerrit.server.CurrentUser) AuthException(com.google.gerrit.extensions.restapi.AuthException) AnonymousUser(com.google.gerrit.server.AnonymousUser) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) GroupResource(com.google.gerrit.server.group.GroupResource)

Aggregations

AnonymousUser (com.google.gerrit.server.AnonymousUser)5 CurrentUser (com.google.gerrit.server.CurrentUser)5 AuthException (com.google.gerrit.extensions.restapi.AuthException)4 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 Account (com.google.gerrit.reviewdb.client.Account)2 GroupControl (com.google.gerrit.server.account.GroupControl)2 GroupDescription (com.google.gerrit.common.data.GroupDescription)1 GroupDescription (com.google.gerrit.entities.GroupDescription)1 PeerDaemonUser (com.google.gerrit.server.PeerDaemonUser)1 GroupResource (com.google.gerrit.server.group.GroupResource)1 EvaluationException (com.googlecode.prolog_cafe.exceptions.EvaluationException)1 IntegerTerm (com.googlecode.prolog_cafe.lang.IntegerTerm)1 StructureTerm (com.googlecode.prolog_cafe.lang.StructureTerm)1 SymbolTerm (com.googlecode.prolog_cafe.lang.SymbolTerm)1 Term (com.googlecode.prolog_cafe.lang.Term)1