|
@@ -47,7 +47,11 @@ class WebSecurityConfig : WebSecurityConfigurerAdapter() {
|
|
|
@Bean
|
|
|
override fun userDetailsService(): UserDetailsService { //覆盖写userDetailsService方法 (1)
|
|
|
return UserDetailsService {
|
|
|
- val optional = userService.findByUsername(it)
|
|
|
+ var optional = userService.findByUsername(it)
|
|
|
+ if (optional.isPresent) {
|
|
|
+ return@UserDetailsService AuthUser(optional.get())
|
|
|
+ }
|
|
|
+ optional = userService.findByPhone(it)
|
|
|
if (optional.isPresent) {
|
|
|
return@UserDetailsService AuthUser(optional.get())
|
|
|
}
|
|
@@ -79,7 +83,11 @@ class WebSecurityConfig : WebSecurityConfigurerAdapter() {
|
|
|
|
|
|
@Bean
|
|
|
fun authenticationEntryPoint(): AuthenticationEntryPoint? {
|
|
|
- return AuthenticationEntryPoint { _: HttpServletRequest?, response: HttpServletResponse, _: AuthenticationException? -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED) }
|
|
|
+ return AuthenticationEntryPoint { _: HttpServletRequest?, response: HttpServletResponse, _: AuthenticationException? ->
|
|
|
+ response.sendError(
|
|
|
+ HttpServletResponse.SC_UNAUTHORIZED
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -115,10 +123,10 @@ class WebSecurityConfig : WebSecurityConfigurerAdapter() {
|
|
|
http.authorizeRequests().antMatchers("/login.html", loginPage).permitAll()
|
|
|
http.authorizeRequests().anyRequest().authenticated()
|
|
|
http.formLogin().loginPage(loginPage).successHandler(loginSuccessHandler())
|
|
|
- .authenticationDetailsSource(webAuthenticationDetailsSource())
|
|
|
+ .authenticationDetailsSource(webAuthenticationDetailsSource())
|
|
|
http.logout().logoutUrl(logoutUrl).logoutRequestMatcher(AntPathRequestMatcher(logoutUrl))
|
|
|
- .deleteCookies("JSESSIONID")
|
|
|
- .logoutSuccessHandler(logoutSuccessHandler())
|
|
|
+ .deleteCookies("JSESSIONID")
|
|
|
+ .logoutSuccessHandler(logoutSuccessHandler())
|
|
|
http.sessionManagement().invalidSessionUrl(loginPage)
|
|
|
|
|
|
http.exceptionHandling().defaultAuthenticationEntryPointFor(authenticationEntryPoint(), requestMatcher())
|
|
@@ -127,8 +135,10 @@ class WebSecurityConfig : WebSecurityConfigurerAdapter() {
|
|
|
|
|
|
override fun configure(web: WebSecurity) {
|
|
|
web.ignoring().antMatchers("/resources/**", "/static/**")
|
|
|
- web.ignoring().antMatchers("/**/*.js", "/lang/*.json", "/**/*.css", "/**/*.map", "/**/*.png",
|
|
|
- "/**/*.jpg", "/**/*.woff", "/**/*.ttf", "/*.ico")
|
|
|
+ web.ignoring().antMatchers(
|
|
|
+ "/**/*.js", "/lang/*.json", "/**/*.css", "/**/*.map", "/**/*.png",
|
|
|
+ "/**/*.jpg", "/**/*.woff", "/**/*.ttf", "/*.ico"
|
|
|
+ )
|
|
|
web.ignoring().antMatchers(*permitUrls)
|
|
|
web.ignoring().antMatchers("/doc.html")
|
|
|
web.ignoring().antMatchers("/open/**")
|