Changeset f25d07e for phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/configs/WebSecurityConfig.java
- Timestamp:
- 09/07/22 00:51:50 (2 years ago)
- Branches:
- master
- Children:
- 527b93f
- Parents:
- dbd4834
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/configs/WebSecurityConfig.java
rdbd4834 rf25d07e 1 1 package finki.it.phoneluxbackend.security.configs; 2 2 3 import finki.it.phoneluxbackend.security.CustomAuthenticationFilter; 4 import finki.it.phoneluxbackend.security.CustomAuthorizationFilter; 3 5 import finki.it.phoneluxbackend.services.UserService; 4 6 import lombok.AllArgsConstructor; 7 import org.springframework.context.annotation.Bean; 5 8 import org.springframework.context.annotation.Configuration; 9 import org.springframework.security.authentication.AuthenticationManager; 6 10 import org.springframework.security.authentication.dao.DaoAuthenticationProvider; 7 import org.springframework.security.config.annotation.SecurityBuilder;8 11 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 9 import org.springframework.security.config.annotation.web.WebSecurityConfigurer;10 12 import org.springframework.security.config.annotation.web.builders.HttpSecurity; 11 13 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 12 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;13 14 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 14 import org.springframework.security.config. annotation.web.configuration.WebSecurityCustomizer;15 import org.springframework.security.config.http.SessionCreationPolicy; 15 16 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 16 import org.springframework.security.web.SecurityFilterChain; 17 import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 18 19 import static org.springframework.http.HttpMethod.GET; 17 20 18 21 @Configuration … … 26 29 @Override 27 30 protected void configure(HttpSecurity http) throws Exception { 28 http 29 .csrf().disable() 30 .authorizeRequests() 31 .antMatchers("/registration/**") 32 .permitAll() 33 .anyRequest() 34 .authenticated().and() 35 .formLogin(); 31 // http 32 // .csrf().disable() 33 // .authorizeRequests() 34 // .antMatchers("/registration/**") 35 // .permitAll() 36 // .anyRequest() 37 // .authenticated().and() 38 // .formLogin(); 39 40 http.csrf().disable(); 41 http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); 42 // http.authorizeRequests().antMatchers(GET,"/phones").hasAnyAuthority("USER"); 43 http.authorizeRequests().anyRequest().permitAll(); 44 http.addFilter(new CustomAuthenticationFilter(authenticationManagerBean())); 45 http.addFilterBefore(new CustomAuthorizationFilter(), UsernamePasswordAuthenticationFilter.class); 36 46 37 47 } … … 42 52 } 43 53 54 @Bean 55 @Override 56 public AuthenticationManager authenticationManagerBean() throws Exception { 57 return super.authenticationManagerBean(); 58 } 44 59 45 60 public DaoAuthenticationProvider daoAuthenticationProvider(){
Note:
See TracChangeset
for help on using the changeset viewer.