Dissolve gerrit-server top-level directory
Change-Id: I538512dfe0f1bea774c01fdd45fa410a45634011
This commit is contained in:
committed by
Dave Borowitz
parent
472396c797
commit
376a7bbb64
26
java/com/google/gerrit/server/ssh/NoSshInfo.java
Normal file
26
java/com/google/gerrit/server/ssh/NoSshInfo.java
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2010 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.ssh;
|
||||
|
||||
import com.jcraft.jsch.HostKey;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class NoSshInfo implements SshInfo {
|
||||
@Override
|
||||
public List<HostKey> getHostKeys() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
43
java/com/google/gerrit/server/ssh/NoSshKeyCache.java
Normal file
43
java/com/google/gerrit/server/ssh/NoSshKeyCache.java
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright (C) 2010 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.ssh;
|
||||
|
||||
import com.google.gerrit.common.errors.InvalidSshKeyException;
|
||||
import com.google.gerrit.reviewdb.client.AccountSshKey;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class NoSshKeyCache implements SshKeyCache, SshKeyCreator {
|
||||
|
||||
public static Module module() {
|
||||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(SshKeyCache.class).to(NoSshKeyCache.class);
|
||||
bind(SshKeyCreator.class).to(NoSshKeyCache.class);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evict(String username) {}
|
||||
|
||||
@Override
|
||||
public AccountSshKey create(AccountSshKey.Id id, String encoded) throws InvalidSshKeyException {
|
||||
throw new InvalidSshKeyException();
|
||||
}
|
||||
}
|
||||
25
java/com/google/gerrit/server/ssh/NoSshModule.java
Normal file
25
java/com/google/gerrit/server/ssh/NoSshModule.java
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2010 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.ssh;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
/** Disables the SSH support by stubbing out relevant objects. */
|
||||
public class NoSshModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(SshInfo.class).to(NoSshInfo.class);
|
||||
}
|
||||
}
|
||||
103
java/com/google/gerrit/server/ssh/SshAddressesModule.java
Normal file
103
java/com/google/gerrit/server/ssh/SshAddressesModule.java
Normal file
@@ -0,0 +1,103 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.ssh;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.util.SocketUtil;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SshAddressesModule extends AbstractModule {
|
||||
private static final Logger log = LoggerFactory.getLogger(SshAddressesModule.class);
|
||||
|
||||
public static final int DEFAULT_PORT = 29418;
|
||||
public static final int IANA_SSH_PORT = 22;
|
||||
|
||||
@Override
|
||||
protected void configure() {}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@SshListenAddresses
|
||||
public List<SocketAddress> getListenAddresses(@GerritServerConfig Config cfg) {
|
||||
List<SocketAddress> listen = Lists.newArrayListWithExpectedSize(2);
|
||||
String[] want = cfg.getStringList("sshd", null, "listenaddress");
|
||||
if (want == null || want.length == 0) {
|
||||
listen.add(new InetSocketAddress(DEFAULT_PORT));
|
||||
return listen;
|
||||
}
|
||||
|
||||
if (want.length == 1 && isOff(want[0])) {
|
||||
return listen;
|
||||
}
|
||||
|
||||
for (String desc : want) {
|
||||
try {
|
||||
listen.add(SocketUtil.resolve(desc, DEFAULT_PORT));
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.error("Bad sshd.listenaddress: " + desc + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return listen;
|
||||
}
|
||||
|
||||
private static boolean isOff(String listenHostname) {
|
||||
return "off".equalsIgnoreCase(listenHostname)
|
||||
|| "none".equalsIgnoreCase(listenHostname)
|
||||
|| "no".equalsIgnoreCase(listenHostname);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@SshAdvertisedAddresses
|
||||
List<String> getAdvertisedAddresses(
|
||||
@GerritServerConfig Config cfg, @SshListenAddresses List<SocketAddress> listen) {
|
||||
String[] want = cfg.getStringList("sshd", null, "advertisedaddress");
|
||||
if (want.length > 0) {
|
||||
return Arrays.asList(want);
|
||||
}
|
||||
List<InetSocketAddress> pub = new ArrayList<>();
|
||||
List<InetSocketAddress> local = new ArrayList<>();
|
||||
|
||||
for (SocketAddress addr : listen) {
|
||||
if (addr instanceof InetSocketAddress) {
|
||||
InetSocketAddress inetAddr = (InetSocketAddress) addr;
|
||||
if (inetAddr.getAddress().isLoopbackAddress()) {
|
||||
local.add(inetAddr);
|
||||
} else {
|
||||
pub.add(inetAddr);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pub.isEmpty()) {
|
||||
pub = local;
|
||||
}
|
||||
List<String> adv = Lists.newArrayListWithCapacity(pub.size());
|
||||
for (InetSocketAddress addr : pub) {
|
||||
adv.add(SocketUtil.format(addr, IANA_SSH_PORT));
|
||||
}
|
||||
return adv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.ssh;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
/**
|
||||
* Marker on the list of {@link java.net.SocketAddress}es configured to be advertised by the server.
|
||||
*/
|
||||
@Retention(RUNTIME)
|
||||
@BindingAnnotation
|
||||
public @interface SshAdvertisedAddresses {}
|
||||
22
java/com/google/gerrit/server/ssh/SshInfo.java
Normal file
22
java/com/google/gerrit/server/ssh/SshInfo.java
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2009 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.ssh;
|
||||
|
||||
import com.jcraft.jsch.HostKey;
|
||||
import java.util.List;
|
||||
|
||||
public interface SshInfo {
|
||||
List<HostKey> getHostKeys();
|
||||
}
|
||||
20
java/com/google/gerrit/server/ssh/SshKeyCache.java
Normal file
20
java/com/google/gerrit/server/ssh/SshKeyCache.java
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright (C) 2009 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.ssh;
|
||||
|
||||
/** Permits controlling the contents of the SSH key cache area. */
|
||||
public interface SshKeyCache {
|
||||
void evict(String username);
|
||||
}
|
||||
22
java/com/google/gerrit/server/ssh/SshKeyCreator.java
Normal file
22
java/com/google/gerrit/server/ssh/SshKeyCreator.java
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2016 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.ssh;
|
||||
|
||||
import com.google.gerrit.common.errors.InvalidSshKeyException;
|
||||
import com.google.gerrit.reviewdb.client.AccountSshKey;
|
||||
|
||||
public interface SshKeyCreator {
|
||||
AccountSshKey create(AccountSshKey.Id id, String encoded) throws InvalidSshKeyException;
|
||||
}
|
||||
28
java/com/google/gerrit/server/ssh/SshListenAddresses.java
Normal file
28
java/com/google/gerrit/server/ssh/SshListenAddresses.java
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.ssh;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
/**
|
||||
* Marker on the list of {@link java.net.SocketAddress}es on which the SSH daemon is configured to
|
||||
* listen.
|
||||
*/
|
||||
@Retention(RUNTIME)
|
||||
@BindingAnnotation
|
||||
public @interface SshListenAddresses {}
|
||||
Reference in New Issue
Block a user