Ignore:
Timestamp:
12/19/21 19:39:00 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
bdd6491
Parents:
1ad8e64
Message:

spring security 2.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner/src/main/java/finki/diplomska/tripplanner/security/SecurityConfig.java

    r1ad8e64 r84d0fbb  
    22
    33
     4import finki.diplomska.tripplanner.service.impl.CustomUserDetailsServiceImpl;
    45import org.springframework.beans.factory.annotation.Autowired;
     6import org.springframework.context.annotation.Bean;
    57import org.springframework.context.annotation.Configuration;
     8import org.springframework.security.authentication.AuthenticationManager;
     9import org.springframework.security.config.BeanIds;
     10import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
    611import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
    712import org.springframework.security.config.annotation.web.builders.HttpSecurity;
     
    914import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
    1015import org.springframework.security.config.http.SessionCreationPolicy;
     16import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
     17import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
     18
     19import static finki.diplomska.tripplanner.security.SecurityConstants.MARIADB_URL;
     20import static finki.diplomska.tripplanner.security.SecurityConstants.SIGN_UP_URLS;
    1121
    1222@Configuration
     
    2131    @Autowired
    2232    private JwtAuthenticationEntryPoint unauthorizedHandler;
     33
     34    @Autowired
     35    private CustomUserDetailsServiceImpl customUserDetailsService;
     36
     37    @Bean
     38    public JwtAuthenticationFilter jwtAuthenticationFilter() {return  new JwtAuthenticationFilter();}
     39
     40
     41    @Autowired
     42    private BCryptPasswordEncoder bCryptPasswordEncoder;
     43
     44    @Override
     45    protected void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
     46        authenticationManagerBuilder.userDetailsService(customUserDetailsService).passwordEncoder(bCryptPasswordEncoder);
     47    }
     48
     49    @Override
     50    @Bean(BeanIds.AUTHENTICATION_MANAGER)
     51    protected AuthenticationManager authenticationManager() throws Exception {
     52        return super.authenticationManager();
     53    }
    2354
    2455    @Override
     
    4374                        "/**/*.js"
    4475                ).permitAll()
    45                 .antMatchers("/api/users/**").permitAll()
     76                .antMatchers(SIGN_UP_URLS).permitAll()
     77                .antMatchers(MARIADB_URL).permitAll()
    4678                .anyRequest().authenticated();
     79        http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
     80
    4781    }
    4882}
Note: See TracChangeset for help on using the changeset viewer.