Witam moja aplikacja jest zdeployowana na Heroku, który ma bardzo niski limit na ilość połączeń (20). Właśnie dlatego muszę uważnie patrzeć na każde otwarte połączenie. Z moim kodem ilość połączeń skacze z 0 do 10 po jedynie odświeżeniu strony. Dlaczego tak się dzieje? Oto mój kod:
package pl.jawegiel.springsecurityexample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import javax.sql.DataSource;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Override
public void configure(HttpSecurity http) throws Exception {
http
.cors().and().csrf().disable()
.authorizeRequests().antMatchers("/getUsersInfo")
.fullyAuthenticated().and().httpBasic();
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(new BCryptPasswordEncoder())
.usersByUsernameQuery("SELECT username, password, 'true' as enabled from users where username=?")
.authoritiesByUsernameQuery("SELECT username, role FROM users WHERE username=?");
}
}
w application.properties:
spring.datasource.url=...
spring.datasource.platform=postgres
spring.datasource.username=...
spring.datasource.password=...
oraz mój controller.java
@RestController
@CrossOrigin(origins = "*")
public class Controller {
@Autowired
private UserService userService;
@GetMapping("/")
public String abc() {
return "abc";
}
...
}
DAJE PUNKTY ZA SENSOWNE ODPOWIEDZI!