You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.7 KiB
65 lines
2.7 KiB
package com.kob.backend.config; |
|
|
|
|
|
|
|
import com.kob.backend.config.filter.JwtAuthenticationTokenFilter; |
|
import org.springframework.beans.factory.annotation.Autowired; |
|
import org.springframework.context.annotation.Bean; |
|
import org.springframework.context.annotation.Configuration; |
|
import org.springframework.http.HttpMethod; |
|
import org.springframework.security.authentication.AuthenticationManager; |
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
|
import org.springframework.security.config.annotation.web.builders.WebSecurity; |
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
|
import org.springframework.security.config.http.SessionCreationPolicy; |
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
|
import org.springframework.security.crypto.password.PasswordEncoder; |
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; |
|
|
|
/** |
|
* @author zfp |
|
*/ |
|
@Configuration |
|
@EnableWebSecurity |
|
public class SecurityConfig extends WebSecurityConfigurerAdapter { |
|
@Autowired |
|
private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter; |
|
|
|
@Bean |
|
public PasswordEncoder passwordEncoder() { |
|
return new BCryptPasswordEncoder(); |
|
} |
|
|
|
@Bean |
|
@Override |
|
public AuthenticationManager authenticationManagerBean() throws Exception { |
|
return super.authenticationManagerBean(); |
|
} |
|
|
|
@Override |
|
protected void configure(HttpSecurity http) throws Exception { |
|
http.csrf().disable() |
|
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) |
|
.and() |
|
.authorizeRequests() |
|
.antMatchers("/api/user/account/token/", |
|
"/api/user/account/register/", |
|
"/api/user/account/acwing/web/apply_code/", |
|
"/api/user/account/acwing/web/receive_code/", |
|
"/api/user/account/acwing/acapp/apply_code/", |
|
"/api/user/account/acwing/acapp/receive_code/").permitAll() |
|
.antMatchers("/pk/start/game/").hasIpAddress("127.0.0.1") |
|
.antMatchers("/pk/receive/bot/move/").hasIpAddress("127.0.0.1") |
|
.antMatchers(HttpMethod.OPTIONS).permitAll() |
|
.anyRequest().authenticated(); |
|
|
|
http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); |
|
} |
|
|
|
@Override |
|
public void configure(WebSecurity web) throws Exception { |
|
web.ignoring().antMatchers("/websocket/**"); |
|
} |
|
|
|
}
|
|
|