├── sshd-shell-spring-boot-starter
└── src
│ ├── test
│ ├── resources
│ │ ├── banner.txt
│ │ ├── db
│ │ │ ├── changelog
│ │ │ │ ├── db.changelog-master.yaml
│ │ │ │ └── changes
│ │ │ │ │ └── 01.xml
│ │ │ └── migration
│ │ │ │ └── test.sql
│ │ ├── banner.png
│ │ ├── id_rsa.pub
│ │ ├── application.properties
│ │ └── id_rsa
│ └── java
│ │ └── sshd
│ │ └── shell
│ │ └── springboot
│ │ ├── console
│ │ └── ConsoleIOTest.java
│ │ ├── autoconfiguration
│ │ ├── SshdShellAutoConfigurationAuthProviderBeanTest.java
│ │ ├── SshdShellAutoConfigurationAuthProviderInvalidAuthTypeTest.java
│ │ ├── SshSessionContextTest.java
│ │ ├── SshdSftpEnabledTest.java
│ │ ├── SshdShellAutoConfigurationWithPublicKeyAndBannerImageTest.java
│ │ ├── SshdShellAutoConfigurationDisabledEndpointTest.java
│ │ ├── SshdShellAutoConfigurationAuthProviderTest.java
│ │ ├── AbstractSshSupport.java
│ │ └── ConfigTest.java
│ │ ├── command
│ │ ├── DummyCommand.java
│ │ ├── ExceptionCommand.java
│ │ ├── TestCommand.java
│ │ └── EndpointCommand.java
│ │ └── util
│ │ └── ZipUtilsTest.java
│ └── main
│ ├── resources
│ ├── META-INF
│ │ └── spring.factories
│ └── config
│ │ └── application.properties
│ └── java
│ └── sshd
│ └── shell
│ └── springboot
│ ├── ShellException.java
│ ├── console
│ ├── UsageInfo.java
│ ├── ColorType.java
│ ├── DefaultUserInputProcessor.java
│ ├── HighlightUserInputProcessor.java
│ ├── ConsoleConfiguration.java
│ ├── MailUserInputProcessor.java
│ ├── ConsoleIO.java
│ ├── BaseUserInputProcessor.java
│ └── TerminalProcessor.java
│ ├── autoconfiguration
│ ├── Constants.java
│ ├── CommandExecutor.java
│ ├── SshdShellCommand.java
│ ├── SshSessionContext.java
│ ├── CommandExecutableDetails.java
│ ├── SshdShellProperties.java
│ ├── ShellBanner.java
│ └── SshdShellAutoConfiguration.java
│ ├── util
│ ├── Assert.java
│ ├── JsonUtils.java
│ └── ZipUtils.java
│ ├── command
│ ├── AbstractSystemCommand.java
│ ├── ExitCommand.java
│ ├── InfoCommand.java
│ ├── BeansCommand.java
│ ├── FlywayCommand.java
│ ├── MappingsCommand.java
│ ├── HttpTraceCommand.java
│ ├── ThreadDumpCommand.java
│ ├── LiquibaseCommand.java
│ ├── ShutdownCommand.java
│ ├── ScheduledTasksCommand.java
│ ├── ConditionsReportCommand.java
│ ├── CommandUtils.java
│ ├── ConfigurationPropertiesReportCommand.java
│ ├── IntegrationGraphCommand.java
│ ├── EnvironmentCommand.java
│ ├── LogfileCommand.java
│ ├── HealthCommand.java
│ ├── CachesCommand.java
│ ├── HeapDumpCommand.java
│ ├── HelpCommand.java
│ ├── AuditEventsCommand.java
│ ├── MetricsCommand.java
│ ├── SessionsCommand.java
│ └── LoggersCommand.java
│ └── server
│ ├── SshdAuthorizedKeysAuthenticator.java
│ ├── SimpleSshdPasswordAuthenticator.java
│ ├── SshdNativeFileSystemFactory.java
│ ├── AuthProviderSshdPasswordAuthenticator.java
│ ├── SshSessionInstance.java
│ └── SshdServerConfiguration.java
├── sshd-shell-spring-boot-test-app
├── src
│ └── main
│ │ ├── resources
│ │ ├── db
│ │ │ ├── changelog
│ │ │ │ ├── db.changelog-master.yaml
│ │ │ │ └── changes
│ │ │ │ │ └── 01.xml
│ │ │ └── migration
│ │ │ │ └── test.sql
│ │ ├── banner.png
│ │ ├── templates
│ │ │ └── test.html
│ │ ├── application.properties
│ │ └── banner.txt
│ │ └── java
│ │ └── demo
│ │ ├── MyController.java
│ │ ├── Main.java
│ │ ├── EchoCommand.java
│ │ ├── AdminCommand.java
│ │ └── MySecurityConfig.java
└── pom.xml
├── .gitignore
├── .github
├── ISSUE_TEMPLATE
│ ├── Feature_request.md
│ └── Bug_report.md
└── workflows
│ └── actions.yml
├── pom.xml
└── CODE_OF_CONDUCT.md
/sshd-shell-spring-boot-starter/src/test/resources/banner.txt:
--------------------------------------------------------------------------------
1 | Spring Boot
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/resources/db/changelog/db.changelog-master.yaml:
--------------------------------------------------------------------------------
1 | databaseChangeLog:
2 | - includeAll:
3 | path: classpath*:db/changelog/changes/
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-test-app/src/main/resources/db/changelog/db.changelog-master.yaml:
--------------------------------------------------------------------------------
1 | databaseChangeLog:
2 | - includeAll:
3 | path: classpath*:db/changelog/changes/
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/resources/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anand1st/sshd-shell-spring-boot/HEAD/sshd-shell-spring-boot-starter/src/test/resources/banner.png
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-test-app/src/main/resources/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anand1st/sshd-shell-spring-boot/HEAD/sshd-shell-spring-boot-test-app/src/main/resources/banner.png
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=sshd.shell.springboot.autoconfiguration.SshdShellAutoConfiguration
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /sshd-shell-spring-boot-starter/target/
2 | /sshd-shell-spring-boot-test-app/target/
3 | /sshd-shell-spring-boot-test-app/hostKey.ser
4 | /sshd-shell-spring-boot-test-app/sshd.log
5 | /.idea/
6 | **/.DS_Store
7 | **/*.iml
8 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/resources/db/migration/test.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE IF NOT EXISTS `employee` (
2 | `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
3 | `name` varchar(20),
4 | `email` varchar(50),
5 | `date_of_birth` timestamp
6 | );
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-test-app/src/main/resources/db/migration/test.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE IF NOT EXISTS `employee` (
2 | `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
3 | `name` varchar(20),
4 | `email` varchar(50),
5 | `date_of_birth` timestamp
6 | );
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-test-app/src/main/resources/templates/test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | TODO supply a title
5 |
6 |
7 |
8 |
9 | TODO write content
10 |
11 |
12 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-test-app/src/main/java/demo/MyController.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import org.springframework.stereotype.Controller;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 |
6 | /**
7 | *
8 | * @author anand
9 | */
10 | @Controller
11 | public class MyController {
12 |
13 | @GetMapping("/test")
14 | public String test() {
15 | return "test";
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/resources/id_rsa.pub:
--------------------------------------------------------------------------------
1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAqo77h58REjvlpIPXCGzTAwEyFiPbdPFCcMh45jkjoufU6dtqJfqcfyfdiT0quuCCMj2uCtHPy5gbWzT9bmB7f2qdff+Ap3gnRAsRtVhXxdeqVsFBgTZpXK9wXxT0E/Hrt+mknTBqRiibu1pHQU1RfJ2FwY5FQAygJeO3KaadpGFdmeFMVxZ5XGFetUziQqS0uJYT2kKLGLfG4Iaa8PJ06tpmJGuNkftEnYIKDH9FLFIwxtBThoaCl/BZIHqFu3VTb/wzfWPW7SZ/gJ+1WauwgqMaDF5ry0rCd5dcxXr5JbpDGbkbCuhTVt3CPhNtXLQqz7Uggs6/I9ipdnVtMS3J
2 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/Feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 |
5 | ---
6 |
7 | **Is your feature request related to a problem? Please describe.**
8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9 |
10 | **Describe the solution you'd like**
11 | A clear and concise description of what you want to happen.
12 |
13 | **Describe alternatives you've considered**
14 | A clear and concise description of any alternative solutions or features you've considered.
15 |
16 | **Additional context**
17 | Add any other context or screenshots about the feature request here.
18 |
--------------------------------------------------------------------------------
/.github/workflows/actions.yml:
--------------------------------------------------------------------------------
1 | name: Build/Test Pipeline
2 | on: [push]
3 | jobs:
4 | Main:
5 | runs-on: ubuntu-latest
6 | steps:
7 | - run: echo "Job triggered by ${{ github.event_name }} event."
8 | - name: Checkout Repository Code
9 | uses: actions/checkout@v2
10 | - name: Set up JDK 8
11 | uses: actions/setup-java@v2
12 | with:
13 | java-version: '8'
14 | distribution: 'adopt'
15 | cache: maven
16 | - name: Change to sshd-shell-spring-boot-starter directory
17 | run: cd sshd-shell-spring-boot-starter
18 | - name: Build with Maven
19 | run: mvn --batch-mode --update-snapshots test org.jacoco:jacoco-maven-plugin:report
20 | - name: Coverall Coverage Report Submission
21 | run: mvn --batch-mode org.eluder.coveralls:coveralls-maven-plugin:report --define repoToken=${{ secrets.COVERALL_REPO_TOKEN }}
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/Bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 |
5 | ---
6 |
7 | **Describe the bug**
8 | A clear and concise description of what the bug is.
9 |
10 | **To Reproduce**
11 | Steps to reproduce the behavior:
12 | 1. Go to '...'
13 | 2. Click on '....'
14 | 3. Scroll down to '....'
15 | 4. See error
16 |
17 | **Expected behavior**
18 | A clear and concise description of what you expected to happen.
19 |
20 | **Screenshots**
21 | If applicable, add screenshots to help explain your problem.
22 |
23 | **Desktop (please complete the following information):**
24 | - OS: [e.g. iOS]
25 | - Browser [e.g. chrome, safari]
26 | - Version [e.g. 22]
27 |
28 | **Smartphone (please complete the following information):**
29 | - Device: [e.g. iPhone6]
30 | - OS: [e.g. iOS8.1]
31 | - Browser [e.g. stock browser, safari]
32 | - Version [e.g. 22]
33 |
34 | **Additional context**
35 | Add any other context about the problem here.
36 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-test-app/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | logging.level.sshd.shell=DEBUG
2 | #logging.level.org.apache.sshd=DEBUG
3 | logging.file.name=sshd.log
4 |
5 | management.endpoint.shutdown.enabled=true
6 |
7 | spring.main.allow-circular-references=true
8 |
9 | spring.flyway.baseline-on-migrate=true
10 |
11 | spring.jmx.enabled=true
12 |
13 | sshd.shell.enabled=true
14 | sshd.shell.text.color=BLUE
15 | sshd.shell.prompt.color=RED
16 | sshd.shell.prompt.title=server
17 |
18 | sshd.filetransfer.enabled=true
19 | sshd.filesystem.base.dir=/Users/anand
20 |
21 | ### Enable configuration below for authentication/authorization via spring-security
22 | sshd.shell.auth.authType=AUTH_PROVIDER
23 |
24 | ### Enable configuration below for simple authentication/authorization
25 | sshd.shell.password=admin
26 |
27 | ### Enable and replace username/password below to test with gmail (ensure 'less secure app' setting is turned on)
28 | #spring.mail.username=
29 | #spring.mail.password=
30 | #spring.mail.host=smtp.gmail.com
31 | #spring.mail.port=465
32 | #spring.mail.protocol=smtps
33 |
34 | spring.redis.port=${embeddedRedisPort}
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/ShellException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot;
17 |
18 | /**
19 | *
20 | * @author anand
21 | */
22 | public class ShellException extends Exception {
23 |
24 | private static final long serialVersionUID = 7114130906989289480L;
25 |
26 | public ShellException(String message) {
27 | super(message);
28 | }
29 |
30 | public ShellException(String message, Throwable cause) {
31 | super(message, cause);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/resources/application.properties:
--------------------------------------------------------------------------------
1 | # Copyright 2017 anand.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | sshd.shell.enabled=true
16 | sshd.shell.port=0
17 | sshd.shell.hostKeyFile=target/hostKey.ser
18 |
19 | logging.level.sshd.shell=INFO
20 | logging.file.name=target/sshd.log
21 |
22 | spring.mail.host=127.0.0.1
23 | spring.mail.port=0
24 | spring.mail.username=anand@test.com
25 | spring.mail.password=xxx
26 | spring.mail.protocol=smtp
27 |
28 | management.endpoint.shutdown.enabled=true
29 |
30 | spring.cache.cache-names=test
31 | spring.cache.caffeine.spec=maximumSize=10, expireAfterAccess=30s
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/console/UsageInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.console;
17 |
18 | import java.util.List;
19 |
20 | /**
21 | *
22 | * @author anand
23 | */
24 | @lombok.AllArgsConstructor
25 | @lombok.Getter
26 | public class UsageInfo {
27 |
28 | private final List rows;
29 |
30 | @lombok.AllArgsConstructor
31 | @lombok.Getter
32 | public static class Row {
33 |
34 | private final String usage;
35 | private final String description;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/autoconfiguration/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.autoconfiguration;
17 |
18 | /**
19 | * For internal use only.
20 | *
21 | * @author anand
22 | */
23 | public enum Constants {
24 |
25 | ;
26 | public static final String USER = "__user";
27 | public static final String HELP = "help";
28 | public static final String USER_ROLES = "__userRoles";
29 | public static final String EXECUTE = "__execute";
30 | public static final String SHELL_BANNER = "__shellBanner";
31 | }
32 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/resources/db/changelog/changes/01.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-test-app/src/main/resources/db/changelog/changes/01.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/autoconfiguration/CommandExecutor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package sshd.shell.springboot.autoconfiguration;
20 |
21 | import sshd.shell.springboot.ShellException;
22 |
23 | /**
24 | *
25 | * @author anand
26 | */
27 | @FunctionalInterface
28 | interface CommandExecutor {
29 |
30 | String get(String arg) throws InterruptedException, ShellException;
31 | }
32 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/console/ColorType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.console;
17 |
18 | import org.jline.utils.AttributedStyle;
19 |
20 | /**
21 | *
22 | * @author anand
23 | */
24 | @lombok.AllArgsConstructor
25 | public enum ColorType {
26 |
27 | BLACK(AttributedStyle.BLACK),
28 | RED(AttributedStyle.RED),
29 | GREEN(AttributedStyle.GREEN),
30 | YELLOW(AttributedStyle.YELLOW),
31 | BLUE(AttributedStyle.BLUE),
32 | MAGENTA(AttributedStyle.MAGENTA),
33 | CYAN(AttributedStyle.CYAN),
34 | WHITE(AttributedStyle.WHITE);
35 |
36 | public final int value;
37 | }
38 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/java/sshd/shell/springboot/console/ConsoleIOTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.console;
17 |
18 | import static org.junit.Assert.assertTrue;
19 | import org.junit.Test;
20 | import sshd.shell.springboot.util.JsonUtils;
21 |
22 | /**
23 | *
24 | * @author anand
25 | */
26 | public class ConsoleIOTest {
27 |
28 | @Test
29 | public void testConsoleIOAsJsonException() {
30 | assertTrue(JsonUtils.asJson(new X("x")).startsWith("Error processing json output"));
31 | }
32 |
33 | @lombok.AllArgsConstructor
34 | private static class X {
35 | final String x;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/util/Assert.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.util;
17 |
18 | import java.util.Objects;
19 | import sshd.shell.springboot.ShellException;
20 |
21 | /**
22 | *
23 | * @author anand
24 | */
25 | public enum Assert {
26 | ;
27 |
28 | public static void isTrue(boolean statement, String errorMessage) throws ShellException {
29 | if (!statement) {
30 | throw new ShellException(errorMessage);
31 | }
32 | }
33 |
34 | public static void isNotNull(Object object, String errorMessage) throws ShellException {
35 | isTrue(Objects.nonNull(object), errorMessage);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/AbstractSystemCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.command;
17 |
18 | import java.util.Arrays;
19 | import java.util.Collections;
20 | import java.util.HashSet;
21 | import java.util.Set;
22 |
23 | /**
24 | *
25 | * @author anand
26 | */
27 | public abstract class AbstractSystemCommand {
28 |
29 | private final Set systemRoles;
30 |
31 | public AbstractSystemCommand(String[] systemRoles) {
32 | this.systemRoles = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(systemRoles)));
33 | }
34 |
35 | public final Set getSystemRoles() {
36 | return systemRoles;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | io.github.anand1st
6 | sshd-shell-spring-boot-parent
7 | 1.0-SNAPSHOT
8 | pom
9 | https://github.com/anand1st/sshd-shell-spring-boot
10 |
11 | UTF-8
12 |
13 |
14 |
15 | Apache License, Version 2.0
16 | http://www.apache.org/licenses/LICENSE-2.0.txt
17 | repo
18 |
19 |
20 |
21 | https://github.com/anand1st/sshd-shell-spring-boot.git
22 |
23 |
24 |
25 | Nithyanandan Natchimuthu
26 | anand1st@gmail.com
27 |
28 |
29 |
30 | sshd-shell-spring-boot-starter
31 | sshd-shell-spring-boot-test-app
32 |
33 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-test-app/src/main/java/demo/Main.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import javax.annotation.PreDestroy;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.cache.annotation.EnableCaching;
7 | import org.springframework.util.SocketUtils;
8 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
9 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
10 | import redis.embedded.RedisServer;
11 |
12 | /**
13 | *
14 | * @author anand
15 | */
16 | @EnableCaching
17 | @SpringBootApplication
18 | public class Main extends WebMvcConfigurationSupport {
19 |
20 | private static final RedisServer REDIS_SERVER;
21 |
22 | static {
23 | int availablePort = SocketUtils.findAvailableTcpPort();
24 | System.setProperty("embeddedRedisPort", String.valueOf(availablePort));
25 | REDIS_SERVER = new RedisServer(availablePort);
26 | REDIS_SERVER.start();
27 | }
28 |
29 | public static void main(String... args) {
30 | SpringApplication.run(Main.class, args);
31 | }
32 |
33 | @PreDestroy
34 | void cleanUp() {
35 | REDIS_SERVER.stop();
36 | }
37 |
38 | @Override
39 | protected void addViewControllers(ViewControllerRegistry registry) {
40 | registry.addViewController("/test").setViewName("test");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/ExitCommand.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package sshd.shell.springboot.command;
20 |
21 | import org.springframework.stereotype.Component;
22 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
23 |
24 | /**
25 | *
26 | * @author anand
27 | */
28 | @Component
29 | @lombok.NoArgsConstructor(access = lombok.AccessLevel.PACKAGE)
30 | @SshdShellCommand(value = "exit", description = "Exit shell")
31 | public final class ExitCommand {
32 |
33 | public String exit(String arg) throws InterruptedException {
34 | throw new InterruptedException("Exiting shell");
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/java/sshd/shell/springboot/autoconfiguration/SshdShellAutoConfigurationAuthProviderBeanTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.autoconfiguration;
17 |
18 | import org.springframework.boot.test.context.SpringBootTest;
19 | import org.springframework.test.annotation.DirtiesContext;
20 |
21 | /**
22 | *
23 | * @author anand
24 | */
25 | @SpringBootTest(classes = ConfigTest.class, properties = {
26 | "sshd.shell.auth.authType=AUTH_PROVIDER",
27 | "sshd.shell.username=bob",
28 | "sshd.shell.password=bob",
29 | "sshd.shell.auth.authProviderBeanName=authProvider",
30 | "spring.flyway.baseline-on-migrate=true",
31 | "spring.main.allow-circular-references=true"
32 | })
33 | @DirtiesContext
34 | public class SshdShellAutoConfigurationAuthProviderBeanTest extends SshdShellAutoConfigurationAuthProviderTest {
35 | }
36 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/java/sshd/shell/springboot/autoconfiguration/SshdShellAutoConfigurationAuthProviderInvalidAuthTypeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.autoconfiguration;
17 |
18 | import org.springframework.boot.test.context.SpringBootTest;
19 | import org.springframework.test.annotation.DirtiesContext;
20 |
21 | /**
22 | *
23 | * @author anand
24 | */
25 | @SpringBootTest(classes = ConfigTest.class, properties = {
26 | "sshd.shell.auth.authType=AUTH_PROVIDER",
27 | "sshd.shell.username=bob",
28 | "sshd.shell.password=bob",
29 | "sshd.shell.auth.authProviderBeanName=authProvider",
30 | "spring.flyway.baseline-on-migrate=true",
31 | "spring.main.allow-circular-references=true"
32 | })
33 | @DirtiesContext
34 | public class SshdShellAutoConfigurationAuthProviderInvalidAuthTypeTest extends
35 | SshdShellAutoConfigurationAuthProviderTest {
36 | }
37 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/java/sshd/shell/springboot/command/DummyCommand.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package sshd.shell.springboot.command;
20 |
21 | import org.springframework.stereotype.Component;
22 | import org.springframework.transaction.annotation.Transactional;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 |
25 | /**
26 | *
27 | * @author anand
28 | */
29 | @Component
30 | @SshdShellCommand(value = "dummy", description = "dummy description")
31 | public class DummyCommand {
32 |
33 | @Transactional
34 | @SshdShellCommand(value = "run", description = "dummy run")
35 | public String run(String arg) {
36 | return "dummy run successful";
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-test-app/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ${Ansi.RED} $$$ $$$$$ $$$$ $$$$ $$$$$
2 | ${Ansi.GREEN} $$$ $$$$$$$ $$$$ $$$$ $$$$$$$
3 | ${Ansi.BLUE} $$$ $$$$$$$ $$$$$ $$$$$ $$$$$$$
4 | ${Ansi.RED} $$$ $$$$$$$ $$$$ $$$$ $$$$$$$
5 | ${Ansi.GREEN} $$$ $$$$ $$$$ $$$$$ $$$$$ $$$$ $$$$
6 | ${Ansi.BLUE} $$$ $$$$ $$$$ $$$$ $$$$ $$$$ $$$$
7 | ${Ansi.RED} $$$ $$$$$ $$$$$ $$$$ $$$$ $$$$$ $$$$$
8 | ${Ansi.GREEN} $$$ $$$$ $$$$ $$$$$ $$$$$ $$$$ $$$$
9 | ${Ansi.BLUE} $$$ $$$$ $$$$ $$$$ $$$$ $$$$ $$$$
10 | ${Ansi.RED} $$$ $$$$$ $$$$$ $$$$$ $$$$$ $$$$$ $$$$$
11 | ${Ansi.GREEN} $$$ $$$$$$$$$$$$$ $$$$ $$$$ $$$$$$$$$$$$$
12 | ${Ansi.BLUE} $$$$ $$$$ $$$$$$$$$$$$$ $$$$ $$$$ $$$$$$$$$$$$$
13 | ${Ansi.RED} $$$$ $$$$ $$$$$$$$$$$$$$$ $$$$$$$ $$$$$$$$$$$$$$$
14 | ${Ansi.GREEN} $$$$$ $$$$$ $$$$ $$$$ $$$$$$$ $$$$ $$$$
15 | ${Ansi.BLUE} $$$$$$$$$$$ $$$$$ $$$$$ $$$$$$$ $$$$$ $$$$$
16 | ${Ansi.RED} $$$$$$$$$ $$$$ $$$$ $$$$$ $$$$ $$$$
17 | ${Ansi.GREEN} $$$$$$$ $$$$ $$$$ $$$$$ $$$$ $$$$
18 |
19 | ${Ansi.RED} :: Spring Boot${spring-boot.formatted-version} :: ${Ansi.DEFAULT}
20 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-test-app/src/main/java/demo/EchoCommand.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import java.io.IOException;
4 | import org.springframework.stereotype.Component;
5 | import sshd.shell.springboot.autoconfiguration.SshSessionContext;
6 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
7 | import sshd.shell.springboot.console.ConsoleIO;
8 |
9 | /**
10 | *
11 | * @author anand
12 | */
13 | @Component
14 | @SshdShellCommand(value = "echo", description = "Echo by users. Type 'echo' for supported subcommands")
15 | public class EchoCommand {
16 |
17 | @SshdShellCommand(value = "bob", description = "Bob's echo. Usage: echo bob ")
18 | public String bobSays(String arg) throws IOException {
19 | String name = ConsoleIO.readInput("What's your name?");
20 | SshSessionContext.put("name", name);
21 | return "bob echoes " + arg + " and your name is " + name + ", rooted filesystem path is "
22 | + SshSessionContext.getUserDir().toString();
23 | }
24 |
25 | @SshdShellCommand(value = "alice", description = "Alice's echo. Usage: echo alice ")
26 | public String aliceSays(String arg) {
27 | String str = "";
28 | if (SshSessionContext.containsKey("name")) {
29 | str = ", Name " + SshSessionContext.get("name") + " exists";
30 | }
31 | return "alice says " + arg + str;
32 | }
33 |
34 | @SshdShellCommand(value = "admin", description = "Admin's echo. Usage: echo admin ", roles = "ADMIN")
35 | public String adminSays(String arg) {
36 | return "admin says " + arg;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-test-app/src/main/java/demo/AdminCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package demo;
17 |
18 | import org.springframework.stereotype.Component;
19 | import sshd.shell.springboot.ShellException;
20 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
21 |
22 | /**
23 | *
24 | * @author anand
25 | */
26 | @Component
27 | @SshdShellCommand(value = "admin", description = "Admin functionality. Type 'admin' for supported subcommands",
28 | roles = "ADMIN")
29 | public class AdminCommand {
30 |
31 | @SshdShellCommand(value = "manage", description = "Manage task. Usage: admin manage ", roles = "ADMIN")
32 | public String manage(String arg) {
33 | return arg + " has been managed by admin";
34 | }
35 |
36 | @SshdShellCommand(value = "testShellException", description = "Test throwing ShellException")
37 | public String testShellException(String arg) throws ShellException {
38 | throw new ShellException("Exception Message:" + arg);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/java/sshd/shell/springboot/autoconfiguration/SshSessionContextTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.autoconfiguration;
17 |
18 | import java.io.IOException;
19 | import static org.junit.Assert.assertEquals;
20 | import static org.junit.Assert.assertFalse;
21 | import static org.junit.Assert.assertTrue;
22 | import org.junit.Test;
23 |
24 | /**
25 | *
26 | * @author anand
27 | */
28 | public class SshSessionContextTest {
29 |
30 | @Test
31 | public void testSshSessionContext() throws IOException {
32 | assertFalse(SshSessionContext.containsKey("test"));
33 | SshSessionContext.put("test", "test");
34 | assertEquals("test", SshSessionContext.get("test"));
35 | assertTrue(SshSessionContext.containsKey("test"));
36 | assertEquals("test", SshSessionContext.remove("test"));
37 | assertFalse(SshSessionContext.containsKey("test"));
38 | SshSessionContext.clear();
39 | assertTrue(SshSessionContext.isEmpty());
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/server/SshdAuthorizedKeysAuthenticator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.server;
17 |
18 | import java.nio.file.Path;
19 | import java.security.PublicKey;
20 | import java.util.Collections;
21 | import org.apache.sshd.server.config.keys.AuthorizedKeysAuthenticator;
22 | import org.apache.sshd.server.session.ServerSession;
23 | import sshd.shell.springboot.autoconfiguration.Constants;
24 |
25 | /**
26 | *
27 | * @author anand
28 | */
29 | class SshdAuthorizedKeysAuthenticator extends AuthorizedKeysAuthenticator {
30 |
31 | SshdAuthorizedKeysAuthenticator(Path path) {
32 | super(path);
33 | }
34 |
35 | @Override
36 | public boolean authenticate(String username, PublicKey key, ServerSession session) {
37 | if (super.authenticate(username, key, session)) {
38 | session.getIoSession().setAttribute(Constants.USER_ROLES, Collections.singleton("*"));
39 | session.getIoSession().setAttribute(Constants.USER, username);
40 | return true;
41 | }
42 | return false;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/java/sshd/shell/springboot/util/ZipUtilsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.util;
17 |
18 | import java.io.File;
19 | import java.io.IOException;
20 | import java.nio.file.Files;
21 | import java.nio.file.Path;
22 | import java.nio.file.Paths;
23 | import java.nio.file.StandardCopyOption;
24 | import static org.junit.Assert.assertEquals;
25 | import static org.junit.Assert.assertFalse;
26 | import org.junit.Test;
27 |
28 | /**
29 | *
30 | * @author anand
31 | */
32 | public class ZipUtilsTest {
33 |
34 | @Test
35 | public void testZipFiles() throws IOException {
36 | File zipDir = new File("target");
37 | Files.copy(Paths.get("src/test/resources/banner.txt"), new File(zipDir, "banner.txt").toPath(),
38 | StandardCopyOption.REPLACE_EXISTING);
39 | Path[] filesToZip = {Paths.get("target/banner.txt")};
40 | Path result = ZipUtils.zipFiles(zipDir.toPath(), true, filesToZip);
41 | assertEquals(Paths.get("target/banner.txt.zip"), result);
42 | assertFalse(new File("target/banner.txt").exists());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/java/sshd/shell/springboot/command/ExceptionCommand.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package sshd.shell.springboot.command;
20 |
21 | import org.springframework.stereotype.Component;
22 | import sshd.shell.springboot.ShellException;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 |
25 | /**
26 | *
27 | * @author anand
28 | */
29 | @Component
30 | @SshdShellCommand(value = "exception", description = "throws Exceptions")
31 | public class ExceptionCommand {
32 |
33 | @SshdShellCommand(value = "iae", description = "throws IAE")
34 | public String iae(String arg) {
35 | throw new IllegalArgumentException("illegalargumentexception");
36 | }
37 |
38 | @SshdShellCommand(value = "se", description = "throws ShellException")
39 | public String se(String arg) throws ShellException {
40 | throw new ShellException("shellexception");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/resources/id_rsa:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIIEowIBAAKCAQEAwKqO+4efERI75aSD1whs0wMBMhYj23TxQnDIeOY5I6Ln1Onb
3 | aiX6nH8n3Yk9KrrggjI9rgrRz8uYG1s0/W5ge39qnX3/gKd4J0QLEbVYV8XXqlbB
4 | QYE2aVyvcF8U9BPx67fppJ0wakYom7taR0FNUXydhcGORUAMoCXjtymmnaRhXZnh
5 | TFcWeVxhXrVM4kKktLiWE9pCixi3xuCGmvDydOraZiRrjZH7RJ2CCgx/RSxSMMbQ
6 | U4aGgpfwWSB6hbt1U2/8M31j1u0mf4CftVmrsIKjGgxea8tKwneXXMV6+SW6Qxm5
7 | GwroU1bdwj4TbVy0Ks+1IILOvyPYqXZ1bTEtyQIDAQABAoIBAA0He8Pm2Ar/gK13
8 | ArN4DmP2wA3zEVm1/trPZb9HUnXmfmcXqY70Io6Sys9giJJrMOOdIi6y7J1w10iC
9 | UoMRA9VWOI+OBcldifKd12HLMb490ufiFg+n/VYCvpqK04/uCV43gcVwG+YT+IsP
10 | kHthHylzk/OHs2dbfX8XEN9CIdJnPSrqc28sKSOu5Wp8fY1kb//UkM42RWv8ewlo
11 | 6FLDKHVbybmX4GZLLN43b6pTY5HoorYUjuBjfSKTyJwecdn02bWWGb834kv09fRH
12 | gd4HGk+iO+9jM2teppLZcRCpC3WtHVZ1KSdSkYZdNHy0oJYLI9fKZ44fJ7IbefJC
13 | kfwPYAECgYEA+wTUdYwh0YbFOIaO5cc4n46SgOQ8skJphT1/PLI8O31KRLlbT8yh
14 | lR1FLKJEuXfn/o7nGypci25uU1Wj59sIrSqHT7w+EYJE5brhR1Tq9LA25KWd3mZz
15 | 1FwwfwGnOj8xrQxoRLmV0PSdq5IEz0TOGhASmwpqlynaYqf7qbYr3cECgYEAxH1M
16 | cpakna28hpHNN2a1JT/DKG75xcGkoCy7wk20EQu20W+yWcep+mfKIYySSpQvukqU
17 | j+hVj4XI2gQA2VgO/SjrfBnPaEoSbJhodo4frV7DOFqasu8KpIWy/75Ys2ZH+oYH
18 | bTC4+FsZm+XDIGxFBSQU8AFf973EmxqiSmhi4gkCgYBcFtKG6UkC4El8SkkkXSkV
19 | yC1RIepuj1S87+m877qPLJDRk5q/NNhWpy1YiZNi4212AyEf4zOeZ34MDpAaIE4X
20 | kVGg2/N9Yug5y4yYKbwk1nzc9zFqhPWbg9K61XVvNf3YeYPLKraeuQ8bAW/IRnrC
21 | LwFUZcbi/BTFOtFl2pJPQQKBgQCb8g4wi9sOwgr0itdi9wMiEx8jAiD+kRfFgHts
22 | VRtqw+9O/eWBV/RSJvnH8rdQtZfDtNl/9Zeilz23uqGp3jfXORjcn+d7D/7bbYLL
23 | RTVi9eje2xoYlZvOw8YzL7FagPzzmlhekuLbSgJjNtHM8+E7mU18xrqR920I5PSV
24 | NY/1cQKBgH0zfFHuoHwZnSGrV5m1wsIcvjxMznM+ny9gsMv23wedojmo4b1YNBjr
25 | 4q+XkzII08QFbPmTP9zGq/twFvi2NcKkLTEZLV8tt2TnhP9jKmsnbaHD7xzNh9xn
26 | xtjO3/abxp9qjyPfwx8R8DWdjDj/PHEntOs1WRXs8Pc6nTNr9cGJ
27 | -----END RSA PRIVATE KEY-----
28 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/util/JsonUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.util;
17 |
18 | import com.fasterxml.jackson.core.JsonProcessingException;
19 | import com.fasterxml.jackson.databind.ObjectMapper;
20 | import com.fasterxml.jackson.databind.ObjectWriter;
21 | import java.io.IOException;
22 |
23 | /**
24 | *
25 | * @author anand
26 | */
27 | @lombok.extern.slf4j.Slf4j
28 | public enum JsonUtils {
29 | ;
30 |
31 | private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().findAndRegisterModules();
32 | private static final ObjectWriter WRITER = OBJECT_MAPPER.writer().withDefaultPrettyPrinter();
33 |
34 | public static String asJson(Object object) {
35 | try {
36 | return WRITER.writeValueAsString(object);
37 | } catch (JsonProcessingException ex) {
38 | log.error("Error processing json output", ex);
39 | return "Error processing json output: " + ex.getMessage();
40 | }
41 | }
42 |
43 | public static E stringToObject(String json, Class clazz) throws IOException {
44 | return OBJECT_MAPPER.readValue(json, clazz);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/autoconfiguration/SshdShellCommand.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package sshd.shell.springboot.autoconfiguration;
20 |
21 | import java.lang.annotation.ElementType;
22 | import java.lang.annotation.Retention;
23 | import java.lang.annotation.RetentionPolicy;
24 | import java.lang.annotation.Target;
25 |
26 | /**
27 | *
28 | * @author anand
29 | */
30 | @Retention(RetentionPolicy.RUNTIME)
31 | @Target({ElementType.TYPE, ElementType.METHOD})
32 | public @interface SshdShellCommand {
33 |
34 | /**
35 | * Command.
36 | * @return command
37 | */
38 | public String value();
39 |
40 | /**
41 | * Description of command.
42 | * @return description of command
43 | */
44 | public String description();
45 |
46 | /**
47 | * Roles that can execute command.
48 | * @return supported roles for executing command
49 | */
50 | public String[] roles() default {"*"};
51 | }
52 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/console/DefaultUserInputProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.console;
17 |
18 | import java.util.Optional;
19 | import java.util.regex.Pattern;
20 | import org.springframework.core.annotation.Order;
21 | import org.springframework.stereotype.Component;
22 | import sshd.shell.springboot.ShellException;
23 | import sshd.shell.springboot.util.Assert;
24 |
25 | /**
26 | *
27 | * @author anand
28 | */
29 | @Component("__defaultUserInputProcessor")
30 | @Order(Integer.MAX_VALUE)
31 | class DefaultUserInputProcessor extends BaseUserInputProcessor {
32 |
33 | private final String[] bannedSymbols = {"|"};
34 |
35 | @Override
36 | public Optional getUsageInfo() {
37 | return Optional.empty();
38 | }
39 |
40 | @Override
41 | public Pattern getPattern() {
42 | return Pattern.compile(".+");
43 | }
44 |
45 | @Override
46 | public void processUserInput(String userInput) throws InterruptedException, ShellException {
47 | for (String bannedSymbol : bannedSymbols) {
48 | Assert.isTrue(!userInput.contains(bannedSymbol), "Invalid command");
49 | }
50 | ConsoleIO.writeOutput(processCommands(userInput));
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/InfoCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.command;
17 |
18 | import org.springframework.beans.factory.annotation.Value;
19 | import org.springframework.boot.actuate.info.InfoEndpoint;
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22 | import org.springframework.stereotype.Component;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 | import sshd.shell.springboot.util.JsonUtils;
25 |
26 | /**
27 | *
28 | * @author anand
29 | */
30 | @Component
31 | @ConditionalOnBean(InfoEndpoint.class)
32 | @ConditionalOnProperty(name = "management.endpoint.info.enabled", havingValue = "true", matchIfMissing = true)
33 | @SshdShellCommand(value = "info", description = "System status")
34 | public final class InfoCommand extends AbstractSystemCommand {
35 |
36 | private final InfoEndpoint infoEndpoint;
37 |
38 | InfoCommand(@Value("${sshd.system.command.roles.info}") String[] systemRoles, InfoEndpoint infoEndpoint) {
39 | super(systemRoles);
40 | this.infoEndpoint = infoEndpoint;
41 | }
42 |
43 | public String info(String arg) {
44 | return JsonUtils.asJson(infoEndpoint.info());
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/server/SimpleSshdPasswordAuthenticator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.server;
17 |
18 | import java.util.Set;
19 | import org.apache.sshd.server.auth.password.PasswordAuthenticator;
20 | import org.apache.sshd.server.auth.password.PasswordChangeRequiredException;
21 | import org.apache.sshd.server.session.ServerSession;
22 | import sshd.shell.springboot.autoconfiguration.Constants;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellProperties.Shell;
24 |
25 | /**
26 | *
27 | * @author anand
28 | */
29 | @lombok.AllArgsConstructor(access = lombok.AccessLevel.PACKAGE)
30 | class SimpleSshdPasswordAuthenticator implements PasswordAuthenticator {
31 |
32 | private final Shell props;
33 | private final Set systemCommandRoles;
34 |
35 | @Override
36 | public boolean authenticate(String username, String password, ServerSession session) throws
37 | PasswordChangeRequiredException {
38 | if (username.equals(props.getUsername()) && password.equals(props.getPassword())) {
39 | session.getIoSession().setAttribute(Constants.USER_ROLES, systemCommandRoles);
40 | session.getIoSession().setAttribute(Constants.USER, username);
41 | return true;
42 | }
43 | return false;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/BeansCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.command;
17 |
18 | import org.springframework.beans.factory.annotation.Value;
19 | import org.springframework.boot.actuate.beans.BeansEndpoint;
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22 | import org.springframework.stereotype.Component;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 | import sshd.shell.springboot.util.JsonUtils;
25 |
26 | /**
27 | *
28 | * @author anand
29 | */
30 | @Component
31 | @ConditionalOnBean(BeansEndpoint.class)
32 | @ConditionalOnProperty(name = "management.endpoint.beans.enabled", havingValue = "true", matchIfMissing = true)
33 | @SshdShellCommand(value = "beans", description = "List beans")
34 | public final class BeansCommand extends AbstractSystemCommand {
35 |
36 | private final BeansEndpoint beansEndpoint;
37 |
38 | BeansCommand(@Value("${sshd.system.command.roles.beans}") String[] systemRoles, BeansEndpoint beansEndpoint) {
39 | super(systemRoles);
40 | this.beansEndpoint = beansEndpoint;
41 | }
42 |
43 | public String beans(String arg) {
44 | return JsonUtils.asJson(beansEndpoint.beans());
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/FlywayCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.command;
17 |
18 | import org.springframework.beans.factory.annotation.Value;
19 | import org.springframework.boot.actuate.flyway.FlywayEndpoint;
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22 | import org.springframework.stereotype.Component;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 | import sshd.shell.springboot.util.JsonUtils;
25 |
26 | /**
27 | *
28 | * @author anand
29 | */
30 | @Component
31 | @ConditionalOnBean(FlywayEndpoint.class)
32 | @ConditionalOnProperty(name = "management.endpoint.flyway.enabled", havingValue = "true", matchIfMissing = true)
33 | @SshdShellCommand(value = "flyway", description = "Flyway database migration details (if applicable)")
34 | public final class FlywayCommand extends AbstractSystemCommand {
35 |
36 | private final FlywayEndpoint flywayEndpoint;
37 |
38 | FlywayCommand(@Value("${sshd.system.command.roles.flyway}") String[] systemRoles, FlywayEndpoint flywayEndpoint) {
39 | super(systemRoles);
40 | this.flywayEndpoint = flywayEndpoint;
41 | }
42 |
43 | public String flyway(String arg) {
44 | return JsonUtils.asJson(flywayEndpoint.flywayBeans());
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/MappingsCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.command;
17 |
18 | import org.springframework.beans.factory.annotation.Value;
19 | import org.springframework.boot.actuate.web.mappings.MappingsEndpoint;
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22 | import org.springframework.stereotype.Component;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 | import sshd.shell.springboot.util.JsonUtils;
25 |
26 | /**
27 | *
28 | * @author anand
29 | */
30 | @Component
31 | @ConditionalOnBean(MappingsEndpoint.class)
32 | @ConditionalOnProperty(name = "management.endpoint.mappings.enabled", havingValue = "true", matchIfMissing = true)
33 | @SshdShellCommand(value = "mappings", description = "List http request mappings")
34 | public final class MappingsCommand extends AbstractSystemCommand {
35 |
36 | private final MappingsEndpoint mappingsEndpoint;
37 |
38 | MappingsCommand(@Value("${sshd.system.command.roles.mappings}") String[] systemRoles,
39 | MappingsEndpoint mappingsEndpoint) {
40 | super(systemRoles);
41 | this.mappingsEndpoint = mappingsEndpoint;
42 | }
43 |
44 | public String mappings(String arg) {
45 | return JsonUtils.asJson(mappingsEndpoint.mappings());
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/HttpTraceCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.command;
17 |
18 | import org.springframework.beans.factory.annotation.Value;
19 | import org.springframework.boot.actuate.trace.http.HttpTraceEndpoint;
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22 | import org.springframework.stereotype.Component;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 | import sshd.shell.springboot.util.JsonUtils;
25 |
26 | /**
27 | *
28 | * @author anand
29 | */
30 | @Component
31 | @ConditionalOnBean(HttpTraceEndpoint.class)
32 | @ConditionalOnProperty(name = "management.endpoint.httptrace.enabled", havingValue = "true", matchIfMissing = true)
33 | @SshdShellCommand(value = "httpTrace", description = "Http trace information")
34 | public final class HttpTraceCommand extends AbstractSystemCommand {
35 |
36 | private final HttpTraceEndpoint httpTraceEndpoint;
37 |
38 | HttpTraceCommand(@Value("${sshd.system.command.roles.httpTrace}") String[] systemRoles,
39 | HttpTraceEndpoint httpTraceEndpoint) {
40 | super(systemRoles);
41 | this.httpTraceEndpoint = httpTraceEndpoint;
42 | }
43 |
44 | public String httpTrace(String arg) {
45 | return JsonUtils.asJson(httpTraceEndpoint.traces());
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/ThreadDumpCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.command;
17 |
18 | import org.springframework.beans.factory.annotation.Value;
19 | import org.springframework.boot.actuate.management.ThreadDumpEndpoint;
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22 | import org.springframework.stereotype.Component;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 | import sshd.shell.springboot.util.JsonUtils;
25 |
26 | /**
27 | *
28 | * @author anand
29 | */
30 | @Component
31 | @ConditionalOnBean(ThreadDumpEndpoint.class)
32 | @ConditionalOnProperty(name = "management.endpoint.threaddump.enabled", havingValue = "true", matchIfMissing = true)
33 | @SshdShellCommand(value = "threadDump", description = "Print thread dump")
34 | public final class ThreadDumpCommand extends AbstractSystemCommand {
35 |
36 | private final ThreadDumpEndpoint threadDumpEndpoint;
37 |
38 | ThreadDumpCommand(@Value("${sshd.system.command.roles.threadDump}") String[] systemRoles,
39 | ThreadDumpEndpoint threadDumpEndpoint) {
40 | super(systemRoles);
41 | this.threadDumpEndpoint = threadDumpEndpoint;
42 | }
43 |
44 | public String threadDump(String arg) {
45 | return JsonUtils.asJson(threadDumpEndpoint.threadDump());
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/LiquibaseCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.command;
17 |
18 | import org.springframework.beans.factory.annotation.Value;
19 | import org.springframework.boot.actuate.liquibase.LiquibaseEndpoint;
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22 | import org.springframework.stereotype.Component;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 | import sshd.shell.springboot.util.JsonUtils;
25 |
26 | /**
27 | *
28 | * @author anand
29 | */
30 | @Component
31 | @ConditionalOnBean(LiquibaseEndpoint.class)
32 | @ConditionalOnProperty(name = "management.endpoint.liquibase.enabled", havingValue = "true", matchIfMissing = true)
33 | @SshdShellCommand(value = "liquibase", description = "Liquibase database migration details (if applicable)")
34 | public final class LiquibaseCommand extends AbstractSystemCommand {
35 |
36 | private final LiquibaseEndpoint liquibaseEndpoint;
37 |
38 | LiquibaseCommand(@Value("${sshd.system.command.roles.liquibase}") String[] systemRoles,
39 | LiquibaseEndpoint liquibaseEndpoint) {
40 | super(systemRoles);
41 | this.liquibaseEndpoint = liquibaseEndpoint;
42 | }
43 |
44 | public String liquibase(String arg) {
45 | return JsonUtils.asJson(liquibaseEndpoint.liquibaseBeans());
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/ShutdownCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.command;
17 |
18 | import org.springframework.beans.factory.annotation.Value;
19 | import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
20 | import org.springframework.boot.actuate.context.ShutdownEndpoint;
21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22 | import org.springframework.stereotype.Component;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 | import sshd.shell.springboot.util.JsonUtils;
25 |
26 | /**
27 | *
28 | * @author anand
29 | */
30 | @Component
31 | @ConditionalOnAvailableEndpoint(endpoint = ShutdownEndpoint.class)
32 | @ConditionalOnProperty(name = "management.endpoint.shutdown.enabled", havingValue = "true", matchIfMissing = false)
33 | @SshdShellCommand(value = "shutdown", description = "Shutdown application")
34 | public final class ShutdownCommand extends AbstractSystemCommand {
35 |
36 | private final ShutdownEndpoint shutdownEndpoint;
37 |
38 | ShutdownCommand(@Value("${sshd.system.command.roles.shutdown}") String[] systemRoles,
39 | ShutdownEndpoint shutdownEndpoint) {
40 | super(systemRoles);
41 | this.shutdownEndpoint = shutdownEndpoint;
42 | }
43 |
44 | public String shutdown(String arg) {
45 | return JsonUtils.asJson(shutdownEndpoint.shutdown());
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/ScheduledTasksCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.command;
17 |
18 | import org.springframework.beans.factory.annotation.Value;
19 | import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint;
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22 | import org.springframework.stereotype.Component;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 | import sshd.shell.springboot.util.JsonUtils;
25 |
26 | /**
27 | *
28 | * @author anand
29 | */
30 | @Component
31 | @ConditionalOnBean(ScheduledTasksEndpoint.class)
32 | @ConditionalOnProperty(name = "management.endpoint.scheduledtasks.enabled", havingValue = "true", matchIfMissing = true)
33 | @SshdShellCommand(value = "scheduledTasks", description = "Scheduled tasks")
34 | public final class ScheduledTasksCommand extends AbstractSystemCommand {
35 |
36 | private final ScheduledTasksEndpoint scheduledTasksEndpoint;
37 |
38 | ScheduledTasksCommand(@Value("${sshd.system.command.roles.scheduledTasks}") String[] systemRoles,
39 | ScheduledTasksEndpoint scheduledTasksEndpoint) {
40 | super(systemRoles);
41 | this.scheduledTasksEndpoint = scheduledTasksEndpoint;
42 | }
43 |
44 | public String scheduledTasks(String arg) {
45 | return JsonUtils.asJson(scheduledTasksEndpoint.scheduledTasks());
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/resources/config/application.properties:
--------------------------------------------------------------------------------
1 | # Copyright 2019 anand.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | sshd.system.command.roles=ADMIN
16 | sshd.system.command.roles.auditEvents=${sshd.system.command.roles}
17 | sshd.system.command.roles.beans=${sshd.system.command.roles}
18 | sshd.system.command.roles.caches=${sshd.system.command.roles}
19 | sshd.system.command.roles.conditionsReport=${sshd.system.command.roles}
20 | sshd.system.command.roles.configurationPropertiesReport=${sshd.system.command.roles}
21 | sshd.system.command.roles.environment=${sshd.system.command.roles}
22 | sshd.system.command.roles.health=${sshd.system.command.roles}
23 | sshd.system.command.roles.heapDump=${sshd.system.command.roles}
24 | sshd.system.command.roles.httpTrace=${sshd.system.command.roles}
25 | sshd.system.command.roles.info=${sshd.system.command.roles}
26 | sshd.system.command.roles.loggers=${sshd.system.command.roles}
27 | sshd.system.command.roles.mappings=${sshd.system.command.roles}
28 | sshd.system.command.roles.metrics=${sshd.system.command.roles}
29 | sshd.system.command.roles.scheduledTasks=${sshd.system.command.roles}
30 | sshd.system.command.roles.shutdown=${sshd.system.command.roles}
31 | sshd.system.command.roles.threadDump=${sshd.system.command.roles}
32 | sshd.system.command.roles.flyway=${sshd.system.command.roles}
33 | sshd.system.command.roles.integrationGraph=${sshd.system.command.roles}
34 | sshd.system.command.roles.liquibase=${sshd.system.command.roles}
35 | sshd.system.command.roles.sessions=${sshd.system.command.roles}
36 | sshd.system.command.roles.logfile=${sshd.system.command.roles}
37 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/test/java/sshd/shell/springboot/command/TestCommand.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package sshd.shell.springboot.command;
20 |
21 | import java.io.IOException;
22 | import org.springframework.stereotype.Component;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 | import sshd.shell.springboot.console.ConsoleIO;
25 |
26 | /**
27 | *
28 | * @author anand
29 | */
30 | @Component
31 | @SshdShellCommand(value = "test", description = "test description", roles = {"USER", "ADMIN"})
32 | public class TestCommand {
33 |
34 | @SshdShellCommand(value = "run", description = "test run", roles = "USER")
35 | public String run(String arg) {
36 | return "test run " + arg;
37 | }
38 |
39 | @SshdShellCommand(value = "execute", description = "test execute", roles = "ADMIN")
40 | public String execute(String arg) {
41 | return "test execute successful";
42 | }
43 |
44 | @SshdShellCommand(value = "interactive", description = "test interactive")
45 | public String interactive(String arg) throws IOException {
46 | String name = ConsoleIO.readInput("Name:");
47 | ConsoleIO.writeJsonOutput(new X(name));
48 | return "Hi " + name;
49 | }
50 |
51 | @lombok.AllArgsConstructor
52 | private static class X {
53 | public final String obj;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/ConditionsReportCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.command;
17 |
18 | import org.springframework.beans.factory.annotation.Value;
19 | import org.springframework.boot.actuate.autoconfigure.condition.ConditionsReportEndpoint;
20 | import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22 | import org.springframework.stereotype.Component;
23 | import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
24 | import sshd.shell.springboot.util.JsonUtils;
25 |
26 | /**
27 | *
28 | * @author anand
29 | */
30 | @Component
31 | @ConditionalOnAvailableEndpoint(endpoint = ConditionsReportEndpoint.class)
32 | @ConditionalOnProperty(name = "management.endpoint.conditions.enabled", havingValue = "true", matchIfMissing = true)
33 | @SshdShellCommand(value = "conditionsReport", description = "Conditions report")
34 | public final class ConditionsReportCommand extends AbstractSystemCommand {
35 |
36 | private final ConditionsReportEndpoint conditionsReportEndpoint;
37 |
38 | ConditionsReportCommand(@Value("${sshd.system.command.roles.conditionsReport}") String[] systemRoles,
39 | ConditionsReportEndpoint conditionsReportEndpoint) {
40 | super(systemRoles);
41 | this.conditionsReportEndpoint = conditionsReportEndpoint;
42 | }
43 |
44 | public String conditionsReport(String arg) {
45 | return JsonUtils.asJson(conditionsReportEndpoint.applicationConditionEvaluation());
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/command/CommandUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.command;
17 |
18 | import java.io.File;
19 | import java.io.IOException;
20 | import java.nio.file.Files;
21 | import java.nio.file.Path;
22 | import java.nio.file.Paths;
23 | import org.springframework.core.io.Resource;
24 | import sshd.shell.springboot.autoconfiguration.SshSessionContext;
25 | import sshd.shell.springboot.util.ZipUtils;
26 |
27 | /**
28 | *
29 | * @author anand
30 | */
31 | @lombok.extern.slf4j.Slf4j
32 | public enum CommandUtils {
33 | ;
34 |
35 | public static Path sessionUserPathContainingZippedResource(Resource resource) throws IOException {
36 | Path heapDumpFilePath = Paths.get(resource.getURI());
37 | return ZipUtils.zipFiles(sessionUserDir(), true, heapDumpFilePath);
38 | }
39 |
40 | private static Path sessionUserDir() throws IOException {
41 | File sessionUserDir = SshSessionContext.getUserDir();
42 | if (!sessionUserDir.exists()) {
43 | Files.createDirectories(sessionUserDir.toPath());
44 | }
45 | return sessionUserDir.toPath();
46 | }
47 |
48 | public static String process(JsonProcessor processor) {
49 | try {
50 | return processor.process();
51 | } catch (IOException | IllegalArgumentException ex) {
52 | log.warn("Invalid json", ex);
53 | return "Expected valid json as argument";
54 | }
55 | }
56 |
57 | @FunctionalInterface
58 | public static interface JsonProcessor {
59 |
60 | String process() throws IOException;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/autoconfiguration/SshSessionContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 anand.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sshd.shell.springboot.autoconfiguration;
17 |
18 | import java.io.File;
19 | import java.util.HashMap;
20 | import java.util.Map;
21 | import java.util.function.Supplier;
22 |
23 | /**
24 | *
25 | * @author anand
26 | */
27 | public enum SshSessionContext {
28 | ;
29 |
30 | private static final ThreadLocal> USER_DIR_CONTEXT = new ThreadLocal>();
31 | private static final ThreadLocal