https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/
import jakarta.servlet.ServletContext; | |
import jakarta.servlet.http.HttpServletRequest; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.core.env.Environment; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
@Bean | |
@ConditionalOnWebApplication | |
@ConditionalOnNotWarDeployment() | |
public CommandLineRunner clrNotInWar() { | |
return (args) -> { | |
System.out.println("Not running as war!"); | |
}; | |
} | |
static class OnWarDeployment extends NoneNestedConditions { |
@Component | |
public static class CPPP extends ConfigurationPropertiesBindingPostProcessor { | |
private ApplicationContext applicationContext; | |
@Override | |
public void setApplicationContext(ApplicationContext applicationContext) { | |
super.setApplicationContext(applicationContext); | |
this.applicationContext = applicationContext; | |
} |
System.out.println(genIndent(0, "\uD83C\uDFD8\uFE0F") + " Contexts"); | |
System.out.println(genIndent(1, "\uD83C\uDFE0") + " Context: " + contextName); | |
System.out.println(genIndent(2, "✅") + " Positive Matches: "); | |
System.out.println(genIndent(2, "⛔") + " Negative Matches (at least one did not match): " + contextName); | |
System.out.println(genIndent(3, "\uD83D\uDC4D") + " Condition Name: " + conditionName); | |
System.out.println(genIndent(4, " \uD83D\uDEC8") + " Message: " + messageAndConditionDescriptor.getMessage()); | |
🏘️ Contexts |
Springboot skips auto-configure the WebMvcAutoConfiguration, because it finds that there is org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration bean, and why did that bean instantiate because the user had @EnableWebMvc annotation on a @Configuration class. This is really screwed up.
WebMvcAutoConfiguration: Matched: - @ConditionalOnClass found required classes 'jakarta.servlet.Servlet', 'org.springframework.web.servlet.DispatcherServlet', 'org.springframework.web.servlet.config.annotation.WebMvcConfigurer' (OnClassCondition) - found 'session' scope (OnWebApplicationCondition) Did not match: - @ConditionalOnMissingBean (types: org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; SearchStrategy: all) found beans of type 'org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport' org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration (OnBeanCondition)
> spring help encodepassword
spring encodepassword - Encode a password for use with Spring Security
usage: spring encodepassword [options] <password to encode>
Option Description
------ -----------
-a, --algorithm <String> The algorithm to use (default: default)
package sandipchitale.twowaytlsserver; | |
import org.springframework.boot.autoconfigure.ssl.SslBundleRegistrar; | |
import org.springframework.boot.autoconfigure.web.ServerProperties; | |
import org.springframework.boot.ssl.SslBundle; | |
import org.springframework.boot.ssl.SslBundleRegistry; | |
import org.springframework.boot.ssl.SslBundles; | |
import org.springframework.boot.ssl.jks.JksSslStoreBundle; | |
import org.springframework.boot.ssl.jks.JksSslStoreDetails; |
@Bean | |
public CommandLineRunner clr() { | |
return args -> { | |
}; | |
} |
@Configuration | |
@EnableWebSecurity() | |
static class SecurityConfig { | |
public static class CustomAuthenticationProvider implements AuthenticationProvider { | |
private final String username; | |
private final String password; | |
private final String role; | |
CustomAuthenticationProvider(String username, String password, String role) { | |
this.username = username; |