2020-01-31 08:59:12 +00:00
|
|
|
package com.codesdream.ase.configure;
|
|
|
|
|
2020-02-04 17:31:14 +00:00
|
|
|
import com.codesdream.ase.component.ASEPasswordEncoder;
|
|
|
|
import com.codesdream.ase.service.ASEUserDetailsService;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2020-01-31 08:59:12 +00:00
|
|
|
import org.springframework.context.annotation.Configuration;
|
2020-02-04 17:31:14 +00:00
|
|
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
2020-01-31 08:59:12 +00:00
|
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
2020-02-04 17:31:14 +00:00
|
|
|
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
2020-01-31 08:59:12 +00:00
|
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
|
|
2020-02-04 17:31:14 +00:00
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Spring Security 配置类
|
|
|
|
* 用于Spring Security相关参数的配置
|
|
|
|
*/
|
2020-01-31 08:59:12 +00:00
|
|
|
@Configuration
|
|
|
|
@EnableWebSecurity
|
|
|
|
public class CustomWebSecurityConfig extends WebSecurityConfigurerAdapter {
|
2020-02-04 17:31:14 +00:00
|
|
|
|
2020-02-14 07:59:40 +00:00
|
|
|
@Resource
|
2020-02-04 17:31:14 +00:00
|
|
|
ASEUserDetailsService aseUserDetailService;
|
|
|
|
|
2020-02-14 07:59:40 +00:00
|
|
|
@Resource
|
2020-02-04 17:31:14 +00:00
|
|
|
ASEPasswordEncoder asePasswordEncoder;
|
|
|
|
|
2020-01-31 08:59:12 +00:00
|
|
|
@Override
|
|
|
|
protected void configure(HttpSecurity http) throws Exception {
|
2020-02-04 17:31:14 +00:00
|
|
|
http.authorizeRequests()
|
2020-01-31 08:59:12 +00:00
|
|
|
.anyRequest().authenticated()
|
|
|
|
.and()
|
2020-02-04 17:31:14 +00:00
|
|
|
.csrf().disable().formLogin()
|
|
|
|
.and()
|
2020-02-14 07:59:40 +00:00
|
|
|
.formLogin().loginPage("/login")
|
|
|
|
.permitAll().defaultSuccessUrl("/").permitAll()
|
2020-02-04 17:31:14 +00:00
|
|
|
.and()
|
|
|
|
.logout().permitAll();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
2020-02-14 07:59:40 +00:00
|
|
|
auth.userDetailsService(aseUserDetailService)
|
|
|
|
.passwordEncoder(asePasswordEncoder);
|
2020-02-04 17:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void configure(WebSecurity web) throws Exception {
|
|
|
|
web
|
|
|
|
.ignoring()
|
2020-02-14 07:59:40 +00:00
|
|
|
.antMatchers("/assets/**", "/register/**", "/forget/**", "/not_found/**");
|
2020-01-31 08:59:12 +00:00
|
|
|
}
|
|
|
|
}
|