I finally notice that Spring boot integrate this apache option you should add Security dependencies for spring security after that you modify your application properties like this (it's also for https protocol) :
# Define a custom port instead of the default 8080
server.port=443
#Define http server
#http.port=8080
# Tell Spring Security (if used) to require requests over HTTPS
security.require-ssl=true
# The format used for the keystore
server.ssl.key-store-type=PKCS12
# The path to the keystore containing the certificate
server.ssl.key-store=classpath:keystore.p12
# The password used to generate the certificate
server.ssl.key-store-password=keycertifpass
# The alias mapped to the certificate
server.ssl.key-alias=tomcat
After that you add Basic authentication in a new class, this kind of authentication is the responsible for adding user and pass through URL :
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
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 org.springframework.security.crypto.password.PasswordEncoder;
import com.project.exception.CustomAuthenticationEntryPoint;
@Configuration
@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CustomAuthenticationEntryPoint unauthorizedHandler;
/** Use Basic Authentication **/
@Override
public void configure(HttpSecurity http) throws Exception
{
http.httpBasic().realmName("user").and().authorizeRequests()
.antMatchers("/**").hasRole("user")
.and()
.csrf().disable()
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler);
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception
{
auth.inMemoryAuthentication()
.withUser("user").password(passwordEncoder().encode("pass")).roles("user");
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
For me i have customized the Error Handling for authenticationEntryPoint you can add it if you want or leave it without customization, you are free.
I wish with this answer to help people who faced the same problem.
Thanks everyone.