@Test public void testBindingSimple() { SimpleAuthenticationProperties props = new SimpleAuthenticationProperties(); RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell.auth.simple"); binder.setConversionService(new DefaultConversionService()); Map<String, String> map = new HashMap<String, String>(); map.put("shell.auth.simple.user.name", "username123"); map.put("shell.auth.simple.user.password", "password123"); binder.bind(new MutablePropertyValues(map)); assertFalse(binder.getBindingResult().hasErrors()); Properties p = new Properties(); props.applyToCrshShellConfig(p); assertEquals("username123", p.get("crash.auth.simple.username")); assertEquals("password123", p.get("crash.auth.simple.password")); }
@Test public void testBindingSimple() { SimpleAuthenticationProperties props = load(SimpleAuthenticationProperties.class, "management.shell.auth.simple.user.name=username123", "management.shell.auth.simple.user.password=password123"); Properties p = new Properties(); props.applyToCrshShellConfig(p); assertThat(p.get("crash.auth.simple.username")).isEqualTo("username123"); assertThat(p.get("crash.auth.simple.password")).isEqualTo("password123"); }
@Test public void testDefaultPasswordAutoGeneratedIfUnresolvedPlaceholder() { SimpleAuthenticationProperties security = load( SimpleAuthenticationProperties.class, "management.shell.auth.simple.user.password=${ADMIN_PASSWORD}"); assertThat(security.getUser().isDefaultPassword()).isTrue(); }
@Test public void testDefaultPasswordAutoGeneratedIfEmpty() { SimpleAuthenticationProperties security = load( SimpleAuthenticationProperties.class, "management.shell.auth.simple.user.password="); assertThat(security.getUser().isDefaultPassword()).isTrue(); }
@Test public void testDefaultPasswordAutogeneratedIfUnresolovedPlaceholder() { SimpleAuthenticationProperties security = new SimpleAuthenticationProperties(); RelaxedDataBinder binder = new RelaxedDataBinder(security, "security"); binder.bind(new MutablePropertyValues(Collections .singletonMap("shell.auth.simple.user.password", "${ADMIN_PASSWORD}"))); assertFalse(binder.getBindingResult().hasErrors()); assertTrue(security.getUser().isDefaultPassword()); }
@Test public void testDefaultPasswordAutogeneratedIfEmpty() { SimpleAuthenticationProperties security = new SimpleAuthenticationProperties(); RelaxedDataBinder binder = new RelaxedDataBinder(security, "security"); binder.bind(new MutablePropertyValues( Collections.singletonMap("shell.auth.simple.user.password", ""))); assertFalse(binder.getBindingResult().hasErrors()); assertTrue(security.getUser().isDefaultPassword()); }
@Bean @ConditionalOnProperty(prefix = AUTH_PREFIX, name = "type", havingValue = "simple", matchIfMissing = true) @ConditionalOnMissingBean(CrshShellAuthenticationProperties.class) public SimpleAuthenticationProperties simpleAuthenticationProperties() { return new SimpleAuthenticationProperties(); }
@Bean @ConditionalOnProperty(prefix = "shell", name = "auth", havingValue = "simple", matchIfMissing = true) @ConditionalOnMissingBean(CrshShellAuthenticationProperties.class) public SimpleAuthenticationProperties simpleAuthenticationProperties() { return new SimpleAuthenticationProperties(); }