{"id":15019344,"url":"https://github.com/fonimus/ssh-shell-spring-boot","last_synced_at":"2025-02-26T15:11:28.554Z","repository":{"id":38271872,"uuid":"124578706","full_name":"fonimus/ssh-shell-spring-boot","owner":"fonimus","description":"Spring shell in spring boot application over ssh","archived":false,"fork":false,"pushed_at":"2024-08-28T04:20:52.000Z","size":982,"stargazers_count":78,"open_issues_count":17,"forks_count":25,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-19T14:09:20.070Z","etag":null,"topics":["spring-boot","spring-boot-starter","spring-boot2","spring-shell","springboot","springboot2","ssh"],"latest_commit_sha":null,"homepage":"https://github.com/fonimus/spring-boot-ssh-shell","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fonimus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-09T18:31:56.000Z","updated_at":"2025-02-18T15:30:54.000Z","dependencies_parsed_at":"2024-05-31T07:49:53.290Z","dependency_job_id":"51d97728-ec69-4cdd-a050-00b3488018d9","html_url":"https://github.com/fonimus/ssh-shell-spring-boot","commit_stats":{"total_commits":539,"total_committers":10,"mean_commits":53.9,"dds":0.4897959183673469,"last_synced_commit":"addf97b0a6c8294c6bbaa0b888298305387d8b4d"},"previous_names":["fonimus/spring-boot-ssh-shell"],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fonimus%2Fssh-shell-spring-boot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fonimus%2Fssh-shell-spring-boot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fonimus%2Fssh-shell-spring-boot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fonimus%2Fssh-shell-spring-boot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fonimus","download_url":"https://codeload.github.com/fonimus/ssh-shell-spring-boot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240876861,"owners_count":19871903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["spring-boot","spring-boot-starter","spring-boot2","spring-shell","springboot","springboot2","ssh"],"created_at":"2024-09-24T19:53:21.872Z","updated_at":"2025-02-26T15:11:28.532Z","avatar_url":"https://github.com/fonimus.png","language":"Java","readme":"# Spring Boot Ssh Shell\n\n[![Build Status](https://github.com/fonimus/ssh-shell-spring-boot/actions/workflows/build.yml/badge.svg)](https://github.com/fonimus/ssh-shell-spring-boot/actions/workflows/build.yml)\n[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=fonimus_ssh-shell-spring-boot\u0026metric=sqale_rating)](https://sonarcloud.io/dashboard?id=fonimus_ssh-shell-spring-boot)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=fonimus_ssh-shell-spring-boot\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=fonimus_ssh-shell-spring-boot)\n[![Maven Central](https://img.shields.io/maven-central/v/com.github.fonimus/ssh-shell-spring-boot-starter.svg?label=maven%20central)](https://search.maven.org/search?q=g:%22com.github.fonimus%22%20AND%20a:%22ssh-shell-spring-boot-starter%22)\n\n\u003e Spring shell in spring boot application over ssh\n\nFor more information please\nvisit `spring shell` [website](https://docs.spring.io/spring-shell/docs/3.0.3/docs/index.html).\n\n* [Getting started](#getting-started)\n* [Commands](#commands)\n* [Post processors](#post-processors)\n* [Parameter providers](#parameter-providers)\n* [Custom authentication](#custom-authentication)\n* [Command helper](#command-helper)\n* [Banner](#banner)\n* [Listeners](#listeners)\n* [Session Manager](#session-manager)\n* [Tests](#tests)\n* [Samples](#samples)\n* [Release notes](#release-notes)\n\n## Getting started\n\n### Dependency\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.fonimus\u003c/groupId\u003e\n    \u003cartifactId\u003essh-shell-spring-boot-starter\u003c/artifactId\u003e\n\u003c/dependency\u003e\n```\n\n_Warning :_ since version 2.0.0 (spring shell 2.1.0) interactive shell is\nenabled by default.\nYou can set property `spring.shell.interactive.enabled=false` to disable it.\n\n\u003e **Note:** auto configuration `SshShellAutoConfiguration` (active by default)\n\u003e can be deactivated by property\n\u003e **ssh.shell.enable=false**.\n\nIt means that the ssh server won't start and the commands won't be scanned.\nUnfortunately the application will still\nload the `spring-shell` auto configuration classes and display a shell at\nstartup (shell:\u003e). You can disable them with\nfollowing property:\n\n```yaml\nspring:\n  autoconfigure:\n    exclude:\n      - org.springframework.shell.boot.ExitCodeAutoConfiguration\n      - org.springframework.shell.boot.ShellContextAutoConfiguration\n      - org.springframework.shell.boot.SpringShellAutoConfiguration\n      - org.springframework.shell.boot.ShellRunnerAutoConfiguration\n      - org.springframework.shell.boot.ApplicationRunnerAutoConfiguration\n      - org.springframework.shell.boot.CommandCatalogAutoConfiguration\n      - org.springframework.shell.boot.LineReaderAutoConfiguration\n      - org.springframework.shell.boot.CompleterAutoConfiguration\n      - org.springframework.shell.boot.UserConfigAutoConfiguration\n      - org.springframework.shell.boot.JLineAutoConfiguration\n      - org.springframework.shell.boot.JLineShellAutoConfiguration\n      - org.springframework.shell.boot.ParameterResolverAutoConfiguration\n      - org.springframework.shell.boot.StandardAPIAutoConfiguration\n      - org.springframework.shell.boot.ThemingAutoConfiguration\n      - org.springframework.shell.boot.StandardCommandsAutoConfiguration\n      - org.springframework.shell.boot.ComponentFlowAutoConfiguration  \n```  \n\n### Configuration\n\nPlease check\nclass: [SshShellProperties.java](./starter/src/main/java/com/github/fonimus/ssh/shell/SshShellProperties.java)\nfor more\ninformation\n\n```yaml\nssh:\n  shell:\n    enable: true\n    # 'simple' or 'security'\n    authentication: simple\n    # if authentication set to 'security' the AuthenticationProvider bean name\n    # if not specified and only one AuthenticationProvider bean is present in the context, it will be used \n    auth-provider-bean-name:\n    # since 1.2.2, optional file containing authorized public keys (standard authorized_keys format, one key per line\n    # starting with 'ssh-rsa'), takes precedence over authentication (simple or not)\n    authorized-public-keys-file:\n    # since 1.5.5, optional spring resource containing authorized public keys (file:, classpath: , etc)\n    # note: in case of a non file resource, a temporary file is created with given content and deleted on process exit\n    # this is due to ssh external library which only accepts file in api\n    authorized-public-keys:\n    # for ssh helper 'confirm' method\n    confirmation-words:\n      - y\n      - yes\n    # since 1.4.0, set enable to false to disable following default commands\n    commands:\n      actuator:\n        create: true\n        enable: true\n        restricted: true\n        # empty by default\n        excludes:\n          - ...\n        authorized-roles:\n          - ACTUATOR\n      # since 1.4.0\n      jmx:\n        create: true\n        enable: true\n        restricted: true\n        authorized-roles:\n          - ADMIN\n      system:\n        create: true\n        enable: true\n        restricted: true\n        authorized-roles:\n          - ADMIN\n      # since 1.4.0\n      datasource:\n        create: true\n        enable: true\n        restricted: true\n        authorized-roles:\n          - ADMIN\n        excludes:\n          - datasource-update\n      postprocessors:\n        create: true\n        enable: true\n        restricted: false\n      # history and script added in 1.8.0\n      history:\n        create: true\n        enable: true\n        restricted: false\n      script:\n        create: true\n        enable: true\n        restricted: false\n      # since 1.3.0, command which allows you to list ssh sessions, and stop them\n      manage-sessions:\n        create: true\n        enable: false\n        restricted: true\n        authorized-roles:\n          - ADMIN\n      # since 1.5.0\n      tasks:\n        create: true\n        enable: false\n        restricted: true\n        authorized-roles:\n          - ADMIN\n    display-banner: true\n    history-file: \u003cjava.io.tmpdir\u003e/sshShellHistory.log\n    # since 1.3.0, set to false to have one file per user (\u003chistory-directory\u003e/sshShellHistory-\u003cuser\u003e.log)\n    shared-history: true\n    # since 1.3.0, only if shared-history is set to false\n    history-directory: \u003cjava.io.tmpdir\u003e\n    host: 127.0.0.1\n    host-key-file: \u003cjava.io.tmpdir\u003e/hostKey.ser\n    # displayed in log if generated\n    password:\n    port: 2222\n    user: user\n    prompt:\n      # in enum: com.github.fonimus.ssh.shell.PromptColor (black, red, green, yellow, blue, magenta, cyan, white, bright)\n      color: white\n      text: 'shell\u003e'\n```\n\n* Add `spring-boot-starter-actuator` dependency to get actuator commands\n\n* Add `spring-boot-starter-security` dependency to\n  configure `ssh.shell.authentication=security` with *\n  AuthenticationProvider*\n\n#### Default behavior\n\nSome commands are disabled by default, it can be the whole group (\nlike `manage-sessions`), or just\none sub command (like `datasource-update` in group `datasource`).\n\nTo enable a group, set the **enable** property to true :\n\n```yaml\nssh:\n  shell:\n    commands:\n      manage-sessions:\n        enable: true\n      datasource:\n        excludes:\n```\n\nTo un-exclude a sub command inside a group, set the **excludes** property to the\nnew wanted\narray. To include all sub commands, set new empty array :\n\n```yaml\nssh:\n  shell:\n    commands:\n      datasource:\n        excludes:\n```\n\n### Writing commands\n\nYou can write your command exactly the way you would do with `spring shell` (For\nmore information please\nvisit `spring shell` [website](https://docs.spring.io/spring-shell/docs/3.0.3/docs/index.html).\n\nInstead of using `org.springframework.shell.standard.ShellComponent` annotation,\nyou should\nuse `com.github.fonimus.ssh.shell.commands.SshShellComponent`:\nit is just a conditional `@ShellComponent` with `@ConditionalOnProperty` on\nproperty **ssh.shell.enable**\n\nExample:\n\n```java\nimport org.springframework.shell.standard.ShellCommandGroup;\nimport org.springframework.shell.standard.ShellMethod;\n\nimport com.github.fonimus.ssh.shell.commands.SshShellComponent;\n\n\n@SshShellComponent\n@ShellCommandGroup(\"Test Commands\")\npublic class TestCommands {\n\n    @ShellMethod(\"test command\")\n    public String test() {\n        return \"ok\";\n    }\n}\n``` \n\n## Commands\n\nAll commands group can be deactivated by enable property :\n\n```yaml\nssh:\n  shell:\n    commands:\n      \u003ccommand\u003e:\n        enable: true\n```\n\nSub commands in group can be also filtered by includes and excludes properties :\n\n```yaml\nssh:\n  shell:\n    commands:\n      \u003ccommand\u003e:\n        includes:\n          - xxx\n        excludes:\n          - xxx\n```\n\n### Actuator\n\nIf `org.springframework.boot:spring-boot-starter-actuator` dependency is\npresent, actuator commands\nwill be available.\n\nCommand availability is also bind to endpoint activation.\n\n```yaml\nmanagement:\n  endpoint:\n    audit:\n      enabled: false\n```\n\n### Tasks\n\nActivated by default if you have ``@EnableScheduling``,\nthese commands allow you to interact with spring boot scheduled tasks :\n\n* `tasks-list` : List scheduled tasks\n* `tasks-stop` : Stop one or all scheduled tasks or execution\n* `tasks-restart` : Restart one or all scheduled tasks\n* `tasks-single` : Launch one execution of all or specified task(s)\n\nNote: refresh parameter in `tasks-list` will remove single executions.\n\n#### Task scheduler\n\nBased on spring\ndocumentation ``org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.setScheduler``\nthe task scheduler used for scheduled tasks will be :\n\nIf not specified, it will look for unique bean of type ``TaskScheduler``, or\nwith name\n``taskScheduler``. Otherwise, a local single-threaded will be created.\n\nThe ``TasksCommand`` keep the same mechanism in order to be able to restart\nstopped scheduled tasks.\nIt also provides a ``setTaskScheduler()`` in case you want to specify custom\none.\n\n##### Examples\n\n| Context                                                                                                                                                    | Task scheduler used in TaskCommand                            |\n|------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|\n| No ``TaskScheduler`` bean in context                                                                                                                       | Local single-threaded                                         |\n| One ``TaskScheduler`` bean named **ts** in context                                                                                                         | **ts** bean                                                   |                                               |\n| Multiple ``TaskScheduler`` beans named **ts1**, **ts2** in context                                                                                         | Local single-threaded (could not find name **taskScheduler**) |                                               |\n| Multiple ``TaskScheduler`` beans named **taskScheduler**, **ts2**, **ts3** in context                                                                      | **taskScheduler** bean                                        |                                               |\n| Task scheduler specified in method ``SchedulingConfigurer#configureTasks``                                                                                 | Local single-threaded (not set in task)                       |\n| Task scheduler specified in method ``SchedulingConfigurer#configureTasks`` **AND** ``com.github.fonimus.ssh.shell.commands.TasksCommand.setTaskScheduler`` | Scheduler manually set                                        |\n\n### Jmx\n\n* `jmx-info`: Displays information about jmx mbean. Use -a option to query\n  attribute values.\n* `jmx-invoke`: Invoke operation on object name.\n* `jmx-list`: List jmx mbeans.\n\n### System\n\n* `system-env`: List system environment.\n* `system-properties`: List system properties.\n* `system-threads`: List jvm threads.\n\n### Datasource\n\n* `datasource-list`: List available datasources\n* `datasource-properties`: Datasource properties command. Executes 'show\n  variables'\n* `datasource-query`: Datasource query command.\n* `datasource-update`: Datasource update command.\n\n### Postprocessors\n\n* `postprocessors`: Display the available post processors\n\n## Post processors\n\n\u003e **Note: since 1.0.6**\n\nPost processors can be used with '|' (pipe character) followed by the name of\nthe post processor and the parameters.\nAlso, custom ones can be added.\n\n### Provided post processors\n\n#### Save\n\nThis specific post processor takes the key character '\u003e'.\n\nExample: ```echo test \u003e /path/to/file.txt```\n\n#### Pretty\n\nThis post processor, named `pretty` takes an object and apply jackson pretty\nwriter.\n\nExample: ```info | pretty```\n\n#### Json\n\nThis post processor, named `json` allows you to find a specific path within a\njson object.\n\nCaution: you need to have a json string. You can apply `pretty` post processor\nbefore to do so.\n\nExample: ```info | pretty | json /build/version```\n\n#### Grep\n\nThis post processor, named `grep` allows you to find specific patterns within a\nstring.\n\nExamples: ```info | grep boot```,```info | pretty | grep boot spring```\n\n#### Highlight\n\nThis post processor, named `highlight` allows you to highlight specific patterns\nwithin a string.\n\nExamples: ```info | highlight boot```,```info | pretty | highlight boot spring```\n\n### Custom\n\nTo register a new json result post processor, you need to implement\ninterface `PostProcessor`\n\nThen register it within a spring configuration.\n\nExample:\n\n````java\n\n@Configuration\nclass PostProcessorConfiguration {\n    @Bean\n    public PostProcessor quotePostProcessor() {\n        return new PostProcessor\u003cString\u003e() {\n\n            @Override\n            public String getName() {\n                return \"quote\";\n            }\n\n            @Override\n            public String process(String result, List parameters) {\n                return \"'\" + result + \"'\";\n            }\n        };\n    }\n}\n````\n\n## Parameter providers\n\n### Enum\n\nEnumeration option parameters have auto completion by default.\n\n### File\n\nThanks to [ExtendedFileValueProvider.java](\n./starter/src/main/java/com/github/fonimus/ssh/shell/providers\n/ExtendedFileValueProvider.java)\n(or FileValueProvider is deactivated), auto completion is available\nfor `java.io.File` option parameters.\n\n### Custom values\n\nTo enable auto completion for a parameter, declare a **valueProvider** class.\n\n\u003e **Note:** the value provider has to be in the spring context.\n\n````java\nclass Commands {\n    public command(@ShellOption(valueProvider = CustomValuesProvider.class) String message) {\n        // deal with message\n    }\n}\n\n@Component\nclass CustomValuesProvider implements ValueProvider {\n\n    private final static String[] VALUES = new String[]{\n            \"message1\", \"message2\", \"message3\"\n    };\n\n    @Override\n    public List\u003cCompletionProposal\u003e complete(CompletionContext completionContext) {\n        return Arrays.stream(VALUES).map(CompletionProposal::new).collect(Collectors.toList());\n    }\n}\n````\n\n## Custom authentication\n\nInstead of setting user and password (or using generated one), you can implement\nyour\nown `SshShellAuthenticationProvider`.\n\nAuto configuration will create default implementation only if there is not an\nexisting one in the spring context.\n\nExample:\n\n```java\nimport com.github.fonimus.ssh.shell.SshShellAuthenticationProvider;\n\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\n\n@Configuration\npublic class CustomPasswordConfiguration {\n\n    @Bean\n    public SshShellAuthenticationProvider sshShellAuthenticationProvider() {\n        return (user, pass, serverSession) -\u003e user.equals(pass);\n    }\n\n}\n```\n\n## Command helper\n\nA `com.github.fonimus.ssh.shell.SshShellHelper` bean is provided in context to\nhelp for additional functionalities.\n\nYou can either autowire it or inject it in a constructor:\n\n```java\nimport com.github.fonimus.ssh.shell.SshShellHelper;\n\n@SshShellComponent\npublic class DemoCommand {\n\n    @Autowired\n    private SshShellHelper helper;\n\n    // or\n\n    public DemoCommand(SshShellHelper helper) {\n        this.helper = helper;\n    }\n}\n```\n\n### User interaction\n\n#### Print output\n\n```java\n\n@SshShellComponent\npublic class DemoCommand {\n\n    @Autowired\n    private SshShellHelper helper;\n\n    @ShellMethod(\"Print command\")\n    public String print() {\n        boolean success = true;\n        helper.print(\"Some message\");\n        helper.print(\"Some black message\", PromptColor.BLACK);\n        helper.printSuccess(\"Some success message\");\n        return success ? helper.getSuccess(\"Some returned success message\") : helper.getColored(\"Some returned blue message\", PromptColor.BLUE);\n    }\n}\n```\n\n#### Read input\n\n```java\n\n@SshShellComponent\npublic class DemoCommand {\n\n    @Autowired\n    private SshShellHelper helper;\n\n    @ShellMethod(\"Welcome command\")\n    public String welcome() {\n        String name = helper.read(\"What's your name ?\");\n        return \"Hello, '\" + name + \"' !\";\n    }\n}\n```\n\n#### Confirmation\n\nUtil `confirm` method displays confirmation message and returns `true`\nif response equals ignore case confirmation words.\n\nDefault confirmation words are **[`y`, `yes`]**:\n\nYou can specify if it is case sensitive and provide your own confirmation words.\n\n```java\n\n@SshShellComponent\npublic class DemoCommand {\n\n    @Autowired\n    private SshShellHelper helper;\n\n    @ShellMethod(\"Confirmation command\")\n    public String conf() {\n        return helper.confirm(\"Are you sure ?\") ? \"Great ! Let's do it !\" : \"Such a shame ...\";\n    }\n}\n```\n\n#### Table\n\nA builder `com.github.fonimus.ssh.shell.SimpleTableBuilder` is available to\nquickly set up print table.\n\nQuick example:\n\n````java\nclass Commands {\n    public table() {\n        helper.renderTable(SimpleTable.builder()\n                .column(\"col1\")\n                .column(\"col2\")\n                .column(\"col3\")\n                .column(\"col4\")\n                .line(Arrays.asList(\"line1 col1\", \"line1 col2\", \"line1 col3\", \"line1 col4\"))\n                .line(Arrays.asList(\"line2 col1\", \"line2 col2\", \"line2 col3\", \"line2 col4\"))\n                .line(Arrays.asList(\"line3 col1\", \"line3 col2\", \"line3 col3\", \"line3 col4\"))\n                .line(Arrays.asList(\"line4 col1\", \"line4 col2\", \"line4 col3\", \"line4 col4\"))\n                .line(Arrays.asList(\"line5 col1\", \"line5 col2\", \"line5 col3\", \"line5 col4\"))\n                .line(Arrays.asList(\"line6 col1\", \"line6 col2\", \"line6 col3\", \"line6 col4\"))\n                .build());\n    }\n}\n\n````\n\nResult :\n\n````text\n┌──────────┬──────────┬──────────┬──────────┐\n│   col1   │   col2   │   col3   │   col4   │\n├──────────┼──────────┼──────────┼──────────┤\n│line1 col1│line1 col2│line1 col3│line1 col4│\n├──────────┼──────────┼──────────┼──────────┤\n│line2 col1│line2 col2│line2 col3│line2 col4│\n├──────────┼──────────┼──────────┼──────────┤\n│line3 col1│line3 col2│line3 col3│line3 col4│\n├──────────┼──────────┼──────────┼──────────┤\n│line4 col1│line4 col2│line4 col3│line4 col4│\n├──────────┼──────────┼──────────┼──────────┤\n│line5 col1│line5 col2│line5 col3│line5 col4│\n├──────────┼──────────┼──────────┼──────────┤\n│line6 col1│line6 col2│line6 col3│line6 col4│\n└──────────┴──────────┴──────────┴──────────┘\n````\n\n### Interactive\n\n\u003e **Note: since 1.1.3**\n\nThis method takes an interface to display lines at regular interval.\n\nEvery **refresh delay** (here 2\nseconds), `com.github.fonimus.ssh.shell.interactive.InteractiveInput.getLines`\nis\ncalled.\n\nThis can be used to display progress, monitoring, etc.\n\nThe interactive\nbuilder, [Interactive.java](./starter/src/main/java/com/github/fonimus/ssh/shell/interactive/Interactive.java)\nallows you to build your interactive command.\n\nThis builder can also take key bindings to make specific actions, whose can be\nmade by the following builder:\n[KeyBinding.java](./starter/src/main/java/com/github/fonimus/ssh/shell/interactive/KeyBinding.java).\n\n```java\n\n@SshShellComponent\npublic class DemoCommand {\n\n    @Autowired\n    private SshShellHelper helper;\n\n    @ShellMethod(\"Interactive command\")\n    public void interactive() {\n\n        KeyBinding binding = KeyBinding.builder()\n                .description(\"K binding example\")\n                .key(\"k\").input(() -\u003e LOGGER.info(\"In specific action triggered by key 'k' !\")).build();\n\n        Interactive interactive = Interactive.builder().input((size, currentDelay) -\u003e {\n            LOGGER.info(\"In interactive command for input...\");\n            List\u003cAttributedString\u003e lines = new ArrayList\u003c\u003e();\n            AttributedStringBuilder sb = new AttributedStringBuilder(size.getColumns());\n\n            sb.append(\"\\nCurrent time\", AttributedStyle.BOLD).append(\" : \");\n            sb.append(String.format(\"%8tT\", new Date()));\n\n            lines.add(sb.toAttributedString());\n\n            SecureRandom sr = new SecureRandom();\n            lines.add(new AttributedStringBuilder().append(helper.progress(sr.nextInt(100)),\n                    AttributedStyle.DEFAULT.foreground(sr.nextInt(6) + 1)).toAttributedString());\n            lines.add(AttributedString.fromAnsi(SshShellHelper.INTERACTIVE_LONG_MESSAGE + \"\\n\"));\n\n            return lines;\n        }).binding(binding).fullScreen(true | false).refreshDelay(5000).build();\n\n        helper.interactive(interactive);\n    }\n}\n```\n\nNote: existing key bindings are:\n\n* `q`: to quit interactive command and go back to shell\n* `+`: to increase refresh delay by 1000 milliseconds\n* `-`: to decrease refresh delay by 1000 milliseconds\n\n### Role check\n\nIf you are using *AuthenticationProvider* thanks to\nproperty `ssh.shell.authentication=security`, you can check that\nconnected user has right authorities for command.\nThe easiest way of doing it is thanks to `ShellMethodAvailability`\nfunctionality. Example:\n\n```java\n\n@SshShellComponent\npublic class DemoCommand {\n\n    @Autowired\n    private SshShellHelper helper;\n\n    @ShellMethod(\"Admin command\")\n    @ShellMethodAvailability(\"adminAvailability\")\n    public String admin() {\n        return \"Finally an administrator !!\";\n    }\n\n    public Availability adminAvailability() {\n        if (!helper.checkAuthorities(Collections.singletonList(\"ADMIN\"))) {\n            return Availability.unavailable(\"admin command is only for an admin users !\");\n        }\n        return Availability.available();\n    }\n}\n```\n\n### Retrieve spring security authentication\n\n```java\n\n@SshShellComponent\npublic class DemoCommand {\n\n    @Autowired\n    private SshShellHelper helper;\n\n    @ShellMethod(\"Authentication command\")\n    public SshAuthentication authentication() {\n        return helper.getAuthentication();\n    }\n}\n```\n\n## Banner\n\nIf a banner is found in spring context and `display-banner` is set to true,\nit will be used as welcome prompt message.\n\n## Listeners\n\nAn interface is provided in order to receive events on ssh\nsessions : ``com.github.fonimus.ssh.shell.listeners\n.SshShellListener``.\n\nImplement it and define a spring bean in order to receive events.\n\n_Example_\n\n````java\n\n@Configuration\nclass ShellListenerConfiguration {\n    @Bean\n    public SshShellListener sshShellListener() {\n        return event -\u003e LOGGER.info(\"[listener] event '{}' [id={}, ip={}]\",\n                event.getType(),\n                event.getSession().getServerSession().getIoSession().getId(),\n                event.getSession().getServerSession().getIoSession().getRemoteAddress());\n    }\n}\n````\n\n## Session Manager\n\n\u003e **Note: since 1.3.0**`\n\nA session manager bean is available and allows you to:\n\n* list active sessions\n* get information about one session\n* stop a session\n\n**Note: you need to use @Lazy injection if you are using it in a command**\n\n_Example_\n\n````java\nclass Commands {\n    public MyCommand(@Lazy SshShellSessionManager sessionManager) {\n        this.sessionManager = sessionManager;\n    }\n\n    @ShellMethod(\"My command\")\n    public String myCommand() {\n        sessionManager.listSessions();\n        //...\n    }\n}\n````\n\n### Manage sessions commands\n\nIf activated `ssh.shell.commands.manage-sessions.enable=true`, the following\ncommands are available :\n\n* `manage-sessions-info`: Displays information about single session\n* `manage-sessions-list`: Displays active sessions\n* `manage-sessions-stop`: Stop single specific session\n\n## Tests\n\nIt can be annoying to load ssh server during spring boot tests.\n`SshShellProperties` class provides constants to easily deactivate\nthe all ssh and spring shell auto configurations:\n\n```java\n\n@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, properties = {\"ssh.shell.port=2346\",\n        SshShellProperties.DISABLE_SSH_SHELL,\n        SshShellProperties.DISABLE_SPRING_SHELL_AUTO_CONFIG\n})\n@ExtendWith(SpringExtension.class)\npublic class ApplicationTest {\n}\n```\n\n## Samples\n\n* [Basic sample](./samples/basic), no actuator, no security, no sessions\n* [Complete sample](./samples/complete), with actuator, security dependencies and configurations\n\n## Release notes\n\nPlease check [github releases page](https://github.com/fonimus/ssh-shell-spring-boot/releases).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffonimus%2Fssh-shell-spring-boot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffonimus%2Fssh-shell-spring-boot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffonimus%2Fssh-shell-spring-boot/lists"}