Search in sources :

Example 31 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-boot by spring-projects.

the class SecurityPropertiesTests method testBindingIgnoredMultiValued.

@Test
public void testBindingIgnoredMultiValued() {
    this.binder.bind(new MutablePropertyValues(Collections.singletonMap("security.ignored", "/css/**,/images/**")));
    assertThat(this.binder.getBindingResult().hasErrors()).isFalse();
    assertThat(this.security.getIgnored()).hasSize(2);
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 32 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-boot by spring-projects.

the class SecurityPropertiesTests method testBindingIgnoredDisable.

@Test
public void testBindingIgnoredDisable() {
    this.binder.bind(new MutablePropertyValues(Collections.singletonMap("security.ignored", "none")));
    assertThat(this.binder.getBindingResult().hasErrors()).isFalse();
    assertThat(this.security.getIgnored()).hasSize(1);
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 33 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-boot by spring-projects.

the class SecurityPropertiesTests method testDefaultPasswordAutogeneratedIfEmpty.

@Test
public void testDefaultPasswordAutogeneratedIfEmpty() {
    this.binder.bind(new MutablePropertyValues(Collections.singletonMap("security.user.password", "")));
    assertThat(this.binder.getBindingResult().hasErrors()).isFalse();
    assertThat(this.security.getUser().isDefaultPassword()).isTrue();
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 34 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-boot by spring-projects.

the class SecurityPropertiesTests method testRole.

@Test
public void testRole() {
    this.binder.bind(new MutablePropertyValues(Collections.singletonMap("security.user.role", "ADMIN")));
    assertThat(this.binder.getBindingResult().hasErrors()).isFalse();
    assertThat(this.security.getUser().getRole().toString()).isEqualTo("[ADMIN]");
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 35 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-boot by spring-projects.

the class RelaxedDataBinder method getPropertyValuesForNamePrefix.

private MutablePropertyValues getPropertyValuesForNamePrefix(MutablePropertyValues propertyValues) {
    if (!StringUtils.hasText(this.namePrefix) && !this.ignoreNestedProperties) {
        return propertyValues;
    }
    MutablePropertyValues rtn = new MutablePropertyValues();
    for (PropertyValue value : propertyValues.getPropertyValues()) {
        String name = value.getName();
        for (String prefix : new RelaxedNames(stripLastDot(this.namePrefix))) {
            for (String separator : new String[] { ".", "_" }) {
                String candidate = (StringUtils.hasLength(prefix) ? prefix + separator : prefix);
                if (name.startsWith(candidate)) {
                    name = name.substring(candidate.length());
                    if (!(this.ignoreNestedProperties && name.contains("."))) {
                        PropertyOrigin propertyOrigin = OriginCapablePropertyValue.getOrigin(value);
                        rtn.addPropertyValue(new OriginCapablePropertyValue(name, value.getValue(), propertyOrigin));
                    }
                }
            }
        }
    }
    return rtn;
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) PropertyValue(org.springframework.beans.PropertyValue)

Aggregations

MutablePropertyValues (org.springframework.beans.MutablePropertyValues)305 Test (org.junit.Test)269 TestBean (org.springframework.tests.sample.beans.TestBean)86 ITestBean (org.springframework.tests.sample.beans.ITestBean)82 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)73 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)68 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)35 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)24 PropertyEditorSupport (java.beans.PropertyEditorSupport)23 PropertyValue (org.springframework.beans.PropertyValue)16 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)16 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)16 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)15 ScannedGenericBeanDefinition (org.springframework.context.annotation.ScannedGenericBeanDefinition)14 HashMap (java.util.HashMap)13 BeanWrapper (org.springframework.beans.BeanWrapper)12 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)11 ParseException (java.text.ParseException)9 RelaxedDataBinder (org.springframework.boot.bind.RelaxedDataBinder)9 BooleanTestBean (org.springframework.tests.sample.beans.BooleanTestBean)9