// Copyright (C) 2008 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.sshd; import com.google.gerrit.reviewdb.Account; import com.google.gerrit.server.AccessPath; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.PeerDaemonUser; import com.google.gerrit.server.config.SitePaths; import com.google.gerrit.sshd.SshScope.Context; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; import org.apache.commons.codec.binary.Base64; import org.apache.commons.net.nntp.NewsgroupInfo; import org.apache.mina.core.future.IoFuture; import org.apache.mina.core.future.IoFutureListener; import org.apache.sshd.common.KeyPairProvider; import org.apache.sshd.common.SshException; import org.apache.sshd.common.util.Buffer; import org.apache.sshd.server.PublickeyAuthenticator; import org.apache.sshd.server.session.ServerSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; import java.net.SocketAddress; import java.security.KeyPair; import java.security.PublicKey; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Set; /** * Authenticates by public key through {@link com.google.gerrit.reviewdb.AccountSshKey} entities. */ @Singleton class ToyPubKeyAuth implements PublickeyAuthenticator { private final IdentifiedUser.GenericFactory userFactory; @Inject ToyPubKeyAuth(IdentifiedUser.GenericFactory uf) { userFactory = uf; } @Override public boolean authenticate(String username, PublicKey publicKey, ServerSession serverSession) { final SshSession sd = serverSession.getAttribute(SshSession.KEY); sd.authenticationSuccess(username, userFactory.create(new Account.Id(0))); return true; //To change body of implemented methods use File | Settings | File Templates. } }