Passed
Push — master ( 36028a...7de1b9 )
by Valentyn
13:31 queued 05:41
created

configure(AuthenticationManagerBuilder)   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
package com.osomapps.pt.config;
2
3
import org.springframework.beans.factory.annotation.Autowired;
4
import org.springframework.context.annotation.Bean;
5
import org.springframework.context.annotation.Configuration;
6
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
9
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
10
import org.springframework.security.core.userdetails.UserDetailsService;
11
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
12
import org.springframework.security.crypto.password.PasswordEncoder;
13
14
@EnableWebSecurity
15
@Configuration
16
class SecurityConfig extends WebSecurityConfigurerAdapter {
0 ignored issues
show
Obsolete introduced by
Remove this use of "WebSecurityConfigurerAdapter"; it is deprecated.
Loading history...
17
    @Autowired private UserDetailsService userDetailsService;
18
    @Autowired private CustomLoginSuccessHandler loginSuccessHandler;
19
    @Autowired private CustomLoginFailureHandler loginFailureHandler;
20
    @Autowired private CustomLogoutSuccessHandler logoutSuccessHandler;
21
    @Autowired private CustomAuthenticationEntryPoint authenticationEntryPoint;
22
23
    @Override
24
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
25
        auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
26
    }
27
28
    @Bean
29
    PasswordEncoder passwordEncoder() {
30
        return new BCryptPasswordEncoder();
31
    }
32
33
    @Override
34
    protected void configure(HttpSecurity http) throws Exception {
35
        http.csrf()
36
                .disable()
37
                .authorizeRequests()
38
                .antMatchers("/public/**")
39
                .permitAll()
40
                .antMatchers("/api/v1/admin/**", "/api/v1/auth/**")
41
                .fullyAuthenticated()
42
                .and()
43
                .formLogin()
44
                .loginPage("/login")
45
                .failureUrl("/login?error")
46
                .permitAll()
47
                .successHandler(loginSuccessHandler)
48
                .failureHandler(loginFailureHandler)
49
                .and()
50
                .logout()
51
                .permitAll()
52
                .logoutSuccessHandler(logoutSuccessHandler);
53
        http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint);
54
    }
55
}
56