Search in sources :

Example 11 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class TomcatWebServerFactoryCustomizer method customize.

@Override
public void customize(ConfigurableTomcatWebServerFactory factory) {
    ServerProperties properties = this.serverProperties;
    ServerProperties.Tomcat tomcatProperties = properties.getTomcat();
    PropertyMapper propertyMapper = PropertyMapper.get();
    propertyMapper.from(tomcatProperties::getBasedir).whenNonNull().to(factory::setBaseDirectory);
    propertyMapper.from(tomcatProperties::getBackgroundProcessorDelay).whenNonNull().as(Duration::getSeconds).as(Long::intValue).to(factory::setBackgroundProcessorDelay);
    customizeRemoteIpValve(factory);
    ServerProperties.Tomcat.Threads threadProperties = tomcatProperties.getThreads();
    propertyMapper.from(threadProperties::getMax).when(this::isPositive).to((maxThreads) -> customizeMaxThreads(factory, threadProperties.getMax()));
    propertyMapper.from(threadProperties::getMinSpare).when(this::isPositive).to((minSpareThreads) -> customizeMinThreads(factory, minSpareThreads));
    propertyMapper.from(this.serverProperties.getMaxHttpHeaderSize()).whenNonNull().asInt(DataSize::toBytes).when(this::isPositive).to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize));
    propertyMapper.from(tomcatProperties::getMaxSwallowSize).whenNonNull().asInt(DataSize::toBytes).to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize));
    propertyMapper.from(tomcatProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes).when((maxHttpFormPostSize) -> maxHttpFormPostSize != 0).to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
    propertyMapper.from(tomcatProperties::getAccesslog).when(ServerProperties.Tomcat.Accesslog::isEnabled).to((enabled) -> customizeAccessLog(factory));
    propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull().to(factory::setUriEncoding);
    propertyMapper.from(tomcatProperties::getConnectionTimeout).whenNonNull().to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
    propertyMapper.from(tomcatProperties::getMaxConnections).when(this::isPositive).to((maxConnections) -> customizeMaxConnections(factory, maxConnections));
    propertyMapper.from(tomcatProperties::getAcceptCount).when(this::isPositive).to((acceptCount) -> customizeAcceptCount(factory, acceptCount));
    propertyMapper.from(tomcatProperties::getProcessorCache).to((processorCache) -> customizeProcessorCache(factory, processorCache));
    propertyMapper.from(tomcatProperties::getKeepAliveTimeout).whenNonNull().to((keepAliveTimeout) -> customizeKeepAliveTimeout(factory, keepAliveTimeout));
    propertyMapper.from(tomcatProperties::getMaxKeepAliveRequests).to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests));
    propertyMapper.from(tomcatProperties::getRelaxedPathChars).as(this::joinCharacters).whenHasText().to((relaxedChars) -> customizeRelaxedPathChars(factory, relaxedChars));
    propertyMapper.from(tomcatProperties::getRelaxedQueryChars).as(this::joinCharacters).whenHasText().to((relaxedChars) -> customizeRelaxedQueryChars(factory, relaxedChars));
    propertyMapper.from(tomcatProperties::isRejectIllegalHeader).to((rejectIllegalHeader) -> customizeRejectIllegalHeader(factory, rejectIllegalHeader));
    customizeStaticResources(factory);
    customizeErrorReportValve(properties.getError(), factory);
}
Also used : IncludeAttribute(org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeAttribute) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) Ordered(org.springframework.core.Ordered) CloudPlatform(org.springframework.boot.cloud.CloudPlatform) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) Lifecycle(org.apache.catalina.Lifecycle) ErrorReportValve(org.apache.catalina.valves.ErrorReportValve) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) WebServerFactoryCustomizer(org.springframework.boot.web.server.WebServerFactoryCustomizer) Collectors(java.util.stream.Collectors) AccessLogValve(org.apache.catalina.valves.AccessLogValve) ErrorProperties(org.springframework.boot.autoconfigure.web.ErrorProperties) List(java.util.List) ProtocolHandler(org.apache.coyote.ProtocolHandler) Accesslog(org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Accesslog) Environment(org.springframework.core.env.Environment) Duration(java.time.Duration) Remoteip(org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Remoteip) ConfigurableTomcatWebServerFactory(org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory) AbstractProtocol(org.apache.coyote.AbstractProtocol) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) StringUtils(org.springframework.util.StringUtils) DataSize(org.springframework.util.unit.DataSize) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) DataSize(org.springframework.util.unit.DataSize) Duration(java.time.Duration) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 12 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class Saml2RelyingPartyRegistrationConfiguration method mapIdentityProvider.

