@ -41,7 +41,7 @@ public class ShellProperties {
private String auth = "simple" ;
private String auth = "simple" ;
@Autowired ( required = false )
@Autowired ( required = false )
private AuthenticationProperties authenticationProperties = new SimpleAuthenticationProperties ( ) ;
private CrshShellProperties[ ] additionalProperties = new CrshShellProperties [ ] { new SimpleAuthenticationProperties ( ) } ;
private int commandRefreshInterval = - 1 ;
private int commandRefreshInterval = - 1 ;
@ -65,15 +65,13 @@ public class ShellProperties {
return this . auth ;
return this . auth ;
}
}
public void setAuthenticationProperties (
public void setAdditionalProperties ( CrshShellProperties [ ] additionalProperties ) {
AuthenticationProperties authenticationProperties ) {
Assert . notNull ( additionalProperties , "additionalProperties must not be null" ) ;
Assert . notNull ( authenticationProperties ,
this . additionalProperties = additionalProperties ;
"AuthenticationProperties must not be null" ) ;
this . authenticationProperties = authenticationProperties ;
}
}
public AuthenticationProperties getAuthentication Properties( ) {
public CrshShellProperties[ ] getAdditional Properties( ) {
return this . a uthentication Properties;
return this . a dditional Properties;
}
}
public void setCommandRefreshInterval ( int commandRefreshInterval ) {
public void setCommandRefreshInterval ( int commandRefreshInterval ) {
@ -123,16 +121,15 @@ public class ShellProperties {
* Return a properties file configured from these settings that can be applied to a
* Return a properties file configured from these settings that can be applied to a
* CRaSH shell instance .
* CRaSH shell instance .
* /
* /
public Properties asCr a shShellConfig( ) {
public Properties asCr shShellConfig( ) {
Properties properties = new Properties ( ) ;
Properties properties = new Properties ( ) ;
this . ssh . applyToCr a shShellConfig( properties ) ;
this . ssh . applyToCr shShellConfig( properties ) ;
this . telnet . applyToCr a shShellConfig( properties ) ;
this . telnet . applyToCr shShellConfig( properties ) ;
properties . put ( "crash.auth" , this . auth ) ;
properties . put ( "crash.auth" , this . auth ) ;
if ( this . authenticationProperties ! = null ) {
for ( CrshShellProperties shellProperties : this . additionalProperties ) {
this . authenticationProperties . applyToCra shShellConfig( properties ) ;
shellProperties . applyToCr shShellConfig( properties ) ;
}
}
if ( this . commandRefreshInterval > 0 ) {
if ( this . commandRefreshInterval > 0 ) {
properties . put ( "crash.vfs.refresh_period" ,
properties . put ( "crash.vfs.refresh_period" ,
String . valueOf ( this . commandRefreshInterval ) ) ;
String . valueOf ( this . commandRefreshInterval ) ) ;
@ -151,10 +148,22 @@ public class ShellProperties {
return properties ;
return properties ;
}
}
/ * *
* Base class for Auth specific properties .
* /
public static abstract class CrshShellProperties {
/ * *
* Apply the properties to a CRaSH configuration .
* /
protected abstract void applyToCrshShellConfig ( Properties config ) ;
}
/ * *
/ * *
* SSH properties
* SSH properties
* /
* /
public static class Ssh {
public static class Ssh extends CrshShellProperties {
private boolean enabled = true ;
private boolean enabled = true ;
@ -162,7 +171,8 @@ public class ShellProperties {
private String port = "2000" ;
private String port = "2000" ;
protected void applyToCrashShellConfig ( Properties config ) {
@Override
protected void applyToCrshShellConfig ( Properties config ) {
if ( this . enabled ) {
if ( this . enabled ) {
config . put ( "crash.ssh.port" , this . port ) ;
config . put ( "crash.ssh.port" , this . port ) ;
if ( this . keyPath ! = null ) {
if ( this . keyPath ! = null ) {
@ -180,12 +190,12 @@ public class ShellProperties {
}
}
public void setKeyPath ( String keyPath ) {
public void setKeyPath ( String keyPath ) {
Assert . hasText ( keyPath );
Assert . hasText ( keyPath , "keyPath must have text" );
this . keyPath = keyPath ;
this . keyPath = keyPath ;
}
}
public void setPort ( Integer port ) {
public void setPort ( Integer port ) {
Assert . notNull ( port );
Assert . notNull ( port , "port must not be null" );
this . port = port . toString ( ) ;
this . port = port . toString ( ) ;
}
}
@ -194,13 +204,14 @@ public class ShellProperties {
/ * *
/ * *
* Telnet properties
* Telnet properties
* /
* /
public static class Telnet {
public static class Telnet extends CrshShellProperties {
private boolean enabled = false ;
private boolean enabled = false ;
private String port = "5000" ;
private String port = "5000" ;
protected void applyToCrashShellConfig ( Properties config ) {
@Override
protected void applyToCrshShellConfig ( Properties config ) {
if ( this . enabled ) {
if ( this . enabled ) {
config . put ( "crash.telnet.port" , this . port ) ;
config . put ( "crash.telnet.port" , this . port ) ;
}
}
@ -215,39 +226,27 @@ public class ShellProperties {
}
}
public void setPort ( Integer port ) {
public void setPort ( Integer port ) {
Assert . notNull ( port );
Assert . notNull ( port , "port must not be null" );
this . port = port . toString ( ) ;
this . port = port . toString ( ) ;
}
}
}
}
/ * *
* Base class for Auth specific properties .
* /
public static abstract class AuthenticationProperties {
/ * *
* Apply the settings to a CRaSH configuration .
* /
protected abstract void applyToCrashShellConfig ( Properties config ) ;
}
/ * *
/ * *
* Auth specific properties for JAAS authentication
* Auth specific properties for JAAS authentication
* /
* /
@ConfigurationProperties ( name = "shell.auth.jaas" , ignoreUnknownFields = false )
@ConfigurationProperties ( name = "shell.auth.jaas" , ignoreUnknownFields = false )
public static class JaasAuthenticationProperties extends Authentication Properties {
public static class JaasAuthenticationProperties extends CrshShellProperties {
private String domain = "my-domain" ;
private String domain = "my-domain" ;
@Override
@Override
protected void applyToCr a shShellConfig( Properties config ) {
protected void applyToCrshShellConfig ( Properties config ) {
config . put ( "crash.auth.jaas.domain" , this . domain ) ;
config . put ( "crash.auth.jaas.domain" , this . domain ) ;
}
}
public void setDomain ( String domain ) {
public void setDomain ( String domain ) {
Assert . hasText ( domain );
Assert . hasText ( domain , "domain must have text" );
this . domain = domain ;
this . domain = domain ;
}
}
@ -257,19 +256,19 @@ public class ShellProperties {
* Auth specific properties for key authentication
* Auth specific properties for key authentication
* /
* /
@ConfigurationProperties ( name = "shell.auth.key" , ignoreUnknownFields = false )
@ConfigurationProperties ( name = "shell.auth.key" , ignoreUnknownFields = false )
public static class KeyAuthenticationProperties extends Authentication Properties {
public static class KeyAuthenticationProperties extends CrshShell Properties {
private String path ;
private String path ;
@Override
@Override
protected void applyToCr a shShellConfig( Properties config ) {
protected void applyToCr shShellConfig( Properties config ) {
if ( this . path ! = null ) {
if ( this . path ! = null ) {
config . put ( "crash.auth.key.path" , this . path ) ;
config . put ( "crash.auth.key.path" , this . path ) ;
}
}
}
}
public void setPath ( String path ) {
public void setPath ( String path ) {
Assert . hasText ( path );
Assert . hasText ( path , "path must have text" );
this . path = path ;
this . path = path ;
}
}
@ -279,7 +278,7 @@ public class ShellProperties {
* Auth specific properties for simple authentication
* Auth specific properties for simple authentication
* /
* /
@ConfigurationProperties ( name = "shell.auth.simple" , ignoreUnknownFields = false )
@ConfigurationProperties ( name = "shell.auth.simple" , ignoreUnknownFields = false )
public static class SimpleAuthenticationProperties extends Authentication Properties {
public static class SimpleAuthenticationProperties extends CrshShell Properties {
private static Log logger = LogFactory
private static Log logger = LogFactory
. getLog ( SimpleAuthenticationProperties . class ) ;
. getLog ( SimpleAuthenticationProperties . class ) ;
@ -291,7 +290,7 @@ public class ShellProperties {
private boolean defaultPassword = true ;
private boolean defaultPassword = true ;
@Override
@Override
protected void applyToCr a shShellConfig( Properties config ) {
protected void applyToCr shShellConfig( Properties config ) {
config . put ( "crash.auth.simple.username" , this . username ) ;
config . put ( "crash.auth.simple.username" , this . username ) ;
config . put ( "crash.auth.simple.password" , this . password ) ;
config . put ( "crash.auth.simple.password" , this . password ) ;
if ( this . defaultPassword ) {
if ( this . defaultPassword ) {
@ -305,7 +304,7 @@ public class ShellProperties {
}
}
public void setUsername ( String username ) {
public void setUsername ( String username ) {
Assert . hasLength ( username );
Assert . hasLength ( username , "username must have text" );
this . username = username ;
this . username = username ;
}
}
@ -324,12 +323,12 @@ public class ShellProperties {
* Auth specific properties for Spring authentication
* Auth specific properties for Spring authentication
* /
* /
@ConfigurationProperties ( name = "shell.auth.spring" , ignoreUnknownFields = false )
@ConfigurationProperties ( name = "shell.auth.spring" , ignoreUnknownFields = false )
public static class SpringAuthenticationProperties extends Authentication Properties {
public static class SpringAuthenticationProperties extends CrshShell Properties {
private String [ ] roles = new String [ ] { "ROLE_ADMIN" } ;
private String [ ] roles = new String [ ] { "ROLE_ADMIN" } ;
@Override
@Override
protected void applyToCr a shShellConfig( Properties config ) {
protected void applyToCr shShellConfig( Properties config ) {
if ( this . roles ! = null ) {
if ( this . roles ! = null ) {
config . put ( "crash.auth.spring.roles" ,
config . put ( "crash.auth.spring.roles" ,
StringUtils . arrayToCommaDelimitedString ( this . roles ) ) ;
StringUtils . arrayToCommaDelimitedString ( this . roles ) ) ;
@ -337,7 +336,9 @@ public class ShellProperties {
}
}
public void setRoles ( String [ ] roles ) {
public void setRoles ( String [ ] roles ) {
Assert . notNull ( roles ) ;
// 'roles' can be empty. This means no special to access right to connect to
// shell is required.
Assert . notNull ( roles , "roles must not be null" ) ;
this . roles = roles ;
this . roles = roles ;
}
}