am.ik.servicebroker.mysql.config.SecurityConfig Maven / Gradle / Ivy
package am.ik.servicebroker.mysql.config;
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
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.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final ServiceBrokerAdmin admin;
public SecurityConfig(ServiceBrokerAdmin admin) {
this.admin = admin;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ADMIN")
.mvcMatchers("/v2/**").hasRole("ADMIN")
.and()
.httpBasic()
.and()
.csrf().disable()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.NEVER);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(new InMemoryUserDetailsManager(this.admin.asUserDetails()))
.passwordEncoder(PasswordEncoderFactories.createDelegatingPasswordEncoder());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy