Line data Source code
1 : // Copyright (C) 2009 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.httpd; 16 : 17 : import com.google.gerrit.common.Nullable; 18 : import com.google.gerrit.entities.Account; 19 : import com.google.gerrit.extensions.events.GitReferenceUpdatedListener; 20 : import com.google.gerrit.server.AccessPath; 21 : import com.google.gerrit.server.CurrentUser; 22 : import com.google.gerrit.server.account.AuthResult; 23 : import com.google.inject.servlet.RequestScoped; 24 : import java.util.List; 25 : import java.util.concurrent.CopyOnWriteArrayList; 26 : 27 : /** 28 : * A thread safe class that contains details about a specific user web session. 29 : * 30 : * <p>WARNING: All implementors must have {@link RequestScoped} annotation to maintain thread 31 : * safety. 32 : */ 33 39 : public abstract class WebSession { 34 : public abstract boolean isSignedIn(); 35 : 36 : @Nullable 37 : public abstract String getXGerritAuth(); 38 : 39 : public abstract boolean isValidXGerritAuth(String keyIn); 40 : 41 : public abstract CurrentUser getUser(); 42 : 43 : public abstract void login(AuthResult res, boolean rememberMe); 44 : 45 : /** Set the user account for this current request only. */ 46 : public abstract void setUserAccountId(Account.Id id); 47 : 48 : public abstract boolean isAccessPathOk(AccessPath path); 49 : 50 : public abstract void setAccessPathOk(AccessPath path, boolean ok); 51 : 52 : public abstract void logout(); 53 : 54 : public abstract String getSessionId(); 55 : 56 : /** 57 : * Store and return the ref updates in this session. This class is {@link RequestScoped}, hence 58 : * this is thread safe. 59 : * 60 : * <p>The same session could perform separate requests one after another, so resetting the ref 61 : * updates is necessary between requests. 62 : */ 63 39 : private List<GitReferenceUpdatedListener.Event> refUpdatedEvents = new CopyOnWriteArrayList<>(); 64 : 65 : public List<GitReferenceUpdatedListener.Event> getRefUpdatedEvents() { 66 1 : return refUpdatedEvents; 67 : } 68 : 69 : public void addRefUpdatedEvents(GitReferenceUpdatedListener.Event event) { 70 24 : refUpdatedEvents.add(event); 71 24 : } 72 : 73 : public void resetRefUpdatedEvents() { 74 1 : refUpdatedEvents.clear(); 75 1 : } 76 : }