Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package be.pxl.s2it;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.http.HttpMethod;
- 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.web.cors.CorsConfiguration;
- import org.springframework.web.cors.CorsConfigurationSource;
- import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
- import javax.sql.DataSource;
- import java.util.Arrays;
- import java.util.Collections;
- @EnableWebSecurity
- //@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
- public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
- private Logger logger = LogManager.getLogger(getClass());
- @Autowired
- public void configureGlobalSecurity(AuthenticationManagerBuilder auth, DataSource ds) throws Exception {
- auth.jdbcAuthentication()
- .passwordEncoder(new BCryptPasswordEncoder())
- .dataSource(ds)
- .usersByUsernameQuery(
- "SELECT u.userId, u.password, u.enabled FROM s2it_user u where u.userId = ?")
- .authoritiesByUsernameQuery(
- "SELECT u.userId, a.role from s2it_user u where u.userId = ?");
- }
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http.csrf().disable()
- .cors()
- .and()
- .authorizeRequests()
- .antMatchers("/user/exist/**").permitAll()
- .antMatchers(HttpMethod.GET, "/auth").hasAnyRole("MERCHANT", "USER")
- .antMatchers("/free/**").permitAll()
- .anyRequest().authenticated()
- .and()
- .httpBasic()
- .and()
- .logout().logoutSuccessUrl("/logout")
- .and()
- .exceptionHandling().accessDeniedPage("/403");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement