├── .gitignore
├── .travis.yml
├── LICENSE
├── NOTES
├── README.md
├── TODO
├── checkstyle-suppressions.xml
├── create_config.sh
├── pom.xml
├── src
├── main
│ ├── filtered-resources
│ │ └── VERSION.properties
│ ├── java
│ │ ├── com
│ │ │ └── yahoo
│ │ │ │ └── sshd
│ │ │ │ ├── authentication
│ │ │ │ ├── MultiUserPKAuthenticator.java
│ │ │ │ └── file
│ │ │ │ │ ├── AuthorizedKeysFileScanner.java
│ │ │ │ │ ├── FileTreeWalkerInterface.java
│ │ │ │ │ ├── HomeDirectoryScanningPKAuthenticator.java
│ │ │ │ │ ├── HomeDirectoryScanningPKEventHandler.java
│ │ │ │ │ ├── HomeDirectoryTreeWalker.java
│ │ │ │ │ ├── LocalUserPKAuthenticator.java
│ │ │ │ │ └── MultiUserAuthorizedKeysMap.java
│ │ │ │ ├── authorization
│ │ │ │ ├── ArtifactoryAuthorizer.java
│ │ │ │ ├── ArtifactoryAuthorizerProviderFactory.java
│ │ │ │ ├── ArtifactoryPermTargetType.java
│ │ │ │ ├── WideOpenGatesAuthrorizer.java
│ │ │ │ └── file
│ │ │ │ │ ├── ArtifactoryAuthFileEventHandler.java
│ │ │ │ │ ├── ArtifactoryAuthFileWalker.java
│ │ │ │ │ ├── ArtifactoryAuthorizerFileScanner.java
│ │ │ │ │ ├── AuthFileParser.java
│ │ │ │ │ ├── AuthUser.java
│ │ │ │ │ ├── DefaultArtifactoryAuthorizerProviderFactory.java
│ │ │ │ │ ├── FileBasedArtifactoryAuthorizer.java
│ │ │ │ │ └── PermTarget.java
│ │ │ │ ├── common
│ │ │ │ └── forward
│ │ │ │ │ ├── DenyingTcpipForwarder.java
│ │ │ │ │ └── DenyingTcpipForwarderFactory.java
│ │ │ │ ├── server
│ │ │ │ ├── SshServerWrapper.java
│ │ │ │ ├── Sshd.java
│ │ │ │ ├── TestCiphers.java
│ │ │ │ ├── command
│ │ │ │ │ ├── AbstractScpCommand.java
│ │ │ │ │ ├── DefaultScpCommandFactory.java
│ │ │ │ │ ├── DelegatingCommandFactory.java
│ │ │ │ │ ├── MkdirCommand.java
│ │ │ │ │ ├── NewScpCommand.java
│ │ │ │ │ ├── NewScpHelper.java
│ │ │ │ │ ├── NullScpCommand.java
│ │ │ │ │ ├── NullScpCommandFactory.java
│ │ │ │ │ └── ScpCommandSessionListener.java
│ │ │ │ ├── filesystem
│ │ │ │ │ ├── AFClientCache.java
│ │ │ │ │ ├── ArtifactoryFileSystemFactory.java
│ │ │ │ │ ├── ArtifactoryFileSystemView.java
│ │ │ │ │ ├── ArtifactorySshFile.java
│ │ │ │ │ ├── DevNullSshFile.java
│ │ │ │ │ ├── GuiceFsFactory.java
│ │ │ │ │ ├── InjectableArtifactoryFileSystemFactory.java
│ │ │ │ │ └── NameLengthTuple.java
│ │ │ │ ├── filters
│ │ │ │ │ ├── DenyingForwardingFilter.java
│ │ │ │ │ └── LocalForwardingFilter.java
│ │ │ │ ├── jetty
│ │ │ │ │ ├── JettyRunnableComponent.java
│ │ │ │ │ ├── JettyServer.java
│ │ │ │ │ └── JettyServiceSetting.java
│ │ │ │ ├── logging
│ │ │ │ │ ├── AbstractNCSARequestLog.java
│ │ │ │ │ ├── ConfigurableRolloverOuputStream.java
│ │ │ │ │ ├── DefaultRequestLogFactory.java
│ │ │ │ │ ├── LoggingHelper.java
│ │ │ │ │ ├── NCSARequestLog.java
│ │ │ │ │ ├── RequestLogFactory.java
│ │ │ │ │ ├── SshRequestHandler.java
│ │ │ │ │ ├── SshRequestInfo.java
│ │ │ │ │ ├── SshRequestLog.java
│ │ │ │ │ ├── SshRequestLogListener.java
│ │ │ │ │ └── SshRequestStatus.java
│ │ │ │ ├── settings
│ │ │ │ │ ├── SshdConfigurationException.java
│ │ │ │ │ ├── SshdProxySettings.java
│ │ │ │ │ ├── SshdProxySettingsFactory.java
│ │ │ │ │ ├── SshdSettingsBuilder.java
│ │ │ │ │ ├── SshdSettingsFactory.java
│ │ │ │ │ ├── SshdSettingsInterface.java
│ │ │ │ │ └── SshdSettingsModule.java
│ │ │ │ └── shell
│ │ │ │ │ ├── ForwardingShellFactory.java
│ │ │ │ │ ├── ForwardingShellWrapper.java
│ │ │ │ │ ├── GroovyShellFactory.java
│ │ │ │ │ ├── GroovyShellWrapper.java
│ │ │ │ │ ├── MessageShellFactory.java
│ │ │ │ │ ├── SshProxyMessage.java
│ │ │ │ │ └── groovy
│ │ │ │ │ ├── GroovyPrompt.java
│ │ │ │ │ └── OutputStreamErrorHandler.java
│ │ │ │ ├── tools
│ │ │ │ └── artifactory
│ │ │ │ │ ├── ArtifactMetaData.java
│ │ │ │ │ ├── ArtifactMetaDataBuilder.java
│ │ │ │ │ ├── ArtifactMetaDataParseFailureException.java
│ │ │ │ │ ├── ArtifactNotFoundException.java
│ │ │ │ │ ├── ArtifactoryBadRequestException.java
│ │ │ │ │ ├── ArtifactoryClientFactory.java
│ │ │ │ │ ├── ArtifactoryExceptionInformation.java
│ │ │ │ │ ├── ArtifactoryFileNotFoundException.java
│ │ │ │ │ ├── ArtifactoryIOException.java
│ │ │ │ │ ├── ArtifactoryInformation.java
│ │ │ │ │ ├── ArtifactoryNoReadPermissionException.java
│ │ │ │ │ ├── ArtifactoryNoWritePermissionException.java
│ │ │ │ │ ├── Checksum.java
│ │ │ │ │ ├── ChildArtifact.java
│ │ │ │ │ ├── JFrogArtifactoryClientHelper.java
│ │ │ │ │ ├── JFrogArtifactoryClientHelperFactoryImpl.java
│ │ │ │ │ └── RepositoryAndPath.java
│ │ │ │ └── utils
│ │ │ │ ├── AuthUserData.java
│ │ │ │ ├── DirectoryWatchService.java
│ │ │ │ ├── DirectoryWatchServiceEventHandler.java
│ │ │ │ ├── RunnableComponent.java
│ │ │ │ ├── ThreadSafeSimpleDateFormat.java
│ │ │ │ ├── ThreadUtils.java
│ │ │ │ └── streams
│ │ │ │ ├── AsyncHandler.java
│ │ │ │ ├── AsyncHandlerImpl.java
│ │ │ │ ├── AsyncPipedOutputStream.java
│ │ │ │ ├── EmptyInputStream.java
│ │ │ │ ├── EmptyOutputStream.java
│ │ │ │ ├── InputStreamWithLength.java
│ │ │ │ ├── InputStreamWithLengthInterface.java
│ │ │ │ ├── LengthBasedInputStream.java
│ │ │ │ └── MessageOutputStream.java
│ │ └── org
│ │ │ └── apache
│ │ │ ├── karaf
│ │ │ └── shell
│ │ │ │ └── ssh
│ │ │ │ └── KarafPublickeyAuthenticator.java
│ │ │ └── sshd
│ │ │ └── server
│ │ │ ├── keyprovider
│ │ │ ├── PEMHostKeyProvider.java
│ │ │ ├── PEMHostKeyProviderFactory.java
│ │ │ └── SshdPEMHostKeyProviderFactory.java
│ │ │ └── shell
│ │ │ ├── Shell.java
│ │ │ ├── TtyFilterInputStream.java
│ │ │ └── TtyFilterOutputStream.java
│ └── resources
│ │ ├── asynchttpclient.properties
│ │ ├── logback.xml
│ │ └── sshd_proxy.properties
└── test
│ ├── java
│ ├── com
│ │ └── yahoo
│ │ │ └── sshd
│ │ │ ├── authentication
│ │ │ └── file
│ │ │ │ ├── TestFileTreeWalker.java
│ │ │ │ ├── TestLoader.java
│ │ │ │ ├── TestLocalUserPKAuthenticator.java
│ │ │ │ ├── TestPKAuth.java
│ │ │ │ └── TestPKUpdating.java
│ │ │ ├── authorization
│ │ │ └── file
│ │ │ │ ├── TestArtifactoryAuthorization.java
│ │ │ │ ├── TestAuthFileParser.java
│ │ │ │ └── TestAuthFileScanner.java
│ │ │ ├── server
│ │ │ ├── TestHostKey.java
│ │ │ ├── command
│ │ │ │ ├── TestNewScpCommand.java
│ │ │ │ ├── TestNewScpHelper.java
│ │ │ │ └── TestScpCommandSessionListener.java
│ │ │ ├── filesystem
│ │ │ │ ├── TestArtifactorySshFile.java
│ │ │ │ └── TestNameLengthTuple.java
│ │ │ ├── filters
│ │ │ │ └── TestForwardingFilters.java
│ │ │ ├── jetty
│ │ │ │ └── TestJettyRunnable.java
│ │ │ ├── logging
│ │ │ │ ├── TestSshRequestInfoBuilder.java
│ │ │ │ └── TestSshRequestLogListener.java
│ │ │ ├── settings
│ │ │ │ ├── TestChainedFactories.java
│ │ │ │ ├── TestCipherFactories.java
│ │ │ │ ├── TestOptions.java
│ │ │ │ └── Utils.java
│ │ │ └── shell
│ │ │ │ └── TestMessageShellFactory.java
│ │ │ ├── tools
│ │ │ └── artifactory
│ │ │ │ ├── TestArtifactoryMetaData.java
│ │ │ │ ├── TestExceptions.java
│ │ │ │ ├── TestFormat.java
│ │ │ │ ├── TestJFrogArtifactoryClientHelper.java
│ │ │ │ ├── TestRepoStripping.java
│ │ │ │ └── TestRepositoryAndPath.java
│ │ │ └── utils
│ │ │ └── streams
│ │ │ ├── StreamsUtils.java
│ │ │ ├── TestEmptyStream.java
│ │ │ ├── TestInputStreamWithLength.java
│ │ │ ├── TestLengthBasedInputStream.java
│ │ │ └── TestMessageOutputStream.java
│ └── org
│ │ └── apache
│ │ ├── karaf
│ │ └── shell
│ │ │ └── ssh
│ │ │ └── TestKarafPublickeyAuthenticator.java
│ │ └── sshd
│ │ └── common
│ │ └── kex
│ │ └── TestDH.java
│ └── resources
│ ├── MultiUserPKAuthenticator
│ ├── dir_test
│ │ └── home
│ │ │ └── dir_test
│ │ │ └── .ssh
│ │ │ └── authorized_keys
│ │ │ └── empty_dir
│ ├── empty_home
│ │ └── empty_dir
│ └── home
│ │ ├── areese
│ │ ├── .ssh
│ │ │ ├── authorized_keys
│ │ │ └── bar
│ │ ├── bar
│ │ └── foo_dir
│ │ │ └── bar
│ │ ├── bob
│ │ └── .ssh
│ │ │ └── authorized_keys
│ │ └── sam
│ │ └── .ssh
│ │ └── authorized_keys
│ ├── alwaysempty
│ └── empty
│ ├── auth
│ └── auth.txt
│ ├── conf
│ ├── debug.properties
│ └── sshd_proxy
│ │ ├── .gitkeep
│ │ ├── sshd_proxy.properties
│ │ └── test_env_mapping.properties
│ ├── developer_config
│ └── sshd_proxy.properties
│ ├── hostkey.pem
│ ├── invalid_keys
│ ├── test_ssh_key-0
│ ├── test_ssh_key-0.pub
│ ├── test_ssh_key-1
│ ├── test_ssh_key-1.pub
│ ├── test_ssh_key-2
│ ├── test_ssh_key-2.pub
│ ├── test_ssh_key-3
│ ├── test_ssh_key-3.pub
│ ├── test_ssh_key-4
│ ├── test_ssh_key-4.pub
│ ├── test_ssh_key-5
│ ├── test_ssh_key-5.pub
│ ├── test_ssh_key-6
│ ├── test_ssh_key-6.pub
│ ├── test_ssh_key-7
│ ├── test_ssh_key-7.pub
│ ├── test_ssh_key-8
│ ├── test_ssh_key-8.pub
│ ├── test_ssh_key-9
│ └── test_ssh_key-9.pub
│ ├── json
│ ├── directory.json
│ ├── empty.json
│ ├── file.json
│ └── parent_directory.json
│ ├── keys
│ ├── test_ssh_key-0
│ ├── test_ssh_key-0.pub
│ ├── test_ssh_key-1
│ ├── test_ssh_key-1.pub
│ ├── test_ssh_key-10
│ ├── test_ssh_key-10.pub
│ ├── test_ssh_key-11
│ ├── test_ssh_key-11.pub
│ ├── test_ssh_key-12
│ ├── test_ssh_key-12.pub
│ ├── test_ssh_key-13
│ ├── test_ssh_key-13.pub
│ ├── test_ssh_key-14
│ ├── test_ssh_key-14.pub
│ ├── test_ssh_key-15
│ ├── test_ssh_key-15.pub
│ ├── test_ssh_key-16
│ ├── test_ssh_key-16.pub
│ ├── test_ssh_key-17
│ ├── test_ssh_key-17.pub
│ ├── test_ssh_key-18
│ ├── test_ssh_key-18.pub
│ ├── test_ssh_key-19
│ ├── test_ssh_key-19.pub
│ ├── test_ssh_key-2
│ ├── test_ssh_key-2.pub
│ ├── test_ssh_key-3
│ ├── test_ssh_key-3.pub
│ ├── test_ssh_key-4
│ ├── test_ssh_key-4.pub
│ ├── test_ssh_key-5
│ ├── test_ssh_key-5.pub
│ ├── test_ssh_key-6
│ ├── test_ssh_key-6.pub
│ ├── test_ssh_key-7
│ ├── test_ssh_key-7.pub
│ ├── test_ssh_key-8
│ ├── test_ssh_key-8.pub
│ ├── test_ssh_key-9
│ └── test_ssh_key-9.pub
│ └── nested
│ └── home
│ └── areese
│ ├── .ssh
│ └── authorized_keys
│ └── nested
│ └── home
│ └── areese
│ └── .ssh
│ └── authorized_keys
└── travis
└── publish_to_bintray.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | .settings
3 | .classpath
4 | .project
5 | target
6 | .gradle
7 | *.swp
8 |
9 | # Package Files #
10 | *.jar
11 | *.war
12 | *.ear
13 | *.tgz
14 | .clover
15 | test-output
16 |
17 |
18 | dependency-reduced-pom.xml
19 |
20 | # config for running developers
21 | developer_config
22 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | jdk:
4 | - oraclejdk8
5 |
6 | after_success:
7 | - test "${TRAVIS_JDK_VERSION}" == "oraclejdk8" && mvn javadoc:jar
8 | - test "${TRAVIS_PULL_REQUEST}" == "false" && test "${TRAVIS_TAG}" != "" && ./travis/publish_to_bintray.sh
9 |
10 | branches:
11 | only:
12 | - master
13 | - /^(?i:sshd_proxy)-.*$/
14 |
15 | env:
16 | global:
17 | - secure: KVFZIMNqNr6IgGQFfUItvEwLoKoDiMLZPWrHs3DNWGgXXYTCNQdeETQmcZ6H6dy8fypPk2YKJnyNc5Vwnt9m8F19A6aR3cQL0d86zrGGyrayUvVVlYcpdKpVRgHqpOj6L+fi8amZhNIKG7Nnn5MqfjkBx89I8yo5HLuMNh4XM7A=
18 | - secure: Lf4CIwsDhltD9d48c/qMt8UHB7UrA2x7RatyD99t6LgfQKyBtHz2V2+DbbB7RewnJDV8C4hUNK21qIj6MOrDJM0cW9iUXlSJypdV8TjN0/NHHURkFVhpxK2cFghArVysmbWq05lRgkTjwniCI+hlLdpNdx6D/KfRgegvWI8mBNs=
19 |
--------------------------------------------------------------------------------
/NOTES:
--------------------------------------------------------------------------------
1 | To eat the auth.
2 |
3 |
4 | Need to set the channelFactories:
5 |
6 | ssh.setChannelFactories(channelFactories);
7 |
8 |
9 | if (channelFactories == null) {
10 | channelFactories = Arrays.asList(
11 | new ChannelSession.Factory(),
12 | new TcpipServerChannel.DirectTcpipFactory());
13 | }
14 |
15 |
16 | Need to override TcpipServerChannel.DirectTcpipFactory and friends.
17 |
18 | Need to override the IOServiceFactory:
19 | org.apache.sshd.common.forward.TcpipServerChannel
20 |
21 | connector = getSession().getFactoryManager().getIoServiceFactory()
22 | .createConnector(handler);
23 |
24 | Which returns org.apache.sshd.common.io.nio2.Nio2ServiceFactory, which we need to override
25 | To override org.apache.sshd.common.io.nio2.Nio2Connector, which returns an org.apache.sshd.common.io.nio2.Nio2Session
26 |
27 | Which is where we can finally start eating bytes
28 | and worse.
29 |
30 | The bytes we need to eat may come across multiple writes, so we'll have to set a start eating and stop eating flag across peeks.
31 |
32 | This will get really Ugly because if Authorization comes as multiple packets, we'll have to buffer that bit somewhere.
33 |
34 | Basically we need to buffer at least the Authorization header:
35 | WWW-Authenticate: Basic realm="nmrs_m7VKmomQ2YM3:"
36 |
37 | So we need at a minimum a buffer of WWW-Authenticate: size, and if we read WWW-AuthFoo, then we can write that buffer, and the rest of the following bits, while the previous writes would have been no-ops causing latency.
38 |
39 | Worse, yet we need a secondary buffer which is looking for the \r\n\r\n ala cheap-alive, and we need to eat that and write out our auth bits, then write the \r\n\r\n
40 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 |
2 | For auth override the following are required:
3 |
4 | 1. tcp port forwarding of port X to artifactory host:port.
5 | 2. Stream sniffing, we need to read the byte from the stream stripping out any Authorization headers.
6 | 3. Add the authorization header where it's: ssh_user:encrypted password.
7 | 4. encrypted password comes from encrypting a salt and the username.
8 | Another option is to just pass a token, and then have an artifactory plugin verify the token
9 | by connecting back to the ssh server, but that adds an extra RT.
10 | 5. if in the same jvm 4 may change to be more secure.
11 | 6. write a plugin to validate the password.
--------------------------------------------------------------------------------
/checkstyle-suppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/create_config.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # This script is used to one time create the config directory for development setup.
3 | ROOT=developer_config
4 |
5 | # gack die ROOT die.
6 | mkdir -p $ROOT/conf/sshd_proxy/
7 | mkdir -p $ROOT/logs/sshd_proxy
8 |
9 | # put the artifactory war here.
10 | mkdir -p $ROOT/webapps/
11 |
12 | # create the hostkey
13 | ssh-keygen -t dsa -f $ROOT/conf/sshd_proxy/ssh_host_dsa_key -C '' -N ''
14 |
15 | # copy the properties file
16 | cp src/test/resources/developer_config/sshd_proxy.properties $ROOT/conf/sshd_proxy/sshd_proxy.properties
17 |
18 | # fix ROOT to be our root.
19 | sed -i '' -e s/\$ROOT/$ROOT/g $ROOT/conf/sshd_proxy/sshd_proxy.properties
20 |
--------------------------------------------------------------------------------
/src/main/filtered-resources/VERSION.properties:
--------------------------------------------------------------------------------
1 | version=${pom.version}
2 | build.date=${timestamp}
3 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/authentication/MultiUserPKAuthenticator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authentication;
14 |
15 | import java.io.IOException;
16 | import java.security.PublicKey;
17 | import java.util.Collection;
18 |
19 | import org.apache.sshd.server.PublickeyAuthenticator;
20 | import org.apache.sshd.server.session.ServerSession;
21 |
22 | import com.yahoo.sshd.utils.DirectoryWatchService;
23 |
24 | public interface MultiUserPKAuthenticator extends PublickeyAuthenticator {
25 |
26 | /**
27 | * Called on initial load to start any tasks that will keep the authenticator up to date. Most implementations use
28 | * this to start a {@link DirectoryWatchService} which watches for changes.
29 | *
30 | * @throws IOException
31 | */
32 | void start() throws IOException;
33 |
34 | /**
35 | * Authenticate a user in the map
36 | *
37 | * @param username
38 | * @param publicKey
39 | * @param session
40 | * @return
41 | */
42 | @Override
43 | boolean authenticate(String username, PublicKey publicKey, ServerSession session);
44 |
45 | /**
46 | * If this returns <1, the loading code assumes and error and fails startup.
47 | *
48 | * @return the number of keys loaded.
49 | */
50 | int getNumberOfKeysLoads();
51 |
52 | /**
53 | * List all of the users this map contains
54 | */
55 | Collection getUsers();
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/authentication/file/FileTreeWalkerInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authentication.file;
14 |
15 | import java.io.IOException;
16 | import java.nio.file.Path;
17 |
18 | import com.yahoo.sshd.utils.DirectoryWatchService;
19 |
20 | /**
21 | * This interface is for listening for events from {@link DirectoryWatchService}.
22 | * {@link FileTreeWalkerInterface#registerAll(Path)} is used to register a direcotry
23 | * @author areese
24 | *
25 | */
26 | public interface FileTreeWalkerInterface {
27 | void registerAll(final Path start) throws IOException;
28 |
29 | void register(Path dir) throws IOException;
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/authorization/ArtifactoryAuthorizer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authorization;
14 |
15 |
16 | public interface ArtifactoryAuthorizer {
17 |
18 | public boolean authorized(String repositoryName, String userName, ArtifactoryPermTargetType permissionTarget);
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/authorization/ArtifactoryAuthorizerProviderFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authorization;
14 |
15 | import com.yahoo.sshd.server.settings.SshdSettingsInterface;
16 |
17 | public interface ArtifactoryAuthorizerProviderFactory {
18 |
19 | ArtifactoryAuthorizer artifactoryAuthorizerProvider(SshdSettingsInterface settings);
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/authorization/ArtifactoryPermTargetType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authorization;
14 |
15 | public enum ArtifactoryPermTargetType {
16 | READ("read"), //
17 | WRITE("write"); //
18 |
19 | public String name;
20 |
21 | private ArtifactoryPermTargetType(String name) {
22 | this.name = name;
23 | }
24 |
25 | public static ArtifactoryPermTargetType parseType(String type) {
26 | if (READ.name.equalsIgnoreCase(type)) {
27 | return READ;
28 | }
29 |
30 | if (WRITE.name.equalsIgnoreCase(type)) {
31 | return WRITE;
32 | }
33 |
34 | throw new IllegalArgumentException("Unknown ArtifactoryPermTargetType: " + type);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/authorization/WideOpenGatesAuthrorizer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authorization;
14 |
15 | import org.slf4j.Logger;
16 | import org.slf4j.LoggerFactory;
17 |
18 | import com.yahoo.sshd.authorization.file.FileBasedArtifactoryAuthorizer;
19 | import com.yahoo.sshd.server.settings.SshdSettingsInterface;
20 |
21 | /**
22 | * Added this to make doing dev work a lot less painful. I don't want to setup an auth.txt for doing local development,
23 | * so add a flag. The problem is, we probably should flag this separately, because later we might create a developer
24 | * version that hosts more bits. When that is done, we'll have to rethink this.
25 | *
26 | * @author areese
27 | *
28 | */
29 | public class WideOpenGatesAuthrorizer implements ArtifactoryAuthorizer {
30 | private static final Logger LOG = LoggerFactory.getLogger(FileBasedArtifactoryAuthorizer.class);
31 |
32 | public WideOpenGatesAuthrorizer(SshdSettingsInterface settings) {
33 |
34 | }
35 |
36 | @Override
37 | public boolean authorized(String repositoryName, String userName, ArtifactoryPermTargetType permissionTarget) {
38 | LOG.info("Development mode, blindly allowing user: '{}' access to repo: '{}' with target '{}", userName,
39 | repositoryName, permissionTarget);
40 | return true;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/authorization/file/ArtifactoryAuthFileWalker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authorization.file;
14 |
15 | import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
16 | import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
17 | import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
18 |
19 | import java.io.File;
20 | import java.io.IOException;
21 | import java.nio.file.Path;
22 | import java.nio.file.WatchKey;
23 | import java.nio.file.WatchService;
24 | import java.util.Map;
25 | import java.util.concurrent.ConcurrentHashMap;
26 |
27 | import org.slf4j.Logger;
28 | import org.slf4j.LoggerFactory;
29 |
30 | import com.yahoo.sshd.authentication.file.FileTreeWalkerInterface;
31 |
32 | public class ArtifactoryAuthFileWalker implements FileTreeWalkerInterface {
33 | private static final Logger LOGGER = LoggerFactory.getLogger(ArtifactoryAuthFileWalker.class);
34 |
35 | private final WatchService watchService;
36 | private final Map watchKeys;
37 | private final File watchedDirectory;
38 | private final ConcurrentHashMap authorizationHashMap;
39 |
40 | public ArtifactoryAuthFileWalker(final WatchService watchService, final Map watchKeys,
41 | final File watchedDirectory, ConcurrentHashMap authorizationHashMap) {
42 | this.watchService = watchService;
43 | this.watchKeys = watchKeys;
44 | this.watchedDirectory = watchedDirectory;
45 | this.authorizationHashMap = authorizationHashMap;
46 | }
47 |
48 | @Override
49 | public void registerAll(Path dir) throws IOException {
50 | WatchKey key = dir.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
51 | if (LOGGER.isDebugEnabled()) {
52 | Path prev = watchKeys.get(key);
53 | if (prev == null) {
54 | LOGGER.debug("register: {} ", dir);
55 | } else {
56 | if (!dir.equals(prev)) {
57 | LOGGER.debug("update: {} -> {}", prev, dir);
58 | }
59 | }
60 | }
61 |
62 | watchKeys.put(key, dir);
63 | AuthFileParser.parse(watchedDirectory.getAbsolutePath(), authorizationHashMap);
64 | }
65 |
66 | @Override
67 | public void register(Path dir) throws IOException {
68 |
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/authorization/file/AuthUser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authorization.file;
14 |
15 | public class AuthUser {
16 |
17 | private final String userName;
18 | private boolean read = true;
19 | private boolean write = false;
20 | private boolean all = false;
21 |
22 | public AuthUser(final String userName) {
23 | this.userName = userName;
24 | if ("*".equals(userName)) {
25 | this.all = true;
26 | }
27 | }
28 |
29 | public boolean isRead() {
30 | return read;
31 | }
32 |
33 | public void setRead(boolean read) {
34 | this.read = read;
35 | }
36 |
37 | public boolean isWrite() {
38 | return write;
39 | }
40 |
41 | public void setWrite(boolean write) {
42 | this.write = write;
43 | }
44 |
45 | /**
46 | *
47 | * @return true if this is a wildcard user.
48 | */
49 | public boolean isAll() {
50 | return all;
51 | }
52 |
53 | public void setAll(boolean all) {
54 | this.all = all;
55 | }
56 |
57 | public String getUserName() {
58 | return userName;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/authorization/file/DefaultArtifactoryAuthorizerProviderFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authorization.file;
14 |
15 | import org.slf4j.Logger;
16 | import org.slf4j.LoggerFactory;
17 |
18 | import com.yahoo.sshd.authorization.ArtifactoryAuthorizer;
19 | import com.yahoo.sshd.authorization.ArtifactoryAuthorizerProviderFactory;
20 | import com.yahoo.sshd.authorization.WideOpenGatesAuthrorizer;
21 | import com.yahoo.sshd.server.settings.SshdSettingsInterface;
22 |
23 | public class DefaultArtifactoryAuthorizerProviderFactory implements ArtifactoryAuthorizerProviderFactory {
24 | private static final Logger LOG = LoggerFactory.getLogger(FileBasedArtifactoryAuthorizer.class);
25 |
26 | @Override
27 | public ArtifactoryAuthorizer artifactoryAuthorizerProvider(SshdSettingsInterface settings) {
28 | if (settings.isDevelopementMode()) {
29 | LOG.warn("Running in developement mode, many checks are disabled");
30 | return new WideOpenGatesAuthrorizer(settings);
31 | }
32 |
33 | return new FileBasedArtifactoryAuthorizer(settings);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/authorization/file/PermTarget.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authorization.file;
14 |
15 | import java.util.concurrent.ConcurrentHashMap;
16 |
17 | import org.slf4j.Logger;
18 | import org.slf4j.LoggerFactory;
19 |
20 | public class PermTarget {
21 |
22 | private static final Logger LOG = LoggerFactory.getLogger(PermTarget.class);
23 |
24 | private final ConcurrentHashMap authUsers = new ConcurrentHashMap();
25 |
26 | public boolean userExists(String userName) {
27 | return authUsers.containsKey(userName);
28 | }
29 |
30 | public boolean canRead(String userName) {
31 | final AuthUser allUser = authUsers.get("*");
32 | if (allUser != null && allUser.isAll() && allUser.isRead()) {
33 | // allowing read for all users
34 | if (LOG.isDebugEnabled()) {
35 | LOG.debug("Allowed to read for all users.");
36 | }
37 | return true;
38 | }
39 | final AuthUser user = authUsers.get(userName);
40 | if (user == null) {
41 | if (LOG.isDebugEnabled()) {
42 | LOG.debug("User name {} not found.", userName);
43 | }
44 | return false;
45 | }
46 | return user.isRead();
47 | }
48 |
49 | public boolean canWrite(String userName) {
50 | final AuthUser allUser = authUsers.get("*");
51 | if (allUser != null && allUser.isAll() && allUser.isWrite()) {
52 | // allowing write for all users
53 | if (LOG.isDebugEnabled()) {
54 | LOG.debug("Allowed to write for all users.");
55 | }
56 | return true;
57 | }
58 | final AuthUser user = authUsers.get(userName);
59 | if (user == null) {
60 | if (LOG.isDebugEnabled()) {
61 | LOG.debug("User name {} not found.", userName);
62 | }
63 | return false;
64 | }
65 | return user.isWrite();
66 | }
67 |
68 | public void addUser(AuthUser authUser) {
69 | authUsers.put(authUser.getUserName(), authUser);
70 | }
71 |
72 | public AuthUser getUser(String userName) {
73 | return authUsers.get(userName);
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/common/forward/DenyingTcpipForwarderFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.common.forward;
14 |
15 | import org.apache.sshd.common.TcpipForwarder;
16 | import org.apache.sshd.common.TcpipForwarderFactory;
17 | import org.apache.sshd.common.session.ConnectionService;
18 |
19 | /**
20 | * A denying {@link TcpipForwarderFactory} implementation.
21 | *
22 | * @see DenyingTcpipForwarder
23 | */
24 | public class DenyingTcpipForwarderFactory implements TcpipForwarderFactory {
25 | @Override
26 | public TcpipForwarder create(ConnectionService service) {
27 | return new DenyingTcpipForwarder(service);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/TestCiphers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server;
14 |
15 | import java.util.Collections;
16 | import java.util.List;
17 |
18 | import org.apache.sshd.common.Cipher;
19 | import org.apache.sshd.common.NamedFactory;
20 |
21 | import com.yahoo.sshd.server.settings.SshdProxySettings;
22 |
23 | public class TestCiphers {
24 | public static void main(String[] args) throws Exception {
25 | List> list = SshdProxySettings.createCipherFactoryList(Collections.emptyList());
26 | System.err.println("length: " + list.size());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/command/DelegatingCommandFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.command;
14 |
15 | import java.util.HashMap;
16 | import java.util.Map;
17 |
18 | import org.apache.sshd.server.CommandFactory;
19 |
20 | import com.yahoo.sshd.server.logging.SshRequestLog;
21 |
22 | public abstract class DelegatingCommandFactory implements CommandFactory {
23 |
24 | protected CommandFactory delegate;
25 | protected SshRequestLog requestLog;
26 | protected Map envToAfPropertyMapping = new HashMap<>();
27 |
28 |
29 | public DelegatingCommandFactory() {
30 | this(null);
31 | }
32 |
33 | public DelegatingCommandFactory(CommandFactory delegate) {
34 | this.delegate = delegate;
35 | }
36 |
37 | public CommandFactory setDelegate(CommandFactory cf) {
38 | this.delegate = cf;
39 | return cf;
40 | }
41 |
42 | public CommandFactory getDelegate() {
43 | return delegate;
44 | }
45 |
46 | public SshRequestLog getRequestLog() {
47 | return requestLog;
48 | }
49 |
50 | public void setRequestLog(SshRequestLog requestLog) {
51 | this.requestLog = requestLog;
52 | }
53 |
54 | public Map getEnvToAfPropertyMapping() {
55 | return envToAfPropertyMapping;
56 | }
57 |
58 | public void setEnvToAfPropertyMapping(Map envToAfPropertyMapping) {
59 | this.envToAfPropertyMapping = new HashMap<>(envToAfPropertyMapping);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/command/NewScpCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
3 | * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
4 | * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | /* Some portions of this code are Copyright (c) 2014, Yahoo! Inc. All rights reserved. */
14 | package com.yahoo.sshd.server.command;
15 |
16 | import java.io.IOException;
17 | import java.util.Map;
18 |
19 | import org.apache.sshd.server.Environment;
20 | import org.slf4j.Logger;
21 | import org.slf4j.LoggerFactory;
22 |
23 | import com.yahoo.sshd.server.logging.SshRequestLog;
24 |
25 | /**
26 | * This commands provide SCP support on both server and client side. Permissions and preservation of access /
27 | * modification times on files are not supported.
28 | *
29 | * @author Apache MINA SSHD Project
30 | */
31 | /**
32 | * This was adapted from ScpCommand. It is an implementation of AbstractScpCommand, which contains the parts that were
33 | * removed from ScpCommand when making AbstractScpCommand
34 | *
35 | * @author areese
36 | *
37 | */
38 | public class NewScpCommand extends AbstractScpCommand {
39 | protected static final Logger LOGGER = LoggerFactory.getLogger(NewScpCommand.class);
40 | private final SshRequestLog requestLog;
41 |
42 | public NewScpCommand(String args, SshRequestLog requestLog, Map envToAfPropertyMapping) {
43 | super(args, envToAfPropertyMapping);
44 | this.requestLog = requestLog;
45 | }
46 |
47 | @Override
48 | protected SshRequestLog getSshRequestLog() {
49 | return requestLog;
50 | }
51 |
52 | @Override
53 | public void start(Environment env) throws IOException {
54 | super.start(env);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/command/NullScpCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.command;
14 |
15 | import java.util.HashMap;
16 |
17 | import org.slf4j.Logger;
18 | import org.slf4j.LoggerFactory;
19 |
20 | import com.yahoo.sshd.server.logging.SshRequestLog;
21 |
22 | /**
23 | * This class exists as a dummy test so we can test the speed of doing nothing.
24 | *
25 | * @author areese
26 | *
27 | */
28 | public class NullScpCommand extends AbstractScpCommand {
29 | protected static final Logger LOGGER = LoggerFactory.getLogger(NullScpCommand.class);
30 |
31 | public NullScpCommand(String args) {
32 | super(args, new HashMap());
33 | }
34 |
35 | @Override
36 | protected SshRequestLog getSshRequestLog() {
37 | return null;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/command/NullScpCommandFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.command;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | import org.apache.sshd.server.Command;
19 | import org.apache.sshd.server.CommandFactory;
20 |
21 | @Deprecated
22 | public class NullScpCommandFactory extends DelegatingCommandFactory {
23 |
24 | public NullScpCommandFactory() {
25 |
26 | }
27 |
28 | public NullScpCommandFactory(CommandFactory delegate) {
29 | super(delegate);
30 | }
31 |
32 | /**
33 | * Parses a command string and verifies that the basic syntax is correct. If parsing fails the responsibility is
34 | * delegated to the configured {@link CommandFactory} instance; if one exist.
35 | *
36 | * @param command command to parse
37 | * @return configured {@link Command} instance
38 | * @throws IllegalArgumentException
39 | */
40 | @Override
41 | public Command createCommand(String command) {
42 | try {
43 | return new NullScpCommand(command);
44 | } catch (IllegalArgumentException iae) {
45 | if (delegate != null) {
46 | return delegate.createCommand(command);
47 | }
48 | throw iae;
49 | }
50 | }
51 |
52 | public static String[] splitCommandString(String mustBe, String command) {
53 | if (!command.trim().startsWith(mustBe)) {
54 | throw new IllegalArgumentException("Unknown command, does not begin with '" + mustBe + "'");
55 | }
56 |
57 | String[] args = command.split(" ");
58 | List parts = new ArrayList();
59 | parts.add(args[0]);
60 | for (int i = 1; i < args.length; i++) {
61 | if (!args[i].trim().startsWith("-")) {
62 | parts.add(concatenateWithSpace(args, i));
63 | break;
64 | } else {
65 | parts.add(args[i]);
66 | }
67 | }
68 | return parts.toArray(new String[parts.size()]);
69 | }
70 |
71 | public static String concatenateWithSpace(String[] args, int from) {
72 | StringBuilder sb = new StringBuilder();
73 |
74 | for (int i = from; i < args.length; i++) {
75 | sb.append(args[i] + " ");
76 | }
77 | return sb.toString().trim();
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/command/ScpCommandSessionListener.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.sshd.server.command;
2 |
3 | import org.apache.sshd.common.Session;
4 | import org.apache.sshd.common.SessionListener;
5 | import org.apache.sshd.server.session.ServerSession;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | /**
10 | * This class is used to monitor the session close event for a ScpCommand Object so that it can clean up the ScpCommand
11 | * when the session is closed.
12 | *
13 | * @author adam701 on 9/29/15.
14 | */
15 | public class ScpCommandSessionListener implements SessionListener {
16 |
17 | private static final Logger LOGGER = LoggerFactory.getLogger(ScpCommandSessionListener.class);
18 | private final Thread threadRunningScpCommand;
19 |
20 | public ScpCommandSessionListener(final Thread threadRunningScpCommand) {
21 | this.threadRunningScpCommand = threadRunningScpCommand;
22 | }
23 |
24 | public void registerSession(ServerSession session) {
25 | session.addListener(this);
26 | }
27 |
28 | @Override
29 | public void sessionCreated(Session session) {
30 | }
31 |
32 | @Override
33 | public void sessionEvent(Session session, Event event) {
34 | }
35 |
36 | @Override
37 | public void sessionClosed(Session session) {
38 | if (LOGGER.isDebugEnabled()) {
39 | LOGGER.debug("Session is closed. Try to interrupt the downloading thread if it is still blocked.");
40 | }
41 |
42 | if (null != this.threadRunningScpCommand) {
43 | this.threadRunningScpCommand.interrupt();
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/filesystem/AFClientCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.filesystem;
14 |
15 | import org.slf4j.Logger;
16 | import org.slf4j.LoggerFactory;
17 |
18 | import com.google.common.cache.CacheBuilder;
19 | import com.google.common.cache.CacheLoader;
20 | import com.google.common.cache.LoadingCache;
21 | import com.yahoo.sshd.tools.artifactory.ArtifactoryClientFactory;
22 | import com.yahoo.sshd.tools.artifactory.ArtifactoryInformation;
23 | import com.yahoo.sshd.tools.artifactory.JFrogArtifactoryClientHelper;
24 |
25 | public class AFClientCache implements ArtifactoryClientFactory {
26 | private static final Logger LOGGER = LoggerFactory.getLogger(AFClientCache.class);
27 | private static final int CLIENT_CACHE_SIZE = 10;
28 | protected LoadingCache cache;
29 | protected ArtifactoryClientFactory clientFactory;
30 | protected ArtifactoryInformation afInfo;
31 |
32 | public AFClientCache(final ArtifactoryInformation inAfInfo, final ArtifactoryClientFactory inClientFactory) {
33 | this.clientFactory = inClientFactory;
34 | this.afInfo = inAfInfo;
35 | LOGGER.info("Setting up cache for Artifactory Client with max size " + CLIENT_CACHE_SIZE);
36 | this.cache =
37 | CacheBuilder.newBuilder().maximumSize(CLIENT_CACHE_SIZE)
38 | .build(new CacheLoader() {
39 | @Override
40 | public JFrogArtifactoryClientHelper load(final String repositoryName) {
41 | // no checked exception
42 | if (LOGGER.isDebugEnabled()) {
43 | LOGGER.debug("Creating new Artifactory Client for repository "
44 | + repositoryName);
45 | }
46 | return clientFactory.createJFrogClientHelper(afInfo, repositoryName);
47 | }
48 | });
49 | }
50 |
51 | @Override
52 | public JFrogArtifactoryClientHelper createJFrogClientHelper(ArtifactoryInformation afInfo, String repositoryName) {
53 | return cache.getUnchecked(repositoryName);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/filesystem/ArtifactoryFileSystemFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.filesystem;
14 |
15 | import org.apache.sshd.common.Session;
16 | import org.apache.sshd.common.file.FileSystemView;
17 | import org.apache.sshd.common.file.nativefs.NativeFileSystemFactory;
18 |
19 | import com.yahoo.sshd.authorization.ArtifactoryAuthorizer;
20 | import com.yahoo.sshd.tools.artifactory.ArtifactoryInformation;
21 |
22 | public class ArtifactoryFileSystemFactory extends NativeFileSystemFactory implements
23 | InjectableArtifactoryFileSystemFactory {
24 | protected ArtifactoryInformation afInfo;
25 | protected ArtifactoryAuthorizer artifactoryAuthorizer;
26 |
27 | public ArtifactoryFileSystemFactory() {
28 |
29 | }
30 |
31 | @Override
32 | public void setAfInfo(final ArtifactoryInformation afInfo) {
33 | this.afInfo = afInfo;
34 | }
35 |
36 | @Override
37 | public void setArtifactoryAuthorizer(ArtifactoryAuthorizer artifactoryAuthorizer) {
38 | this.artifactoryAuthorizer = artifactoryAuthorizer;
39 |
40 | }
41 |
42 | /**
43 | * Create the appropriate user file system view.
44 | */
45 | @Override
46 | public FileSystemView createFileSystemView(final Session session) {
47 | final String userName = session.getUsername();
48 | return new ArtifactoryFileSystemView(afInfo, userName, isCaseInsensitive(), artifactoryAuthorizer);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/filesystem/GuiceFsFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.filesystem;
14 |
15 | import org.apache.sshd.common.file.FileSystemFactory;
16 |
17 | import com.yahoo.sshd.tools.artifactory.ArtifactoryInformation;
18 |
19 | public interface GuiceFsFactory {
20 | FileSystemFactory create(final ArtifactoryInformation afInfo);
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/filesystem/InjectableArtifactoryFileSystemFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.filesystem;
14 |
15 | import org.apache.sshd.common.file.FileSystemFactory;
16 |
17 | import com.yahoo.sshd.authorization.ArtifactoryAuthorizer;
18 | import com.yahoo.sshd.tools.artifactory.ArtifactoryInformation;
19 |
20 | public interface InjectableArtifactoryFileSystemFactory extends FileSystemFactory {
21 |
22 | void setAfInfo(ArtifactoryInformation afInfo);
23 |
24 | void setArtifactoryAuthorizer(ArtifactoryAuthorizer artifactoryAuthorizerProvider);
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/filesystem/NameLengthTuple.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.filesystem;
14 |
15 | /**
16 | * This is a simple class for keeping track of a name, length and perms tuple from an ssh based file.
17 | *
18 | * The ssh protocol sends these all together, and to easily delegate it's nice to hang onto them this way.
19 | *
20 | * @author areese
21 | *
22 | */
23 | public class NameLengthTuple {
24 | private final long length;
25 | private final String name;
26 | private final String perms;
27 |
28 | /**
29 | * @param name
30 | * @param length
31 | */
32 | public NameLengthTuple(String name, long length, String perms) {
33 | this.name = name;
34 | this.length = length;
35 | this.perms = perms;
36 | }
37 |
38 | public String getName() {
39 | return name;
40 | }
41 |
42 | public long getLength() {
43 | return length;
44 | }
45 |
46 | public String getPerms() {
47 | return perms;
48 | }
49 |
50 | @Override
51 | public int hashCode() {
52 | final int prime = 31;
53 | int result = 1;
54 | result = prime * result + (int) (length ^ (length >>> 32));
55 | result = prime * result + ((name == null) ? 0 : name.hashCode());
56 | result = prime * result + ((perms == null) ? 0 : perms.hashCode());
57 | return result;
58 | }
59 |
60 | @Override
61 | public boolean equals(Object obj) {
62 | if (this == obj) {
63 | return true;
64 | }
65 | if (obj == null) {
66 | return false;
67 | }
68 | if (getClass() != obj.getClass()) {
69 | return false;
70 | }
71 | NameLengthTuple other = (NameLengthTuple) obj;
72 | if (length != other.length) {
73 | return false;
74 | }
75 | if (name == null) {
76 | if (other.name != null) {
77 | return false;
78 | }
79 | } else if (!name.equals(other.name)) {
80 | return false;
81 | }
82 | if (perms == null) {
83 | if (other.perms != null) {
84 | return false;
85 | }
86 | } else if (!perms.equals(other.perms)) {
87 | return false;
88 | }
89 | return true;
90 | }
91 |
92 | @Override
93 | public String toString() {
94 | return "NameLengthTuple [length=" + length + ", name=" + name + ", perms=" + perms + "]";
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/filters/DenyingForwardingFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.filters;
14 |
15 |
16 | import org.apache.sshd.common.ForwardingFilter;
17 | import org.apache.sshd.common.Session;
18 | import org.apache.sshd.common.SshdSocketAddress;
19 | import org.apache.sshd.server.session.ServerSession;
20 | import org.slf4j.Logger;
21 | import org.slf4j.LoggerFactory;
22 |
23 | /**
24 | * This class exists to deny all sorts of forwarding.
25 | *
26 | * we don't allow X11, agent, forwarding, or listening.
27 | *
28 | * @author areese
29 | *
30 | */
31 | public class DenyingForwardingFilter implements ForwardingFilter {
32 | private static final Logger LOGGER = LoggerFactory.getLogger(DenyingForwardingFilter.class);
33 |
34 | public boolean canForwardAgent(ServerSession session) {
35 | if (LOGGER.isDebugEnabled()) {
36 | LOGGER.debug("Agent forwarding requested for {}", session);
37 | }
38 |
39 | return false;
40 | }
41 |
42 | @Override
43 | public boolean canForwardX11(Session session) {
44 | if (LOGGER.isDebugEnabled()) {
45 | LOGGER.debug("X11 forwarding requested for {}", session);
46 | }
47 |
48 | return false;
49 | }
50 |
51 | @Override
52 | public boolean canListen(SshdSocketAddress socketAddress, Session session) {
53 | if (LOGGER.isDebugEnabled()) {
54 | LOGGER.debug("Listen forwarding requested from {} for {}", socketAddress, session);
55 | }
56 |
57 | return false;
58 | }
59 |
60 | @Override
61 | public boolean canConnect(SshdSocketAddress socketAddress, Session session) {
62 | if (LOGGER.isDebugEnabled()) {
63 | LOGGER.debug("Connect forwarding requested from {} for {}", socketAddress, session);
64 | }
65 |
66 | return false;
67 | }
68 |
69 | @Override
70 | public boolean canForwardAgent(Session session) {
71 | if (LOGGER.isDebugEnabled()) {
72 | LOGGER.debug("Agent forwarding requested for {}", session);
73 | }
74 |
75 | return false;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/filters/LocalForwardingFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.filters;
14 |
15 |
16 | import org.apache.sshd.common.Session;
17 | import org.apache.sshd.common.SshdSocketAddress;
18 | import org.slf4j.Logger;
19 | import org.slf4j.LoggerFactory;
20 |
21 | /**
22 | * This class exists to deny all sorts of forwarding.
23 | *
24 | * we don't allow X11, agent, forwarding, or listening.
25 | *
26 | * @author areese
27 | *
28 | */
29 | public class LocalForwardingFilter extends DenyingForwardingFilter {
30 | private static final Logger LOGGER = LoggerFactory.getLogger(LocalForwardingFilter.class);
31 | private final String toHost;
32 | private final int toPort;
33 |
34 | public LocalForwardingFilter(String toHost, int toPort) {
35 | this.toHost = toHost.toLowerCase();
36 | this.toPort = toPort;
37 | }
38 |
39 | @Override
40 | public boolean canConnect(SshdSocketAddress socketAddress, Session session) {
41 | if (LOGGER.isDebugEnabled()) {
42 | LOGGER.debug("Connect forwarding requested from {} for {}", socketAddress, session);
43 | }
44 |
45 | // we don't want to allow forwards to just anywhere, we only allow them to the artifactory host.
46 | int sp = socketAddress.getPort();
47 | if (sp != toPort) {
48 | if (LOGGER.isDebugEnabled()) {
49 | LOGGER.debug("Denying forwarding requested from {} for {} tohost {} toPort {}", socketAddress, session,
50 | toHost, Integer.valueOf(toPort));
51 | }
52 |
53 | return false;
54 | }
55 |
56 | String spHost = socketAddress.getHostName().toLowerCase();
57 | if (!toHost.equals(spHost)) {
58 | if (LOGGER.isDebugEnabled()) {
59 | LOGGER.debug("Denying forwarding requested from {} for {} tohost {} toPort {}", socketAddress, session,
60 | toHost, Integer.valueOf(toPort));
61 | }
62 |
63 | return false;
64 | }
65 |
66 | return true;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/jetty/JettyRunnableComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.jetty;
14 |
15 | import java.io.IOException;
16 |
17 | import org.eclipse.jetty.server.Server;
18 |
19 | import com.yahoo.sshd.utils.RunnableComponent;
20 |
21 | /**
22 | * A wrapper to allow jetty to be started and stopped.
23 | *
24 | * @author areese
25 | *
26 | */
27 | public class JettyRunnableComponent implements RunnableComponent {
28 |
29 | private int jettyPort;
30 | private String jettyWebAppDir;
31 | private Server server;
32 | private JettyServiceSetting jettyServiceSetting;
33 |
34 | public JettyRunnableComponent(final int jettyPort, final String jettyWebAppDir,
35 | final JettyServiceSetting jettyServiceSetting) {
36 | this.jettyPort = jettyPort;
37 | this.jettyServiceSetting = jettyServiceSetting;
38 | this.jettyWebAppDir = (null == jettyWebAppDir) ? null : jettyWebAppDir.trim();
39 | }
40 |
41 | @Override
42 | public void run() {
43 | try {
44 | if (-1 == jettyPort || null == jettyWebAppDir || jettyWebAppDir.isEmpty()) {
45 | return;
46 | }
47 |
48 | server = JettyServer.newServer(jettyPort, jettyWebAppDir, jettyServiceSetting);
49 | server.start();
50 | } catch (Exception e) {
51 | throw new RuntimeException(e);
52 | }
53 | }
54 |
55 | @Override
56 | public String getName() {
57 | return "Jetty Server";
58 | }
59 |
60 | @Override
61 | public void close() throws IOException {
62 | if (null == server) {
63 | return;
64 | }
65 |
66 | try {
67 | server.stop();
68 | } catch (Exception e) {
69 | throw new IOException(e);
70 | } finally {
71 | server = null;
72 | }
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/jetty/JettyServiceSetting.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 |
14 | package com.yahoo.sshd.server.jetty;
15 |
16 |
17 | /**
18 | * Used to tell the Jetty server which resources to serve.
19 | *
20 | * @author muellerfabian
21 | *
22 | */
23 | public enum JettyServiceSetting {
24 |
25 | ARTIFACTORY,
26 | VIP,
27 | BOTH;
28 |
29 |
30 | public static JettyServiceSetting valueOfIgnoreCase(String setting) throws IllegalArgumentException{
31 |
32 | if (null != setting) {
33 | setting = setting.toUpperCase();
34 | }
35 |
36 | return JettyServiceSetting.valueOf(setting);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/logging/DefaultRequestLogFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.logging;
14 |
15 | public class DefaultRequestLogFactory implements RequestLogFactory {
16 |
17 | @Override
18 | public SshRequestLog createRequestLog(String requestLogFilePath) {
19 | return new NCSARequestLog(requestLogFilePath);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/logging/RequestLogFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.logging;
14 |
15 | public interface RequestLogFactory {
16 |
17 | SshRequestLog createRequestLog(String requestLogFilePath);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/logging/SshRequestHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.logging;
14 |
15 | public interface SshRequestHandler {
16 |
17 | void handleRequest(SshRequestInfo requestInfo);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/logging/SshRequestLog.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.logging;
14 |
15 | import java.io.Closeable;
16 |
17 |
18 | public interface SshRequestLog extends Closeable {
19 |
20 | public void log(SshRequestInfo request);
21 |
22 | public void setup() throws Exception;
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/logging/SshRequestLogListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.logging;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | import org.apache.sshd.common.Session;
19 | import org.apache.sshd.common.SessionListener;
20 | import org.apache.sshd.server.session.ServerSession;
21 | import org.slf4j.Logger;
22 | import org.slf4j.LoggerFactory;
23 |
24 | public class SshRequestLogListener implements SessionListener, SshRequestHandler {
25 | private static final Logger LOGGER = LoggerFactory.getLogger(SshRequestLogListener.class);
26 | private SshRequestLog requestLog;
27 | private List sshRequestList = new ArrayList();
28 |
29 | public SshRequestLogListener(SshRequestLog log) {
30 | this.requestLog = log;
31 | }
32 |
33 | public void setSshRequestLog(SshRequestLog log) {
34 | this.requestLog = log;
35 | }
36 |
37 | public void registerSession(ServerSession session) {
38 | session.addListener(this);
39 | }
40 |
41 | @Override
42 | public void sessionCreated(Session session) {
43 | // this may not be called if the listener is created after the session
44 | // has been created
45 | if (LOGGER.isDebugEnabled()) {
46 | LOGGER.debug("session " + session.toString() + "gets started.");
47 | }
48 | }
49 |
50 | @Override
51 | public void sessionClosed(Session session) {
52 | for (SshRequestInfo request : sshRequestList) {
53 | if (LOGGER.isDebugEnabled()) {
54 | LOGGER.debug("logging the ssh request info " + request.toString());
55 | }
56 | requestLog.log(request);
57 | }
58 | if (LOGGER.isDebugEnabled()) {
59 | LOGGER.debug("session" + session.toString() + " closed.");
60 | }
61 | }
62 |
63 | @Override
64 | public void handleRequest(final SshRequestInfo requestInfo) {
65 | if (null == requestInfo) {
66 | LOGGER.warn("requestInfo is null somehow, no logging");
67 | return;
68 | }
69 | sshRequestList.add(requestInfo);
70 | }
71 |
72 | @Override
73 | public void sessionEvent(Session session, Event event) {
74 | if (LOGGER.isDebugEnabled()) {
75 | LOGGER.debug("session " + session.toString() + " Event: " + event.toString());
76 | }
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/logging/SshRequestStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 |
14 | package com.yahoo.sshd.server.logging;
15 |
16 | public enum SshRequestStatus {
17 |
18 | OK(200, "GET"), //
19 | CREATED(201, "PUT"), //
20 | ACCEPTED(202, "Accepted"), //
21 | NO_CONTENT(204, "No Content"), //
22 | MOVED_PERMANENTLY(301, "Moved Permanently"), //
23 | SEE_OTHER(303, "See Other"), //
24 | NOT_MODIFIED(304, "Not Modified"), //
25 | TEMPORARY_REDIRECT(307, "Temporary Redirect"), //
26 | BAD_REQUEST(400, "Bad Request"), //
27 | UNAUTHORIZED(401, "Unauthorized"), //
28 | FORBIDDEN(403, "Forbidden"), //
29 | NOT_FOUND(404, "Not Found"), //
30 | METHOD_NOT_ALLOWED(405, "Method Not Allowed"),
31 | NOT_ACCEPTABLE(406, "Not Acceptable"), //
32 | CONFLICT(409, "Conflict"), //
33 | GONE(410, "Gone"), //
34 | PRECONDITION_FAILED(412, "Precondition Failed"), //
35 | UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"), //
36 | INTERNAL_SERVER_ERROR(500, "Internal Server Error"), //
37 | SERVICE_UNAVAILABLE(503, "Service Unavailable"); //
38 |
39 | private final int code;
40 | private final String reason;
41 |
42 | SshRequestStatus(final int statusCode, final String reasonPhrase) {
43 | this.code = statusCode;
44 | this.reason = reasonPhrase;
45 | }
46 |
47 | public int getStatusCode() {
48 | return code;
49 | }
50 |
51 | public String getReasonPhrase() {
52 | return toString();
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return reason;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/settings/SshdConfigurationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.settings;
14 |
15 | public class SshdConfigurationException extends Exception {
16 |
17 | private static final long serialVersionUID = 1L;
18 |
19 | public SshdConfigurationException(Exception e) {
20 | super(e);
21 | }
22 |
23 | public SshdConfigurationException(String message) {
24 | super(message);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/settings/SshdProxySettingsFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.settings;
14 |
15 | import javax.annotation.Nonnull;
16 |
17 | public class SshdProxySettingsFactory implements SshdSettingsFactory {
18 |
19 | @Override
20 | public SshdSettingsInterface createSshdSettings(@Nonnull String[] args) throws SshdConfigurationException {
21 | return new SshdSettingsBuilder(args).build();
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/settings/SshdSettingsFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.settings;
14 |
15 | public interface SshdSettingsFactory {
16 | SshdSettingsInterface createSshdSettings(String[] args) throws SshdConfigurationException;
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/settings/SshdSettingsModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.settings;
14 |
15 | import org.apache.sshd.server.keyprovider.PEMHostKeyProviderFactory;
16 | import org.apache.sshd.server.keyprovider.SshdPEMHostKeyProviderFactory;
17 |
18 | import com.google.inject.AbstractModule;
19 | import com.yahoo.sshd.authorization.ArtifactoryAuthorizerProviderFactory;
20 | import com.yahoo.sshd.authorization.file.DefaultArtifactoryAuthorizerProviderFactory;
21 | import com.yahoo.sshd.server.filesystem.ArtifactoryFileSystemFactory;
22 | import com.yahoo.sshd.server.filesystem.InjectableArtifactoryFileSystemFactory;
23 | import com.yahoo.sshd.server.logging.DefaultRequestLogFactory;
24 | import com.yahoo.sshd.server.logging.RequestLogFactory;
25 |
26 | public class SshdSettingsModule extends AbstractModule {
27 |
28 | @Override
29 | protected void configure() {
30 | bind(SshdSettingsFactory.class).to(SshdProxySettingsFactory.class);
31 | bind(InjectableArtifactoryFileSystemFactory.class).to(ArtifactoryFileSystemFactory.class);
32 | bind(PEMHostKeyProviderFactory.class).to(SshdPEMHostKeyProviderFactory.class);
33 | bind(ArtifactoryAuthorizerProviderFactory.class).to(DefaultArtifactoryAuthorizerProviderFactory.class);
34 | bind(RequestLogFactory.class).to(DefaultRequestLogFactory.class);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/shell/ForwardingShellFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
3 | * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
4 | * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | /* Some portions of this code are Copyright (c) 2014, Yahoo! Inc. All rights reserved. */
14 | package com.yahoo.sshd.server.shell;
15 |
16 | import java.util.EnumSet;
17 |
18 | import org.apache.sshd.common.Factory;
19 | import org.apache.sshd.server.Command;
20 | import org.apache.sshd.server.shell.ProcessShellFactory.TtyOptions;
21 | import org.slf4j.Logger;
22 | import org.slf4j.LoggerFactory;
23 |
24 | /**
25 | * Derived from {@link org.apache.sshd.server.shell.ProcessShellFactory}.
26 | *
27 | * A {@link org.apache.sshd.common.Factory} of {@link org.apache.sshd.server.Command} that will simply echo
28 | * text back. The idea is to keep the shell open to allow port forwarding in the background
29 | *
30 | * @author areese
31 | *
32 | */
33 | public class ForwardingShellFactory implements Factory {
34 | @SuppressWarnings("unused")
35 | private static final Logger LOGGER = LoggerFactory.getLogger(ForwardingShellFactory.class);
36 |
37 | private String[] command;
38 | private EnumSet ttyOptions;
39 |
40 | public ForwardingShellFactory(EnumSet ttyOptions) {
41 | this(new String[] {}, ttyOptions);
42 | }
43 |
44 | public ForwardingShellFactory(String[] command, EnumSet ttyOptions) {
45 | this.command = command;
46 | this.ttyOptions = ttyOptions;
47 | }
48 |
49 | public String[] getCommand() {
50 | return command;
51 | }
52 |
53 | public void setCommand(String[] command) {
54 | this.command = command;
55 | }
56 |
57 | @Override
58 | public Command create() {
59 | return new ForwardingShellWrapper(ttyOptions);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/shell/GroovyShellFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
3 | * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
4 | * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | /* Some portions of this code are Copyright (c) 2014, Yahoo! Inc. All rights reserved. */
14 | package com.yahoo.sshd.server.shell;
15 |
16 | import java.util.EnumSet;
17 |
18 | import org.apache.sshd.common.Factory;
19 | import org.apache.sshd.server.Command;
20 | import org.apache.sshd.server.shell.ProcessShellFactory.TtyOptions;
21 | import org.slf4j.Logger;
22 | import org.slf4j.LoggerFactory;
23 |
24 |
25 | /**
26 | * Derived from {@link org.apache.sshd.server.shell.ProcessShellFactory}.
27 | *
28 | * A {@link org.apache.sshd.common.Factory} of {@link org.apache.sshd.server.Command} that will spawn a groovy
29 | * shell There is a major setback, that only out is bound, when to truly be useful, I need to dig into artifactory and
30 | * bind useful bits from there.
31 | *
32 | *
33 | * @author areese
34 | *
35 | */
36 | public class GroovyShellFactory implements Factory {
37 | @SuppressWarnings("unused")
38 | private static final Logger LOGGER = LoggerFactory.getLogger(GroovyShellFactory.class);
39 |
40 | private String[] command;
41 | private EnumSet ttyOptions;
42 |
43 | public GroovyShellFactory(EnumSet ttyOptions) {
44 | this.command = new String[] {};
45 | this.ttyOptions = ttyOptions;
46 | }
47 |
48 | public String[] getCommand() {
49 | return command;
50 | }
51 |
52 | public void setCommand(String[] command) {
53 | this.command = command;
54 | }
55 |
56 | @Override
57 | public Command create() {
58 | return new GroovyShellWrapper(ttyOptions);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/shell/SshProxyMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.shell;
14 |
15 | public class SshProxyMessage {
16 | public static final String MESSAGE_STRING = "" //
17 | + "*---------------------------------------------------*\n"
18 | + "| _ _ _ _| _-|-. _ _ |\n"
19 | + "| this is a |_)| (_)(_||_|(_ | |(_)| | server |\n"
20 | + "| | |\n"
21 | + "*---------------------------------------------------*\n" //
22 | + "";
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/shell/groovy/GroovyPrompt.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.sshd.server.shell.groovy;
2 |
3 | import groovy.lang.Closure;
4 |
5 | public class GroovyPrompt extends Closure {
6 | private static final long serialVersionUID = 1L;
7 |
8 | public GroovyPrompt(Object owner) {
9 | super(owner);
10 | }
11 |
12 | public String doCall() {
13 | return "groovy => ";
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/server/shell/groovy/OutputStreamErrorHandler.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.sshd.server.shell.groovy;
2 |
3 | import java.io.OutputStream;
4 | import java.io.PrintStream;
5 |
6 | import groovy.lang.Closure;
7 |
8 | public class OutputStreamErrorHandler extends Closure {
9 | private static final long serialVersionUID = 1L;
10 |
11 | private final OutputStream err;
12 |
13 | public OutputStreamErrorHandler(Object owner, OutputStream err) {
14 | super(owner);
15 | this.err = err;
16 | }
17 |
18 | public Void doCall(Object o) {
19 | if (!(o instanceof Throwable) || null == err) {
20 | return null;
21 | }
22 |
23 | try (PrintStream ps = new PrintStream(err)) {
24 | ((Throwable) o).printStackTrace(ps);
25 | }
26 |
27 | return null;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/tools/artifactory/ArtifactMetaDataParseFailureException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | public class ArtifactMetaDataParseFailureException extends Exception {
16 |
17 | private static final long serialVersionUID = 1L;
18 |
19 | public ArtifactMetaDataParseFailureException(String message, Exception e) {
20 | super(message, e);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/tools/artifactory/ArtifactNotFoundException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | public class ArtifactNotFoundException extends Exception {
16 | private static final long serialVersionUID = 1L;
17 |
18 | public ArtifactNotFoundException(Exception ex) {
19 | super(ex);
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/tools/artifactory/ArtifactoryBadRequestException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | import com.yahoo.sshd.server.logging.SshRequestStatus;
16 |
17 | import org.apache.sshd.common.file.SshFile;
18 |
19 | public class ArtifactoryBadRequestException extends ArtifactoryIOException {
20 |
21 | private static final long serialVersionUID = 1L;
22 |
23 | public ArtifactoryBadRequestException(String message) {
24 | super(message, null);
25 | }
26 |
27 | public ArtifactoryBadRequestException(String message, SshFile file) {
28 | super(message, file);
29 | }
30 |
31 | @Override
32 | public int getStatusCode() {
33 | return SshRequestStatus.BAD_REQUEST.getStatusCode();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/tools/artifactory/ArtifactoryClientFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | public interface ArtifactoryClientFactory {
16 | JFrogArtifactoryClientHelper createJFrogClientHelper(final ArtifactoryInformation afInfo,
17 | final String repositoryName);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/tools/artifactory/ArtifactoryExceptionInformation.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.sshd.tools.artifactory;
2 |
3 | import org.apache.sshd.common.file.SshFile;
4 |
5 | public interface ArtifactoryExceptionInformation {
6 | /**
7 | *
8 | * @return the sshFile associated with this exception.
9 | */
10 | SshFile getFile();
11 |
12 | /**
13 | * =
14 | * @return the http style status code associated with this exception.
15 | */
16 | int getStatusCode();
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/tools/artifactory/ArtifactoryFileNotFoundException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | import java.io.FileNotFoundException;
16 |
17 | import org.apache.sshd.common.file.SshFile;
18 |
19 | import com.yahoo.sshd.server.logging.SshRequestStatus;
20 |
21 | public class ArtifactoryFileNotFoundException extends FileNotFoundException implements ArtifactoryExceptionInformation {
22 |
23 | private static final long serialVersionUID = 1L;
24 | private SshFile file;
25 |
26 | public ArtifactoryFileNotFoundException(String filePath, Throwable cause) {
27 | super(filePath);
28 | this.initCause(cause);
29 | }
30 |
31 | public ArtifactoryFileNotFoundException(String filePath) {
32 | super(filePath);
33 | }
34 |
35 | public ArtifactoryFileNotFoundException(String filePath, SshFile file) {
36 | super(filePath);
37 | this.file = file;
38 | }
39 |
40 | @Override
41 | public SshFile getFile() {
42 | return file;
43 | }
44 |
45 | @Override
46 | public int getStatusCode() {
47 | return SshRequestStatus.NOT_FOUND.getStatusCode();
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/tools/artifactory/ArtifactoryIOException.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.sshd.tools.artifactory;
2 |
3 | import java.io.IOException;
4 |
5 | import org.apache.sshd.common.file.SshFile;
6 |
7 | public abstract class ArtifactoryIOException extends IOException implements ArtifactoryExceptionInformation {
8 |
9 | private static final long serialVersionUID = 1L;
10 |
11 | private final SshFile file;
12 |
13 | public ArtifactoryIOException(String message, SshFile file) {
14 | super(message);
15 | this.file = file;
16 | }
17 |
18 | @Override
19 | public SshFile getFile() {
20 | return file;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/tools/artifactory/ArtifactoryNoReadPermissionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | import org.apache.sshd.common.file.SshFile;
16 |
17 | import com.yahoo.sshd.server.logging.SshRequestStatus;
18 |
19 |
20 | public class ArtifactoryNoReadPermissionException extends ArtifactoryIOException {
21 |
22 | private static final long serialVersionUID = 1L;
23 |
24 | public ArtifactoryNoReadPermissionException(String message) {
25 | super(message, null);
26 | }
27 |
28 | public ArtifactoryNoReadPermissionException(String message, SshFile file) {
29 | super(message, file);
30 | }
31 |
32 | @Override
33 | public int getStatusCode() {
34 | return SshRequestStatus.FORBIDDEN.getStatusCode();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/tools/artifactory/ArtifactoryNoWritePermissionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | import org.apache.sshd.common.file.SshFile;
16 |
17 | import com.yahoo.sshd.server.logging.SshRequestStatus;
18 |
19 | public class ArtifactoryNoWritePermissionException extends ArtifactoryIOException {
20 | private static final long serialVersionUID = 1L;
21 |
22 | public ArtifactoryNoWritePermissionException(String message) {
23 | super(message, null);
24 | }
25 |
26 | public ArtifactoryNoWritePermissionException(String message, SshFile file) {
27 | super(message, file);
28 | }
29 |
30 | @Override
31 | public int getStatusCode() {
32 | return SshRequestStatus.FORBIDDEN.getStatusCode();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/tools/artifactory/Checksum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | import java.util.LinkedHashMap;
16 | import java.util.LinkedList;
17 | import java.util.List;
18 | import java.util.Map.Entry;
19 |
20 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21 |
22 | @JsonDeserialize(builder = Checksum.class)
23 | public class Checksum {
24 | private final String type;
25 | private final String value;
26 |
27 | /**
28 | * @param type
29 | * @param value
30 | */
31 | Checksum(String type, String value) {
32 | this.type = type;
33 | this.value = value;
34 | }
35 |
36 | public String getType() {
37 | return type;
38 | }
39 |
40 | public String getValue() {
41 | return value;
42 | }
43 |
44 | @Override
45 | public int hashCode() {
46 | final int prime = 31;
47 | int result = 1;
48 | result = prime * result + ((type == null) ? 0 : type.hashCode());
49 | result = prime * result + ((value == null) ? 0 : value.hashCode());
50 | return result;
51 | }
52 |
53 | @Override
54 | public boolean equals(Object obj) {
55 | if (this == obj) {
56 | return true;
57 | }
58 | if (obj == null) {
59 | return false;
60 | }
61 | if (getClass() != obj.getClass()) {
62 | return false;
63 | }
64 | Checksum other = (Checksum) obj;
65 | if (type == null) {
66 | if (other.type != null) {
67 | return false;
68 | }
69 | } else if (!type.equals(other.type)) {
70 | return false;
71 | }
72 | if (value == null) {
73 | if (other.value != null) {
74 | return false;
75 | }
76 | } else if (!value.equals(other.value)) {
77 | return false;
78 | }
79 | return true;
80 | }
81 |
82 | @Override
83 | public String toString() {
84 | return "Checksum [type=" + type + ", value=" + value + "]";
85 | }
86 |
87 | public static Checksum[] build(LinkedHashMap checksums) {
88 | if (null == checksums) {
89 | return null;
90 | }
91 |
92 | List list = new LinkedList<>();
93 |
94 | for (Entry e : checksums.entrySet()) {
95 | list.add(new Checksum(e.getKey(), e.getValue()));
96 | }
97 |
98 | return list.toArray(new Checksum[] {});
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/tools/artifactory/JFrogArtifactoryClientHelperFactoryImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | public class JFrogArtifactoryClientHelperFactoryImpl implements ArtifactoryClientFactory {
16 |
17 | @Override
18 | public JFrogArtifactoryClientHelper createJFrogClientHelper(final ArtifactoryInformation afInfo,
19 | final String repositoryName) {
20 | return new JFrogArtifactoryClientHelper(afInfo, repositoryName);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/utils/AuthUserData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.utils;
14 |
15 | /**
16 | * this interface defines a datatype which leaves how to get password in a secure way to the concrete classes
17 | *
18 | * @author yili
19 | *
20 | */
21 |
22 | public interface AuthUserData {
23 | public String getUserName();
24 |
25 | public char[] getPassword();
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/utils/DirectoryWatchServiceEventHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5 | * following conditions are met:
6 | *
7 | * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8 | * disclaimer.
9 | *
10 | * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
11 | * disclaimer in the documentation and/or other materials provided with the distribution.
12 | *
13 | * - Neither the name of Oracle nor the names of its contributors may be used to endorse or promote products derived
14 | * from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 | */
24 |
25 | /* Some portions of this code are Copyright (c) 2014, Yahoo! Inc. All rights reserved. */
26 |
27 | /*
28 | * Adapted from:
29 | * http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/essential
30 | * /io/examples/WatchDir.java
31 | */
32 | package com.yahoo.sshd.utils;
33 |
34 | import java.nio.file.Path;
35 |
36 | public interface DirectoryWatchServiceEventHandler {
37 |
38 | public void onProcessEvents(Path changed);
39 |
40 | public void onProcessCreateEvents(Path changed);
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/utils/RunnableComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.utils;
14 |
15 | import java.io.Closeable;
16 | import java.io.IOException;
17 |
18 | /**
19 | * An interface for something that can run, has a name and can be stopped.
20 | *
21 | * @author areese
22 | *
23 | */
24 | public interface RunnableComponent extends Runnable, Closeable {
25 | @Override
26 | public void run();
27 |
28 | public String getName();
29 |
30 | @Override
31 | public void close() throws IOException;
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/utils/ThreadSafeSimpleDateFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.utils;
14 |
15 | import java.text.ParseException;
16 | import java.text.SimpleDateFormat;
17 | import java.util.Date;
18 |
19 | public class ThreadSafeSimpleDateFormat {
20 | private final String format;
21 | private final ThreadLocal tls = new ThreadLocal() {
22 | @Override
23 | protected SimpleDateFormat initialValue() {
24 | return new SimpleDateFormat(format);
25 | }
26 | };
27 |
28 | public ThreadSafeSimpleDateFormat(final String format) {
29 | this.format = format;
30 | }
31 |
32 | public Date format(String date) throws ParseException {
33 | return tls.get().parse(date);
34 | }
35 |
36 | public long formatLong(String date) throws ParseException {
37 | return tls.get().parse(date).getTime();
38 | }
39 |
40 | public long formatLongNoException(String date) {
41 | if (null == date) {
42 | return 0L;
43 | }
44 |
45 | date = date.trim();
46 |
47 | if (date.isEmpty()) {
48 | return 0L;
49 | }
50 |
51 | try {
52 | return tls.get().parse(date).getTime();
53 | } catch (ParseException e) {
54 | return 0;
55 | }
56 | }
57 |
58 | public String formatLongToString(long startTimestamp) {
59 | return tls.get().format(new Date(startTimestamp));
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/utils/streams/AsyncHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.utils.streams;
14 |
15 | public interface AsyncHandler {
16 |
17 | public void onCompleted() throws Exception;
18 |
19 | public void onThrowable(Throwable t);
20 |
21 | public Throwable getThrowable();
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/utils/streams/AsyncHandlerImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.utils.streams;
14 |
15 | import java.util.concurrent.CountDownLatch;
16 |
17 | public final class AsyncHandlerImpl implements AsyncHandler {
18 | private final CountDownLatch responseArrived;
19 | private Throwable responseThrowable = null;
20 |
21 | public AsyncHandlerImpl(final CountDownLatch responseArrived) {
22 | this.responseArrived = responseArrived;
23 | }
24 |
25 | @Override
26 | public void onCompleted() throws Exception {
27 | responseArrived.countDown();
28 | }
29 |
30 | @Override
31 | public void onThrowable(Throwable t) {
32 | responseThrowable = t;
33 | responseArrived.countDown();
34 | }
35 |
36 | @Override
37 | public Throwable getThrowable() {
38 | return this.responseThrowable;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/utils/streams/AsyncPipedOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.utils.streams;
14 |
15 | import java.io.IOException;
16 | import java.io.PipedInputStream;
17 | import java.io.PipedOutputStream;
18 | import java.util.concurrent.CountDownLatch;
19 |
20 | /**
21 | *
22 | * @author charlesk
23 | *
24 | */
25 | public class AsyncPipedOutputStream extends PipedOutputStream {
26 | private final CountDownLatch responseArrived = new CountDownLatch(1);
27 | private final AsyncHandlerImpl asyncHandlerImpl = new AsyncHandlerImpl(responseArrived);
28 |
29 | public AsyncPipedOutputStream(PipedInputStream pipedInputStream) throws IOException {
30 | super(pipedInputStream);
31 | }
32 |
33 | /**
34 | * close method will wait until count down latch reaches 0
35 | */
36 | @Override
37 | public void close() throws IOException {
38 | try {
39 | // call close here first so that input stream can be read.
40 | super.close();
41 | // block here until countdownlatch gets to 0 through AsyncHandlerImpl.
42 | responseArrived.await();
43 | } catch (InterruptedException e) {
44 | throw new IOException("InterruptedException while waiting for the response to arrive.");
45 | }
46 | Throwable responseThrowable = asyncHandlerImpl.getThrowable();
47 | if (responseThrowable != null) {
48 | // we got exception throw it.
49 | throw new IOException(responseThrowable);
50 | }
51 | }
52 |
53 | /**
54 | *
55 | * @return AsyncHandler implementation which has been initialized with CountDownLatch.
56 | */
57 | public AsyncHandler getAsyncHandler() {
58 | return this.asyncHandlerImpl;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/utils/streams/EmptyInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.utils.streams;
14 |
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 |
18 | public class EmptyInputStream extends InputStream {
19 |
20 | @Override
21 | public int read(byte[] b) throws IOException {
22 | return -1;
23 | }
24 |
25 | @Override
26 | public int read(byte[] b, int off, int len) throws IOException {
27 | return -1;
28 | }
29 |
30 | @Override
31 | public long skip(long n) throws IOException {
32 | return 0;
33 | }
34 |
35 | @Override
36 | public int available() throws IOException {
37 | return 0;
38 | }
39 |
40 | @Override
41 | public void close() throws IOException {
42 |
43 | }
44 |
45 | @Override
46 | public synchronized void mark(int readlimit) {
47 |
48 | }
49 |
50 | @Override
51 | public synchronized void reset() throws IOException {
52 |
53 | }
54 |
55 | @Override
56 | public boolean markSupported() {
57 | return false;
58 | }
59 |
60 | @Override
61 | public int read() throws IOException {
62 | return -1;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/utils/streams/EmptyOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.utils.streams;
14 |
15 | import java.io.IOException;
16 | import java.io.OutputStream;
17 |
18 | /**
19 | * A stream that is always empty.
20 | *
21 | * @author areese
22 | *
23 | */
24 | public class EmptyOutputStream extends OutputStream {
25 |
26 | @Override
27 | public void write(byte[] b) throws IOException {
28 |
29 | }
30 |
31 | @Override
32 | public void write(byte[] b, int off, int len) throws IOException {
33 |
34 | }
35 |
36 | @Override
37 | public void flush() throws IOException {
38 |
39 | }
40 |
41 | @Override
42 | public void close() throws IOException {
43 |
44 | }
45 |
46 | @Override
47 | public void write(int b) throws IOException {
48 |
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/utils/streams/InputStreamWithLength.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.utils.streams;
14 |
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 |
18 | public class InputStreamWithLength extends InputStream implements InputStreamWithLengthInterface {
19 |
20 | private final InputStream is;
21 | private final int length;
22 |
23 | public InputStreamWithLength(final InputStream is, final int length) {
24 | this.is = is;
25 | this.length = length;
26 | }
27 |
28 | @Override
29 | public int read(byte[] b) throws IOException {
30 | return is.read(b);
31 | }
32 |
33 | @Override
34 | public int read(byte[] b, int off, int len) throws IOException {
35 | return is.read(b, off, len);
36 | }
37 |
38 | @Override
39 | public long skip(long n) throws IOException {
40 | return is.skip(n);
41 | }
42 |
43 | @Override
44 | public int available() throws IOException {
45 | return is.available();
46 | }
47 |
48 | @Override
49 | public void close() throws IOException {
50 | is.close();
51 | }
52 |
53 | @Override
54 | public synchronized void mark(int readlimit) {
55 | is.mark(readlimit);
56 | }
57 |
58 | @Override
59 | public synchronized void reset() throws IOException {
60 | is.reset();
61 | }
62 |
63 | @Override
64 | public boolean markSupported() {
65 | return is.markSupported();
66 | }
67 |
68 | @Override
69 | public int read() throws IOException {
70 | return is.read();
71 | }
72 |
73 | @Override
74 | public int getLength() {
75 | return length;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/yahoo/sshd/utils/streams/InputStreamWithLengthInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.utils.streams;
14 |
15 | import java.io.Closeable;
16 | import java.io.IOException;
17 |
18 | public interface InputStreamWithLengthInterface extends Closeable {
19 | public int read() throws IOException;
20 |
21 | public int read(byte[] b) throws IOException;
22 |
23 | public int read(byte[] b, int off, int len) throws IOException;
24 |
25 | public long skip(long n) throws IOException;
26 |
27 | public int available() throws IOException;
28 |
29 | @Override
30 | public void close() throws IOException;
31 |
32 | public void mark(int readlimit);
33 |
34 | public void reset() throws IOException;
35 |
36 | public boolean markSupported();
37 |
38 | public int getLength();
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/sshd/server/keyprovider/PEMHostKeyProviderFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
3 | * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
4 | * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | /* Some portions of this code are Copyright (c) 2014, Yahoo! Inc. All rights reserved. */
14 | package org.apache.sshd.server.keyprovider;
15 |
16 | import org.apache.sshd.common.KeyPairProvider;
17 |
18 | public interface PEMHostKeyProviderFactory {
19 |
20 | KeyPairProvider createPEMHostKeyProvider(String path);
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/sshd/server/keyprovider/SshdPEMHostKeyProviderFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
3 | * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
4 | * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | /* Some portions of this code are Copyright (c) 2014, Yahoo! Inc. All rights reserved. */
14 | package org.apache.sshd.server.keyprovider;
15 |
16 | import org.apache.sshd.common.KeyPairProvider;
17 |
18 | public class SshdPEMHostKeyProviderFactory implements PEMHostKeyProviderFactory {
19 |
20 | @Override
21 | public KeyPairProvider createPEMHostKeyProvider(String path) {
22 | return new PEMHostKeyProvider(path);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/resources/asynchttpclient.properties:
--------------------------------------------------------------------------------
1 | setAllowPoolingConnection=true
2 | setCompressionEnabled=true
3 | setConnectionTimeoutInMs=60000
4 | setMaximumConnectionsPerHost=20
5 | setMaximumConnectionsTotal=100
6 | setRequestTimeoutInMs=500000
7 |
--------------------------------------------------------------------------------
/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | %d{HH:mm:ss.SSS} %-5level [thread: %thread] %logger{36}.%M:%L - %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
13 |
14 |
16 |
18 |
19 |
21 |
23 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/main/resources/sshd_proxy.properties:
--------------------------------------------------------------------------------
1 | sshd.port=2222
2 | sshd.artifactoryUrl=http://your_artifactory_host:4080/artifactory
3 | sshd.artifactoryUsername=artifactory_username
4 | sshd.artifactoryPassword=artifactory_password
5 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/authentication/file/TestLocalUserPKAuthenticator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authentication.file;
14 |
15 | import java.io.FileInputStream;
16 | import java.security.PublicKey;
17 | import java.util.Map;
18 | import java.util.concurrent.CountDownLatch;
19 |
20 | import org.apache.karaf.shell.ssh.KarafPublickeyAuthenticator;
21 | import org.apache.karaf.shell.ssh.KarafPublickeyAuthenticator.AuthorizedKey;
22 | import org.apache.sshd.common.io.IoSession;
23 | import org.apache.sshd.server.session.ServerSession;
24 | import org.mockito.Mockito;
25 | import org.testng.annotations.Test;
26 |
27 | public class TestLocalUserPKAuthenticator {
28 | @Test
29 | public void testDefault() throws Exception {
30 | CountDownLatch wakeupLatch = new CountDownLatch(1);
31 | LocalUserPKAuthenticator lpka = new LocalUserPKAuthenticator(wakeupLatch) {
32 |
33 | @Override
34 | String getUserName() {
35 | return "areese";
36 | }
37 |
38 | @Override
39 | String getUserHome() {
40 | return "src/test/resources/MultiUserPKAuthenticator/home/areese/";
41 | }
42 | };
43 |
44 | lpka.start();
45 |
46 | ServerSession session = Mockito.mock(ServerSession.class);
47 | IoSession ioSession = Mockito.mock(IoSession.class);
48 | Mockito.when(session.getIoSession()).thenReturn(ioSession);
49 |
50 | Map publicKeys = null;
51 | try (FileInputStream karafFis = new FileInputStream(lpka.getAuthorizedKeysPath())) {
52 | publicKeys =
53 | KarafPublickeyAuthenticator.parseAuthorizedKeys(lpka.getAuthorizedKeysPath()
54 | .getAbsolutePath(), karafFis);
55 | }
56 |
57 | for (PublicKey publicKey : publicKeys.keySet()) {
58 | lpka.authenticate("areese", publicKey, session);
59 | }
60 |
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/authorization/file/TestArtifactoryAuthorization.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authorization.file;
14 |
15 | import org.mockito.Mockito;
16 | import org.testng.Assert;
17 | import org.testng.annotations.BeforeClass;
18 | import org.testng.annotations.DataProvider;
19 | import org.testng.annotations.Test;
20 |
21 | import com.yahoo.sshd.authorization.ArtifactoryPermTargetType;
22 | import com.yahoo.sshd.server.settings.SshdSettingsInterface;
23 |
24 | @Test(groups = "unit")
25 | public class TestArtifactoryAuthorization {
26 |
27 | private FileBasedArtifactoryAuthorizer artifactoryAuthorization;
28 |
29 | @BeforeClass
30 | public void init() {
31 | SshdSettingsInterface mockedSshdSettings = Mockito.mock(SshdSettingsInterface.class);
32 | Mockito.when(mockedSshdSettings.getArtifactoryAuthorizationFilePath()).thenReturn(
33 | "src/test/resources/auth/auth.txt");
34 | artifactoryAuthorization = new FileBasedArtifactoryAuthorizer(mockedSshdSettings);
35 | }
36 |
37 | @SuppressWarnings("boxing")
38 | @DataProvider(name = "authSample")
39 | public static Object[][] getAuthSample() {
40 | return new Object[][] {
41 | // Success cases
42 | // repo & user found. user has read perm
43 | {"repoX", "a", ArtifactoryPermTargetType.READ, true},
44 | // repo & user found. user has write perm
45 | {"repoX", "a", ArtifactoryPermTargetType.WRITE, true},
46 | // repo found with no user but all READ
47 | {"repoX", "c", ArtifactoryPermTargetType.READ, true},
48 |
49 | // failing cases
50 | // repo not found case
51 | {"repoA", "charlesk", ArtifactoryPermTargetType.WRITE, false},
52 | // repo found but user not found case
53 | {"repoX", "user2", ArtifactoryPermTargetType.WRITE, false},
54 | // repo found but no wrte perm
55 | {"repoX", "c", ArtifactoryPermTargetType.WRITE, false}};
56 | }
57 |
58 | @Test(dataProvider = "authSample")
59 | public void testAuthorization(String repositoryName, String userName, ArtifactoryPermTargetType permissionTarget,
60 | boolean expected) {
61 | boolean actual = artifactoryAuthorization.authorized(repositoryName, userName, permissionTarget);
62 | Assert.assertEquals(expected, actual);
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/authorization/file/TestAuthFileScanner.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.authorization.file;
14 |
15 | import org.testng.annotations.Test;
16 |
17 | public class TestAuthFileScanner {
18 |
19 | @Test
20 | public void testAuthFileScanner() {
21 | // File file = new File("src/test/resources/auth/auth.txt");
22 | // AuthFileScanner authFileScanner = new AuthFileScanner(file.toPath());
23 | // Thread authFileScannerThread = new Thread(authFileScanner);
24 | // authFileScannerThread.start();
25 | }
26 |
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/server/TestHostKey.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server;
14 |
15 | import java.security.KeyPair;
16 |
17 | import org.apache.sshd.server.keyprovider.PEMHostKeyProvider;
18 | import org.testng.Assert;
19 | import org.testng.annotations.Test;
20 |
21 | @Test(groups = "unit")
22 | public class TestHostKey {
23 | @Test
24 | public void testHostKey() {
25 | System.err.println("os.name=" + System.getProperty("os.name"));
26 | PEMHostKeyProvider keyPairProvider = new PEMHostKeyProvider("src/test/resources/hostkey.pem");
27 | Iterable keys = keyPairProvider.loadKeys();
28 | Assert.assertNotNull(keys);
29 | // TODO: fix
30 | // Assert.assertFalse(keys.);
31 | for (KeyPair k : keys) {
32 | Assert.assertNotNull(k);
33 | Assert.assertNotNull(k.getPrivate());
34 | System.err.println("key: " + k.getPrivate());
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/server/command/TestScpCommandSessionListener.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.sshd.server.command;
2 |
3 | import org.testng.Assert;
4 | import org.testng.annotations.Test;
5 |
6 | import java.util.concurrent.Executors;
7 | import java.util.concurrent.TimeUnit;
8 |
9 | /**
10 | * Test the ScpCommandSessionListener
11 | *
12 | * Created by adam701 on 9/30/15.
13 | *
14 | */
15 | public class TestScpCommandSessionListener {
16 |
17 | @Test
18 | public void testSessionCloseInterruptThread() throws InterruptedException {
19 | RunnableWithInterruptedFlag blockedTask = new RunnableWithInterruptedFlag();
20 |
21 | Thread thread = Executors.defaultThreadFactory().newThread(blockedTask);
22 | thread.start();
23 |
24 | ScpCommandSessionListener scpCommandSessionListener = new ScpCommandSessionListener(thread);
25 | scpCommandSessionListener.sessionClosed(null);
26 | thread.join(100000);
27 |
28 | Assert.assertEquals(blockedTask.interrupt, true, "Session close event should interrupt the thread.");
29 | }
30 |
31 | private class RunnableWithInterruptedFlag implements Runnable {
32 |
33 | boolean interrupt = false;
34 |
35 | @Override
36 | public void run() {
37 | try {
38 | TimeUnit.SECONDS.sleep(20);
39 | } catch (InterruptedException e) {
40 | this.interrupt = true;
41 | }
42 | }
43 |
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/server/jetty/TestJettyRunnable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.jetty;
14 |
15 | import org.testng.annotations.DataProvider;
16 | import org.testng.annotations.Test;
17 |
18 | import com.yahoo.sshd.utils.RunnableComponent;
19 |
20 | public class TestJettyRunnable {
21 | @SuppressWarnings("boxing")
22 | @DataProvider
23 | public Object[][] disabled() {
24 | return new Object[][] {//
25 | //
26 | {-1, null},//
27 | {1, null},//
28 | {-1, ""},//
29 | {1, ""},//
30 | };
31 | }
32 |
33 | @Test(dataProvider = "disabled")
34 | public void testDisabled(int port, String webapp) throws Exception {
35 | RunnableComponent rc = new JettyRunnableComponent(port, webapp, JettyServiceSetting.ARTIFACTORY);
36 | rc.run();
37 | rc.close();
38 | }
39 |
40 | // FIXME: figure out how to get a dynamic port, I made this one up.
41 | @Test
42 | public void test() throws Exception {
43 | RunnableComponent rc = new JettyRunnableComponent(60540, "target/webapps", JettyServiceSetting.ARTIFACTORY);
44 | rc.run();
45 | rc.close();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/server/logging/TestSshRequestLogListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.logging;
14 |
15 | import org.apache.sshd.server.session.ServerSession;
16 | import org.mockito.Mockito;
17 | import org.testng.annotations.Test;
18 |
19 | public class TestSshRequestLogListener {
20 |
21 | @SuppressWarnings("resource")
22 | @Test
23 | public void testRequestLogDoLog() {
24 | ServerSession session = Mockito.mock(ServerSession.class);
25 | SshRequestInfo requestInfo = Mockito.mock(SshRequestInfo.class);
26 | SshRequestLog requestLogger = Mockito.mock(SshRequestLog.class);
27 |
28 | SshRequestLogListener logListener = new SshRequestLogListener(requestLogger);
29 | logListener.handleRequest(requestInfo);
30 | logListener.sessionClosed(session);
31 | Mockito.verify(requestLogger).log(requestInfo);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/server/settings/TestChainedFactories.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.settings;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | import org.apache.sshd.server.Command;
19 | import org.testng.Assert;
20 | import org.testng.annotations.Test;
21 |
22 | import com.yahoo.sshd.server.command.DelegatingCommandFactory;
23 |
24 | @Test(groups = "unit")
25 | public class TestChainedFactories {
26 |
27 | static final class NumberedDelegateCommandFactory extends DelegatingCommandFactory {
28 | final int number;
29 |
30 | public NumberedDelegateCommandFactory(int number) {
31 | this(number, null);
32 | }
33 |
34 | public NumberedDelegateCommandFactory(int number, DelegatingCommandFactory delegate) {
35 | super(delegate);
36 | this.number = number;
37 | }
38 |
39 | @Override
40 | public Command createCommand(String command) {
41 | return null;
42 | }
43 |
44 | public int getNumber() {
45 | return number;
46 | }
47 | }
48 |
49 | @Test
50 | public void testDelegatingCf() throws SshdConfigurationException {
51 | List cfList = new ArrayList<>();
52 |
53 | for (int i = 0; i < 10; i++) {
54 | cfList.add(new NumberedDelegateCommandFactory(i));
55 | }
56 |
57 | SshdSettingsInterface sshdSettings =
58 | new SshdSettingsBuilder().setSshdPort(2222).setConfiguration(Utils.getConfigMock())
59 | .setArtifactoryUsername("a").setArtifactoryPassword("password")
60 | .setArtifactoryUrl("http://your:4080/artifactory").setCommandFactories(cfList)
61 | .build();
62 |
63 | DelegatingCommandFactory commandFactory = sshdSettings.getCommandFactory();
64 | Assert.assertNotNull(commandFactory);
65 |
66 | int i = 0;
67 | while (null != commandFactory) {
68 | Assert.assertTrue(commandFactory instanceof NumberedDelegateCommandFactory);
69 | Assert.assertEquals(((NumberedDelegateCommandFactory) commandFactory).getNumber(), i++);
70 | commandFactory = (DelegatingCommandFactory) commandFactory.getDelegate();
71 | }
72 |
73 | Assert.assertEquals(i, 10);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/server/settings/TestCipherFactories.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.settings;
14 |
15 | import java.util.Collections;
16 | import java.util.List;
17 |
18 | import org.apache.sshd.common.Cipher;
19 | import org.apache.sshd.common.NamedFactory;
20 | import org.testng.Assert;
21 | import org.testng.annotations.Test;
22 |
23 | import com.yahoo.sshd.server.command.DelegatingCommandFactory;
24 |
25 | @Test(groups = "unit")
26 | public class TestCipherFactories {
27 | @Test
28 | public void testDefaultFactories() throws SshdConfigurationException {
29 | // IF THIS TEST IS FAILING. Install the unlimited strength jce policy
30 | // files.
31 | // arcfour's aren't working on 7u45
32 |
33 | SshdSettingsInterface settings =
34 | new SshdSettingsBuilder().setSshdPort(2222).setConfiguration(Utils.getConfigMock())
35 | .setArtifactoryUsername("a").setArtifactoryPassword("password")
36 | .setArtifactoryUrl("http://your:4080/artifactory")
37 | .setCommandFactories(Collections.emptyList()).build();
38 |
39 | List> ciphers = settings.getCiphers();
40 |
41 | Assert.assertTrue(ciphers.size() >= 4);
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/server/shell/TestMessageShellFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.server.shell;
14 |
15 | import java.lang.reflect.Field;
16 | import java.util.Collections;
17 | import java.util.EnumSet;
18 | import java.util.Map;
19 |
20 | import org.apache.sshd.common.PtyMode;
21 | import org.apache.sshd.server.Command;
22 | import org.apache.sshd.server.Environment;
23 | import org.apache.sshd.server.Signal;
24 | import org.apache.sshd.server.SignalListener;
25 | import org.apache.sshd.server.shell.InvertedShellWrapper;
26 | import org.testng.Assert;
27 | import org.testng.annotations.Test;
28 |
29 | @Test(groups = "unit")
30 | public class TestMessageShellFactory {
31 | @Test
32 | public void testStringMessage() throws Exception {
33 | MessageShellFactory factory = new MessageShellFactory("dummy");
34 | Command command = factory.create();
35 |
36 | command.start(new Environment() {
37 |
38 | @Override
39 | public void removeSignalListener(SignalListener listener) {}
40 |
41 | @Override
42 | public Map getPtyModes() {
43 | return Collections.emptyMap();
44 | }
45 |
46 | @Override
47 | public Map getEnv() {
48 | return Collections.emptyMap();
49 | }
50 |
51 | @Override
52 | public void addSignalListener(SignalListener listener, EnumSet signals) {}
53 |
54 | @Override
55 | public void addSignalListener(SignalListener listener, Signal... signal) {}
56 |
57 | @Override
58 | public void addSignalListener(SignalListener listener) {}
59 | });
60 |
61 | Assert.assertTrue(command instanceof InvertedShellWrapper);
62 | InvertedShellWrapper shellWrapper = (InvertedShellWrapper) command;
63 |
64 | // gotta get the shell out
65 | Field inField = InvertedShellWrapper.class.getDeclaredField("in");
66 | inField.setAccessible(true);
67 | Object object = inField.get(shellWrapper);
68 |
69 | System.out.println(inField);
70 | System.out.println(object);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/tools/artifactory/TestExceptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | import org.testng.annotations.Test;
16 |
17 | @Test(groups = "unit")
18 | public class TestExceptions {
19 | @SuppressWarnings("unused")
20 | @Test
21 | public void testUpCodeCoverage() {
22 | new ArtifactoryFileNotFoundException("", new Exception());
23 | new ArtifactMetaDataParseFailureException("", new Exception());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/tools/artifactory/TestFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | import org.testng.Assert;
16 | import org.testng.annotations.Test;
17 |
18 | @Test(groups = "unit")
19 | public class TestFormat {
20 | @Test
21 | public void testBadIsZero() {
22 | Assert.assertEquals(ArtifactMetaDataBuilder.getDateFormatter().formatLongNoException(null), 0);
23 | Assert.assertEquals(ArtifactMetaDataBuilder.getDateFormatter().formatLongNoException(""), 0);
24 | Assert.assertEquals(ArtifactMetaDataBuilder.getDateFormatter().formatLongNoException("dasdsa"), 0);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/tools/artifactory/TestRepoStripping.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | import org.testng.Assert;
16 | import org.testng.annotations.DataProvider;
17 | import org.testng.annotations.Test;
18 |
19 | @Test(groups = "unit")
20 | public class TestRepoStripping {
21 | @DataProvider
22 | Object[][] repos() {
23 | return new Object[][] {//
24 | {null, null},//
25 | {"", RepositoryAndPath.EMPTY_REPOSITORY}, //
26 | {"/", RepositoryAndPath.EMPTY_REPOSITORY},//
27 | {"/repo", RepositoryAndPath.EMPTY_REPOSITORY}, //
28 | {
29 | "/ssh-proxy-test/com/yahoo/sshd/0.0.1-SNAPSHOT/",
30 | new RepositoryAndPath("ssh-proxy-test",
31 | "com/yahoo/sshd/0.0.1-SNAPSHOT/")}, //
32 | {
33 | "ssh-proxy-test/com/yahoo/sshd/0.0.1-SNAPSHOT/",
34 | new RepositoryAndPath("ssh-proxy-test",
35 | "com/yahoo/sshd/0.0.1-SNAPSHOT/")}, //
36 | {"samIAm/com/foo.jar", new RepositoryAndPath("samIAm", "com/foo.jar")}, //
37 | };
38 | }
39 |
40 | @Test(dataProvider = "repos")
41 | public void testRepoStripping(String in, RepositoryAndPath expected) {
42 | RepositoryAndPath actual = RepositoryAndPath.splitRepositoryAndPath(in);
43 | Assert.assertEquals(actual, expected);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/tools/artifactory/TestRepositoryAndPath.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.tools.artifactory;
14 |
15 | import org.testng.Assert;
16 | import org.testng.annotations.DataProvider;
17 | import org.testng.annotations.Test;
18 |
19 | @Test(groups = "unit")
20 | public class TestRepositoryAndPath {
21 |
22 | @SuppressWarnings("boxing")
23 | @DataProvider
24 | Object[][] repos() {
25 | return new Object[][] {//
26 | {null, null, null, false},//
27 | {"", "", "", false}, //
28 | {"/", "", "", false},//
29 | {"/repo", "", "", false}, //
30 | {"/ssh-proxy-test/com/yahoo/sshd/0.0.1-SNAPSHOT/", "ssh-proxy-test",
31 | "com/yahoo/sshd/0.0.1-SNAPSHOT/", false}, //
32 | {"ssh-proxy-test/com/yahoo/sshd/0.0.1-SNAPSHOT/", "ssh-proxy-test",
33 | "com/yahoo/sshd/0.0.1-SNAPSHOT/", false}, //
34 | {"samIAm/com/foo.jar", "samIAm", "com/foo.jar", false}, //
35 | {"/dev/null/abc", "/dev/null", "abc", true}, //
36 | };
37 | }
38 |
39 | @Test(dataProvider = "repos")
40 | public void testDevNull(String physicalName, String repository, String path, boolean devnull) {
41 | RepositoryAndPath repositoryAndPath = RepositoryAndPath.splitRepositoryAndPath(physicalName);
42 |
43 | if (null == physicalName) {
44 | Assert.assertNull(repositoryAndPath);
45 | } else {
46 | Assert.assertEquals(repositoryAndPath.getRepository(), repository);
47 | Assert.assertEquals(repositoryAndPath.getPath(), path);
48 | Assert.assertEquals(repositoryAndPath.isDevNull(), devnull);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/com/yahoo/sshd/utils/streams/TestEmptyStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package com.yahoo.sshd.utils.streams;
14 |
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 | import java.io.OutputStream;
18 |
19 | import org.testng.Assert;
20 | import org.testng.annotations.Test;
21 |
22 | @Test(groups = "unit")
23 | public class TestEmptyStream {
24 | @Test
25 | public void testEmptyInputStream() throws IOException {
26 | InputStream eis = new EmptyInputStream();
27 | Assert.assertEquals(eis.read(new byte[] {}), -1);
28 | Assert.assertEquals(eis.read(new byte[] {}, 0, 0), -1);
29 | Assert.assertEquals(eis.skip(0), 0);
30 | Assert.assertEquals(eis.available(), 0);
31 | eis.close();
32 | eis.mark(0);
33 | eis.reset();
34 | Assert.assertEquals(eis.markSupported(), false);
35 | Assert.assertEquals(eis.read(), -1);
36 | }
37 |
38 | @Test
39 | public void testEmptyOutputStream() throws IOException {
40 | // all we can test here is did it throw? this thing does nothing.
41 | OutputStream eis = new EmptyOutputStream();
42 | eis.close();
43 | eis.write(0);
44 | eis.write(new byte[] {});
45 | eis.write(new byte[] {}, 0, 0);
46 | eis.flush();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/sshd/common/kex/TestDH.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo! Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the
5 | * License. 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 distributed under the License is distributed on
10 | * an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 | * specific language governing permissions and limitations under the License.
12 | */
13 | package org.apache.sshd.common.kex;
14 |
15 | import java.math.BigInteger;
16 | import java.security.KeyPair;
17 | import java.security.KeyPairGenerator;
18 |
19 | import javax.crypto.interfaces.DHPublicKey;
20 | import javax.crypto.spec.DHParameterSpec;
21 |
22 | import org.testng.Assert;
23 | import org.testng.annotations.DataProvider;
24 | import org.testng.annotations.Test;
25 |
26 | public class TestDH {
27 | @SuppressWarnings("boxing")
28 | @DataProvider
29 | public Object[][] keyPairGenerator() throws Exception {
30 | KeyPairGenerator kpg = KeyPairGenerator.getInstance("DH");
31 | kpg.initialize(512);
32 | return new Object[][] {{1, kpg}};
33 | }
34 |
35 | @Test(
36 | description = "https://issues.apache.org/jira/browse/SSHD-330; https://bugzilla.wikimedia.org/show_bug.cgi?id=53895#c28",
37 | invocationCount = 500, dataProvider = "keyPairGenerator")
38 | public void testDH(int a, KeyPairGenerator kpg) throws Exception {
39 |
40 | KeyPair kp = kpg.generateKeyPair();
41 |
42 | BigInteger Y = ((DHPublicKey) kp.getPublic()).getY();
43 | DHParameterSpec params = ((DHPublicKey) kp.getPublic()).getParams();
44 | BigInteger P = params.getP();
45 | BigInteger G = params.getG();
46 |
47 | DH dh = new DH();
48 | dh.setF(Y);
49 | dh.setP(P);
50 | dh.setG(G);
51 | dh.getE();
52 | byte[] actual = dh.getK();
53 |
54 | if (actual[0] == 0) {
55 | Assert.fail("Found leading 0");
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/resources/MultiUserPKAuthenticator/dir_test/home/dir_test/.ssh/authorized_keys/empty_dir:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YahooArchive/artifactory_ssh_proxy/63feb0963ddf278bf0acad6b48c608b3087fa30e/src/test/resources/MultiUserPKAuthenticator/dir_test/home/dir_test/.ssh/authorized_keys/empty_dir
--------------------------------------------------------------------------------
/src/test/resources/MultiUserPKAuthenticator/empty_home/empty_dir:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YahooArchive/artifactory_ssh_proxy/63feb0963ddf278bf0acad6b48c608b3087fa30e/src/test/resources/MultiUserPKAuthenticator/empty_home/empty_dir
--------------------------------------------------------------------------------
/src/test/resources/MultiUserPKAuthenticator/home/areese/.ssh/authorized_keys:
--------------------------------------------------------------------------------
1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhAHddpmSbk11HiaiGeriqzW7xdO08mSvJP/RSzCRdGbOTnQcOgObcQYnI1CRMay2kH5R2ZRajlR80Nqa/QJ3y/zqLNExVUhkJsfnCfK1UIn02d84+6wfCbcKsWIlFVIiBDbPUPepDBZB+VwQUIKtafHIifpFlNz1aKRdOxjmbQiWCqzzQ6AKpue1ylCmW27HzSrNUvcMlNF6NvSoRt4IXXnpTK5ftBoVCS8rVGqi4rECI72BPRngMq0NOPhf8zeqoX0EP8BfyfECEuXlDAMrNpSyIdLOTMUF3EwVb3EmhqiTHg+3gNQcViWyHHaiCiyaiT+JnLsC3q+h4/XkWaZcn areese@dinnercare
2 |
--------------------------------------------------------------------------------
/src/test/resources/MultiUserPKAuthenticator/home/areese/.ssh/bar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YahooArchive/artifactory_ssh_proxy/63feb0963ddf278bf0acad6b48c608b3087fa30e/src/test/resources/MultiUserPKAuthenticator/home/areese/.ssh/bar
--------------------------------------------------------------------------------
/src/test/resources/MultiUserPKAuthenticator/home/areese/bar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YahooArchive/artifactory_ssh_proxy/63feb0963ddf278bf0acad6b48c608b3087fa30e/src/test/resources/MultiUserPKAuthenticator/home/areese/bar
--------------------------------------------------------------------------------
/src/test/resources/MultiUserPKAuthenticator/home/areese/foo_dir/bar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YahooArchive/artifactory_ssh_proxy/63feb0963ddf278bf0acad6b48c608b3087fa30e/src/test/resources/MultiUserPKAuthenticator/home/areese/foo_dir/bar
--------------------------------------------------------------------------------
/src/test/resources/MultiUserPKAuthenticator/home/bob/.ssh/authorized_keys:
--------------------------------------------------------------------------------
1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDxnXUoor++OyjEFIGAXahWOK42W5jP6zwm1MbbfbNLaoCLThbqJhpLnXFo7OcRdiSrgl7/h81mRkVy6wBjCFFJFxH4q5RWA7v5iRAsQxXuZL5Asb3M6YsLNZUfR/ul6KjLOAqkeLorLk+RT52/fE0GHBfpDmi3swLVLZvO+wgTY83kNxFXbKfgJHsSjgexPTlcYmOxsqlMG4eIc4Phtb9njk41qdB7IrxsGvM5gULE7xwKG8S5+KtDTNbbWCuyTwUeF9Yac6ocnolAhtvFtBUuOU/wnvSZVf7WOotbk1kLbHFVlKXscfLbYdC0ljxJP6Dj9PVNZ3wO3K+M/ZL7KEZ9 areese@dinnercare
2 |
--------------------------------------------------------------------------------
/src/test/resources/MultiUserPKAuthenticator/home/sam/.ssh/authorized_keys:
--------------------------------------------------------------------------------
1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDaU2f0cYVAI9PnZCqb6D6l87Lm+QKifZN2oCQU146do63G9Lw1Kaaam3mIVvvIsHRIwWfEx2eY8cKZPFGojIl5s2xa9IgAgv5aixiBCK6mvnHFxTiuBqStslWxOXdZSMXWeFTAK1sEg+IR1eGQICwXKNzGegX0Gp07AS0qRYzYWXBLtObiCJdjOaQxIA5/FysjcuA1FfjuR67zYr+HrtMQdqH+TI9HRs+z7JUGhz4zM19L5tq9c83f2i7wdX+/eNf5cwcc2X2pZW4l7IA+JkXclNnx/mSUCDXM0p/0QzhzLjNmsZtipE5H63XTAq8mfm6VN9BNizly5pyno3Y+bCWD areese@dinnercare
2 |
--------------------------------------------------------------------------------
/src/test/resources/alwaysempty/empty:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YahooArchive/artifactory_ssh_proxy/63feb0963ddf278bf0acad6b48c608b3087fa30e/src/test/resources/alwaysempty/empty
--------------------------------------------------------------------------------
/src/test/resources/auth/auth.txt:
--------------------------------------------------------------------------------
1 | # add repository names and users
2 | # permissions are separated by commas
3 | # users are separated by pipe
4 | # * represents all
5 |
6 | #user a,b can write, all users can read.
7 | repoX=WRITE:a|b,READ:*
8 |
9 | #all writes and reads allowed.
10 | repoY=WRITE:*,READ:*
11 |
12 | #users z can write, users z can read.
13 | repoZ=WRITE:z,READ:z
14 |
15 | #handle bad cases
16 | repoA
17 | repoB=
18 | repoC=WRITE,foo
19 | pepoK
20 |
--------------------------------------------------------------------------------
/src/test/resources/conf/debug.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YahooArchive/artifactory_ssh_proxy/63feb0963ddf278bf0acad6b48c608b3087fa30e/src/test/resources/conf/debug.properties
--------------------------------------------------------------------------------
/src/test/resources/conf/sshd_proxy/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YahooArchive/artifactory_ssh_proxy/63feb0963ddf278bf0acad6b48c608b3087fa30e/src/test/resources/conf/sshd_proxy/.gitkeep
--------------------------------------------------------------------------------
/src/test/resources/conf/sshd_proxy/sshd_proxy.properties:
--------------------------------------------------------------------------------
1 | sshd.port=2222
2 | sshd.artifactoryUrl=http://your-test-artifactory-server:4080/
3 | sshd.artifactoryUsername=test_user_name
4 | sshd.artifactoryPassword=test_password
5 |
--------------------------------------------------------------------------------
/src/test/resources/conf/sshd_proxy/test_env_mapping.properties:
--------------------------------------------------------------------------------
1 | sshd.port=2222
2 | sshd.artifactoryUrl=http://your-test-artifactory-server:4080/
3 | sshd.artifactoryUsername=test_user_name
4 | sshd.artifactoryPassword=test_password
5 | sshd.envMapping.APP_NAME=X-SshProxy-APP_NAME
6 | sshd.envMapping.PROJECT_ID=X-SshProxy-PROJECT_ID
7 | sshd.envMapping.BRANCH=X-SshProxy-BRANCH
8 | sshd.envMapping.PROJECT_TYPE=X-SshProxy-PROJECT_TYPE
9 | sshd.envMapping.JOB_TYPE=X-SshProxy-JOB_TYPE
10 | sshd.envMapping.BUILD_CONTAINER=X-SshProxy-BUILD_CONTAINER
11 | sshd.envMapping.BUILD_NUMBER=X-SshProxy-BUILD_NUMBER
12 | sshd.envMapping.BUILD_URL=X-SshProxy-BUILD_URL
13 | sshd.envMapping.PULL_REQUEST=X-SshProxy-PULL_REQUEST
14 | sshd.envMapping.SCM_URL=X-SshProxy-SCM_URL
15 | sshd.envMapping.GIT_URL=X-SshProxy-GIT_URL
16 | sshd.envMapping.GIT_BRANCH=X-SshProxy-GIT_BRANCH
17 | sshd.envMapping.GIT_COMMIT=X-SshProxy-GIT_COMMIT
18 |
--------------------------------------------------------------------------------
/src/test/resources/developer_config/sshd_proxy.properties:
--------------------------------------------------------------------------------
1 | sshd.root=$ROOT
2 | sshd.port=2222
3 | sshd.artifactoryUrl=http://localhost:4080/artifactory
4 | # use the default.
5 | sshd.artifactoryUsername=admin
6 | sshd.artifactoryPassword=password
7 |
8 | # run artifactory in the same jvm
9 | sshd.jetty.port=4080
10 | sshd.jetty.webapp.dir=$ROOT/webapps
--------------------------------------------------------------------------------
/src/test/resources/hostkey.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN DSA PRIVATE KEY-----
2 | MIIBuwIBAAKBgQCmHrgLRZVPogcZi5zg88Bk2Rv/kD/WlfAu+osRm7hbivR/CdPF
3 | PybvdShop6w410Nw85cjT7wLE1z5ap3CyrPJUzjhCbpS1nuwYuxmHjGVwte4YwbE
4 | leRhE8SngwkPRBhIP/joKesMLU9Rs8KqxiA0xlz3pItQL2J66XUm7p8YHwIVAM5M
5 | XP2CNKAXPnQFS4X0qW+cMDp3AoGBAISfgieVwKM9RinnMTyMbsZgQgRdN9Wo88Tv
6 | tAQRaouDuCf+YL9L4bBf1CYFHMhblnT55oEUPuj/ip3bG7HODIh2vS6F0msARPam
7 | oKkmfvA3SfODdjlSpZkEA8ZPrBlCdSAklxaMLBbfFfZmJqdoMAngkToxBeyF6H4w
8 | +OXgTdVFAoGAHA9QsUR4sd6VcTiu36OSmlW38w5GwFEJw6TS6Vjz3DGqrZGJL9yG
9 | VawA2bUfNZ9h7LqbMYpXe1e+gCjQbbwT7WFgQmI2rRmLw3nlIZsN/2N7n6UdDGvJ
10 | 5UTqjTA12Q6z3m8wWQZQpOXZHait145np84Kx35ZJcaxYEuBAxx3FxwCFH2qwIKF
11 | vLLNhwqFAPCoD5/VC6fW
12 | -----END DSA PRIVATE KEY-----
13 |
--------------------------------------------------------------------------------
/src/test/resources/invalid_keys/test_ssh_key-0:
--------------------------------------------------------------------------------
1 | SSH PRIVATE KEY FILE FORMAT 1.1
2 | ���s���>��Y�f7���*'X˿� 5p@z �>:��a�
3 | |�)��sL���0�E��!ĕS�D��t�z���ű�h���Ցt� -z��M�|� B�t:g}0�9�͈�+�&���QaY�:�>X����a(s5o\�B0�o�"x��f
4 | ��i^-�̈ؤ>{"����`�+��(�պ���;�2����)GqPu4-