source: src/main/java/edu/gjoko/schedlr/config/AppSecurityConfig.java@ 46fd0c7

Last change on this file since 46fd0c7 was 46fd0c7, checked in by Gjoko Kostadinov <gjoko.kostadinov@…>, 16 months ago

Add admin page initial work.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1package edu.gjoko.schedlr.config;
2
3import edu.gjoko.schedlr.services.PostgresUserDetailsService;
4import org.springframework.context.annotation.Bean;
5import org.springframework.context.annotation.Configuration;
6import org.springframework.security.authentication.AuthenticationManager;
7import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
8import org.springframework.security.config.annotation.web.builders.HttpSecurity;
9import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
10import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
11import org.springframework.security.config.core.GrantedAuthorityDefaults;
12import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
13import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
14import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
15
16@Configuration
17@EnableWebSecurity
18public class AppSecurityConfig extends WebSecurityConfigurerAdapter {
19
20 private final PostgresUserDetailsService userDetailsService;
21
22 private final BCryptPasswordEncoder passwordEncoder;
23
24 private final AuthenticationSuccessHandler authenticationSuccessHandler;
25
26 public AppSecurityConfig(PostgresUserDetailsService userDetailsService, BCryptPasswordEncoder passwordEncoder,
27 AuthenticationSuccessHandler authenticationSuccessHandler) {
28 this.userDetailsService = userDetailsService;
29 this.passwordEncoder = passwordEncoder;
30 this.authenticationSuccessHandler = authenticationSuccessHandler;
31 }
32
33 @Bean
34 public AuthenticationManager customAuthenticationManager() throws Exception {
35 return authenticationManager();
36 }
37
38 @Override
39 protected void configure(AuthenticationManagerBuilder auth) throws Exception {
40 auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);
41 }
42
43 @Override
44 protected void configure(HttpSecurity http) throws Exception {
45 http.csrf()
46 .disable()
47 .httpBasic()
48 .authenticationEntryPoint(new AppAuthenticationEntryPoint())
49 .and()
50 .addFilterBefore(new AppFilter(), BasicAuthenticationFilter.class)
51 .formLogin()
52 .loginPage("/login")
53 .loginProcessingUrl("/login")
54 .successHandler(authenticationSuccessHandler)
55 .defaultSuccessUrl("/homepage")
56 .and()
57 .authorizeRequests()
58 .antMatchers("/login").permitAll()
59 .antMatchers("/register_customer").permitAll()
60 .antMatchers("/register_business").permitAll()
61 .antMatchers("/api/nomenclatures/*").permitAll()
62 .antMatchers("/api/business").permitAll()
63 .antMatchers("/homepage").permitAll()
64 .antMatchers("/css/**").permitAll()
65 .antMatchers("/js/**").permitAll()
66 .antMatchers("/anonymous*").anonymous()
67 .anyRequest()
68 .fullyAuthenticated();
69 }
70}
Note: See TracBrowser for help on using the repository browser.