private Consumer<AssertingPartyDetails.Builder> mapIdentityProvider(Registration properties, boolean usingMetadata) {
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    Saml2RelyingPartyProperties.Identityprovider identityprovider = properties.getIdentityprovider();
    return (details) -> {
        map.from(identityprovider::getEntityId).to(details::entityId);
        map.from(identityprovider.getSinglesignon()::getBinding).whenNonNull().to(details::singleSignOnServiceBinding);
        map.from(identityprovider.getSinglesignon()::getUrl).to(details::singleSignOnServiceLocation);
        map.from(identityprovider.getSinglesignon()::isSignRequest).when((signRequest) -> !usingMetadata).to(details::wantAuthnRequestsSigned);
    };
}
Also used : X509Certificate(java.security.cert.X509Certificate) Decryption(org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Decryption) CertificateFactory(java.security.cert.CertificateFactory) RelyingPartyRegistrationRepository(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository) RsaKeyConverters(org.springframework.security.converter.RsaKeyConverters) InMemoryRelyingPartyRegistrationRepository(org.springframework.security.saml2.provider.service.registration.InMemoryRelyingPartyRegistrationRepository) RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Map(java.util.Map) Signing(org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Registration.Signing) AssertingPartyDetails(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.AssertingPartyDetails) Resource(org.springframework.core.io.Resource) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Registration(org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Registration) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) Saml2X509Credential(org.springframework.security.saml2.core.Saml2X509Credential) Collectors(java.util.stream.Collectors) Saml2X509CredentialType(org.springframework.security.saml2.core.Saml2X509Credential.Saml2X509CredentialType) Consumer(java.util.function.Consumer) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) Builder(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.Builder) Bean(org.springframework.context.annotation.Bean) Verification(org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Identityprovider.Verification) Conditional(org.springframework.context.annotation.Conditional) RelyingPartyRegistrations(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrations) InputStream(java.io.InputStream) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 13 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class JettyWebServerFactoryCustomizer method customize.

@Override
public void customize(ConfigurableJettyWebServerFactory factory) {
    ServerProperties properties = this.serverProperties;
    ServerProperties.Jetty jettyProperties = properties.getJetty();
    factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders());
    ServerProperties.Jetty.Threads threadProperties = jettyProperties.getThreads();
    factory.setThreadPool(determineThreadPool(jettyProperties.getThreads()));
    PropertyMapper propertyMapper = PropertyMapper.get();
    propertyMapper.from(threadProperties::getAcceptors).whenNonNull().to(factory::setAcceptors);
    propertyMapper.from(threadProperties::getSelectors).whenNonNull().to(factory::setSelectors);
    propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull().asInt(DataSize::toBytes).when(this::isPositive).to((maxHttpHeaderSize) -> factory.addServerCustomizers(new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize)));
    propertyMapper.from(jettyProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes).when(this::isPositive).to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
    propertyMapper.from(jettyProperties::getConnectionIdleTimeout).whenNonNull().to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
    propertyMapper.from(jettyProperties::getAccesslog).when(ServerProperties.Jetty.Accesslog::isEnabled).to((accesslog) -> customizeAccessLog(factory, accesslog));
}
Also used : ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) DataSize(org.springframework.util.unit.DataSize) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 14 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class RestDocsMockMvcBuilderCustomizer method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    PropertyMapper map = PropertyMapper.get();
    RestDocsProperties properties = this.properties;
    UriConfigurer uri = this.delegate.uris();
    map.from(properties::getUriScheme).whenHasText().to(uri::withScheme);
    map.from(properties::getUriHost).whenHasText().to(uri::withHost);
    map.from(properties::getUriPort).whenNonNull().to(uri::withPort);
}
Also used : UriConfigurer(org.springframework.restdocs.mockmvc.UriConfigurer) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 15 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class WebServiceTemplateBuilder method configure.

/**
 * Configure the provided {@link WebServiceTemplate} instance using this builder.
 * @param <T> the type of web service template
 * @param webServiceTemplate the {@link WebServiceTemplate} to configure
 * @return the web service template instance
 * @see #build()
 * @see #build(Class)
 */
public <T extends WebServiceTemplate> T configure(T webServiceTemplate) {
    Assert.notNull(webServiceTemplate, "WebServiceTemplate must not be null");
    configureMessageSenders(webServiceTemplate);
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    applyCustomizers(webServiceTemplate, this.internalCustomizers);
    map.from(this.marshaller).to(webServiceTemplate::setMarshaller);
    map.from(this.unmarshaller).to(webServiceTemplate::setUnmarshaller);
    map.from(this.destinationProvider).to(webServiceTemplate::setDestinationProvider);
    map.from(this.transformerFactoryClass).to(webServiceTemplate::setTransformerFactoryClass);
    map.from(this.messageFactory).to(webServiceTemplate::setMessageFactory);
    if (!CollectionUtils.isEmpty(this.interceptors)) {
        Set<ClientInterceptor> merged = new LinkedHashSet<>(this.interceptors);
        if (webServiceTemplate.getInterceptors() != null) {
            merged.addAll(Arrays.asList(webServiceTemplate.getInterceptors()));
        }
        webServiceTemplate.setInterceptors(merged.toArray(new ClientInterceptor[0]));
    }
    applyCustomizers(webServiceTemplate, this.customizers);
    return webServiceTemplate;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ClientInterceptor(org.springframework.ws.client.support.interceptor.ClientInterceptor) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Aggregations

PropertyMapper (org.springframework.boot.context.properties.PropertyMapper)49 Bean (org.springframework.context.annotation.Bean)9 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)8 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)4 DataSize (org.springframework.util.unit.DataSize)4 Duration (java.time.Duration)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 IOException (java.io.IOException)2 Map (java.util.Map)2 AccessLogValve (org.apache.catalina.valves.AccessLogValve)2 AutoConfiguration (org.springframework.boot.autoconfigure.AutoConfiguration)2 EnableAutoConfiguration (org.springframework.boot.autoconfigure.EnableAutoConfiguration)2 Connection (org.springframework.boot.autoconfigure.cassandra.CassandraProperties.Connection)2 Controlconnection (org.springframework.boot.autoconfigure.cassandra.CassandraProperties.Controlconnection)2 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)2 Listener (org.springframework.boot.autoconfigure.kafka.KafkaProperties.Listener)2 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)2 ConsumerAwareRebalanceListener (org.springframework.kafka.listener.ConsumerAwareRebalanceListener)2 StringUtils (org.springframework.util.StringUtils)2