Spring Boot 2.0.0 + OAuth2

Spring Security 5 uses a modernized password storage, see OAuth2 Autoconfig: If you use your own authorization server configuration to configure the list of valid clients through an instance of ClientDetailsServiceConfigurer as shown below, take note that the passwords you configure here are subject to the modernized password storage that came with Spring Security 5. … Read more

Multi-tenancy: Managing multiple datasources with Spring Data JPA

To implement multi-tenancy with Spring Boot we can use AbstractRoutingDataSource as base DataSource class for all ‘tenant databases‘. It has one abstract method determineCurrentLookupKey that we have to override. It tells the AbstractRoutingDataSource which of the tenant datasource it has to provide at the moment to work with. Because it works in the multi-threading environment, … Read more

Certificate for doesn’t match any of the subject alternative names

You need to provide localhost as a subject alternative name when creating your certificate. You can do that by provide the following additional parameter: -ext “SAN:c=DNS:localhost,IP:127.0.0.1” So something like this: keytool -genkeypair -keyalg RSA -keysize 2048 -alias stackoverflow \ -dname “CN=stackoverflow,OU=Hakan,O=Hakan,C=NL” \ -ext “SAN:c=DNS:localhost,IP:127.0.0.1” -validity 3650 \ -storepass <password> -keypass <password> \ -keystore identity.jks -deststoretype … Read more

Spring boot – configure EntityManager

With Spring Boot its not necessary to have any config file like persistence.xml. You can configure with annotations Just configure your DB config for JPA in the application.properties spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver spring.datasource.url=jdbc:oracle:thin:@DB… spring.datasource.username=username spring.datasource.password=pass spring.jpa.database-platform=org.hibernate.dialect…. spring.jpa.show-sql=true Then you can use CrudRepository provided by Spring where you have standard CRUD transaction methods. There you can also implement your … Read more

Spring Security: Upgrading the deprecated WebSecurityConfigurerAdapter in Spring Boot 2.7.0

I have managed to update the methods. This is the WebSecurityConfig class, and the methods are modified in the following way: public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception { authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); } has become: @Bean public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception { return authenticationConfiguration.getAuthenticationManager(); } Explanation: In the old version you inject AuthenticationManagerBuilder, set userDetailsService, passwordEncoder and … Read more

How to access in memory h2 database of one spring boot application from another spring boot application

You can setup H2 Server as Spring Bean. First edit pom.xml – delete <scope>runtime</scope> from h2 dependency: <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> Then add H2 server bean to SpringBootApplication or Configuration class: @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } /** * Start internal H2 server so we can query … Read more

How to log request and response bodies in Spring WebFlux

This is more or less similar to the situation in Spring MVC. In Spring MVC, you can use a AbstractRequestLoggingFilter filter and ContentCachingRequestWrapper and/or ContentCachingResponseWrapper. Many tradeoffs here: if you’d like to access servlet request attributes, you need to actually read and parse the request body logging the request body means buffering the request body, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)