@@ -0,0 +1,2953 @@
+// Copyright (C) 2013 The Android Open Source Project%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A// http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0Apackage com.google.gerrit.server.securestore;%0A%0Aimport com.google.gerrit.common.FileUtil;%0Aimport com.google.gerrit.extensions.annotations.Export;%0Aimport com.google.gerrit.server.config.SitePaths;%0Aimport com.google.inject.Inject;%0Aimport com.google.inject.Singleton;%0A%0Aimport org.eclipse.jgit.internal.storage.file.LockFile;%0Aimport org.eclipse.jgit.lib.Constants;%0Aimport org.eclipse.jgit.storage.file.FileBasedConfig;%0Aimport org.eclipse.jgit.util.FS;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0A%0A@Singleton%0A@Export(DefaultSecureStore.NAME)%0Apublic class DefaultSecureStore implements SecureStore %7B%0A  public static final String NAME = %22default%22;%0A%0A  private final FileBasedConfig sec;%0A%0A  @Inject%0A  DefaultSecureStore(SitePaths site) %7B%0A    File secureConfig = new File(site.etc_dir, %22secure.config%22);%0A    sec = new FileBasedConfig(secureConfig, FS.DETECTED);%0A    try %7B%0A      sec.load();%0A    %7D catch (Exception e) %7B%0A      throw new RuntimeException(%22Cannot load secure.config%22, e);%0A    %7D%0A  %7D%0A%0A  @Override%0A  public String get(String section, String subsection, String name) %7B%0A    return sec.getString(section, subsection, name);%0A  %7D%0A%0A  @Override%0A  public void set(String section, String subsection, String name, String value) %7B%0A    if (value != null) %7B%0A      sec.setString(section, subsection, name, value);%0A    %7D else %7B%0A      sec.unset(section, subsection, name);%0A    %7D%0A    save();%0A  %7D%0A%0A  @Override%0A  public void unset(String section, String subsection, String name) %7B%0A    sec.unset(section, subsection, name);%0A    save();%0A  %7D%0A%0A  private void save() %7B%0A    try %7B%0A      saveSecure(sec);%0A    %7D catch (IOException e) %7B%0A      throw new RuntimeException(%22Cannot save secure.config%22, e);%0A    %7D%0A  %7D%0A%0A  private static void saveSecure(final FileBasedConfig sec) throws IOException %7B%0A    if (FileUtil.modified(sec)) %7B%0A      final byte%5B%5D out = Constants.encode(sec.toText());%0A      final File path = sec.getFile();%0A      final LockFile lf = new LockFile(path, FS.DETECTED);%0A      if (!lf.lock()) %7B%0A        throw new IOException(%22Cannot lock %22 + path);%0A      %7D%0A      try %7B%0A        FileUtil.chmod(0600, new File(path.getParentFile(), path.getName()%0A            + %22.lock%22));%0A        lf.write(out);%0A        if (!lf.commit()) %7B%0A          throw new IOException(%22Cannot commit write to %22 + path);%0A        %7D%0A      %7D finally %7B%0A        lf.unlock();%0A      %7D%0A    %7D%0A  %7D%0A%7D%0A

Add default SecureStore implementation