|
44 | 44 | import org.crsh.vfs.spi.FSDriver;
|
45 | 45 | import org.springframework.beans.factory.ListableBeanFactory;
|
46 | 46 | import org.springframework.beans.factory.annotation.Autowired;
|
| 47 | +import org.springframework.boot.actuate.properties.SecurityProperties; |
| 48 | +import org.springframework.boot.actuate.properties.SecurityProperties.Management; |
47 | 49 | import org.springframework.boot.actuate.properties.ShellProperties;
|
48 | 50 | import org.springframework.boot.actuate.properties.ShellProperties.CrshShellAuthenticationProperties;
|
| 51 | +import org.springframework.boot.actuate.properties.ShellProperties.CrshShellProperties; |
49 | 52 | import org.springframework.boot.actuate.properties.ShellProperties.JaasAuthenticationProperties;
|
50 | 53 | import org.springframework.boot.actuate.properties.ShellProperties.KeyAuthenticationProperties;
|
51 | 54 | import org.springframework.boot.actuate.properties.ShellProperties.SimpleAuthenticationProperties;
|
|
76 | 79 |
|
77 | 80 | /**
|
78 | 81 | * {@link EnableAutoConfiguration Auto-configuration} for embedding an extensible shell
|
79 |
| - * into a Spring Boot enabled application. By default a SSH daemon is started on port 2000 |
80 |
| - * with a default username <code>user</code> and password (default password is logged |
81 |
| - * during application startup). |
| 82 | + * into a Spring Boot enabled application. By default a SSH daemon is started on port |
| 83 | + * 2000. If the CRaSH Telnet plugin is available on the classpath, Telnet deamon will be |
| 84 | + * launched on port 5000. |
82 | 85 | *
|
83 | 86 | * <p>
|
84 |
| - * This configuration will auto detect the existence of a Spring Security |
85 |
| - * {@link AuthenticationManager} and will delegate authentication requests for shell |
86 |
| - * access to this detected instance if <code>shell.auth: spring</code> is set in the |
87 |
| - * application properties. |
| 87 | + * The default shell authentication method uses a username and password combination. If no |
| 88 | + * configuration is provided the default username is 'user' and the password will be |
| 89 | + * printed to console during application startup. Those default values can be overridden |
| 90 | + * by using <code>shell.auth.simple.username</code> and |
| 91 | + * <code>shell.auth.simple.password</code>. |
| 92 | + * |
| 93 | + * <p> |
| 94 | + * If a Spring Security {@link AuthenticationManager} is detected, this configuration will |
| 95 | + * create a {@link CRaSHPlugin} to forward shell authentication requests to Spring |
| 96 | + * Security. This authentication method will get enabled if <code>shell.auth</code> is set |
| 97 | + * to <code>spring</code> or if no explicit <code>shell.auth</code> is provided and a |
| 98 | + * {@link AuthenticationManager} is available. In the latter case shell access will be |
| 99 | + * restricted to users having roles that match those configured in {@link Management}. |
| 100 | + * Required roles can be overridden by <code>shell.auth.spring.roles</code>. |
88 | 101 | *
|
89 | 102 | * <p>
|
90 | 103 | * To add customizations to the shell simply define beans of type {@link CRaSHPlugin} in
|
91 | 104 | * the application context. Those beans will get auto detected during startup and
|
92 |
| - * registered with the underlying shell infrastructure. |
| 105 | + * registered with the underlying shell infrastructure. To configure plugins and the CRaSH |
| 106 | + * infrastructure add beans of type {@link CrshShellProperties} to the application |
| 107 | + * context. |
93 | 108 | *
|
94 | 109 | * <p>
|
95 | 110 | * Additional shell commands can be implemented using the guide and documentation at <a
|
|
99 | 114 | * <code>shell.command_path_patterns</code> in your application configuration.
|
100 | 115 | *
|
101 | 116 | * @author Christian Dupuis
|
| 117 | + * @see ShellProperties |
102 | 118 | */
|
103 | 119 | @Configuration
|
104 | 120 | @ConditionalOnClass({ PluginLifeCycle.class })
|
@@ -145,15 +161,36 @@ public PluginLifeCycle shellBootstrap() {
|
145 | 161 | return bootstrapBean;
|
146 | 162 | }
|
147 | 163 |
|
| 164 | + /** |
| 165 | + * Class to configure CRaSH to authenticate against Spring Security. |
| 166 | + */ |
148 | 167 | @Configuration
|
149 | 168 | @ConditionalOnBean({ AuthenticationManager.class })
|
| 169 | + @AutoConfigureAfter(CrshAutoConfiguration.class) |
150 | 170 | public static class AuthenticationManagerAdapterAutoConfiguration {
|
151 | 171 |
|
| 172 | + @Autowired(required = false) |
| 173 | + private SecurityProperties securityProperties; |
| 174 | + |
152 | 175 | @Bean
|
153 | 176 | public CRaSHPlugin<?> shellAuthenticationManager() {
|
154 | 177 | return new AuthenticationManagerAdapter();
|
155 | 178 | }
|
156 | 179 |
|
| 180 | + @Bean |
| 181 | + @ConditionalOnExpression("'${shell.auth:default_spring}' == 'default_spring'") |
| 182 | + @ConditionalOnMissingBean({ CrshShellAuthenticationProperties.class }) |
| 183 | + public CrshShellAuthenticationProperties springAuthenticationProperties() { |
| 184 | + // In case no shell.auth property is provided fall back to Spring Security |
| 185 | + // based authentication and get role to access shell from SecurityProperties. |
| 186 | + SpringAuthenticationProperties authenticationProperties = new SpringAuthenticationProperties(); |
| 187 | + if (this.securityProperties != null) { |
| 188 | + authenticationProperties.setRoles(new String[] { this.securityProperties |
| 189 | + .getManagement().getRole() }); |
| 190 | + } |
| 191 | + return authenticationProperties; |
| 192 | + } |
| 193 | + |
157 | 194 | }
|
158 | 195 |
|
159 | 196 | /**
|
@@ -238,7 +275,7 @@ private static class AuthenticationManagerAdapter extends
|
238 | 275 | @Autowired(required = false)
|
239 | 276 | private AccessDecisionManager accessDecisionManager;
|
240 | 277 |
|
241 |
| - private String[] roles = new String[] { "ROLE_ADMIN" }; |
| 278 | + private String[] roles = new String[] { "ADMIN" }; |
242 | 279 |
|
243 | 280 | @Override
|
244 | 281 | public boolean authenticate(String username, String password) throws Exception {
|
|
0 commit comments