|
@@ -8,6 +8,7 @@ import cn.rankin.cmsweb.security.JwtAuthenticationTokenFilter;
|
|
|
import cn.rankin.cmsweb.security.JwtTokenService;
|
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
|
import cn.rankin.common.utils.util.HttpUtil;
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -37,7 +38,11 @@ import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuc
|
|
|
import org.springframework.security.web.authentication.session.SessionAuthenticationException;
|
|
|
import org.springframework.security.web.header.Header;
|
|
|
import org.springframework.security.web.header.HeaderWriter;
|
|
|
+import org.springframework.security.web.header.writers.DelegatingRequestMatcherHeaderWriter;
|
|
|
import org.springframework.security.web.session.SessionManagementFilter;
|
|
|
+import org.springframework.web.cors.CorsConfiguration;
|
|
|
+import org.springframework.web.cors.CorsConfigurationSource;
|
|
|
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
import javax.servlet.http.Cookie;
|
|
@@ -55,7 +60,7 @@ import java.util.List;
|
|
|
*/
|
|
|
@Configuration
|
|
|
@EnableWebSecurity
|
|
|
-@EnableGlobalMethodSecurity(prePostEnabled = false)//允许进入页面方法前检验
|
|
|
+@EnableGlobalMethodSecurity(prePostEnabled = true)//允许进入页面方法前检验
|
|
|
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
|
|
|
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
|
|
@@ -131,11 +136,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
*/
|
|
|
@Override
|
|
|
public void configure(WebSecurity web) throws Exception {
|
|
|
- HttpUtil.antMatchers(HttpMethod.OPTIONS, "/**");
|
|
|
+ HttpUtil.antMatchers(HttpMethod.OPTIONS);
|
|
|
HttpUtil.antMatchers(HttpMethod.GET, "/error", "/login/**", "/logout", "/favicon.ico");
|
|
|
- HttpUtil.antMatchers(HttpMethod.POST, "/file/**");
|
|
|
web.ignoring().requestMatchers(HttpUtil.getMatchersArray());
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -143,15 +146,14 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
|
|
|
// 禁用缓存
|
|
|
http.
|
|
|
- headers().cacheControl()
|
|
|
- .and().addHeaderWriter(new StaticHeadersWriter());
|
|
|
+ headers().cacheControl();
|
|
|
+// .and().addHeaderWriter(new StaticHeadersWriter());
|
|
|
|
|
|
http
|
|
|
// 分权限验证
|
|
|
-// .authorizeRequests()
|
|
|
-// .anyRequest().authenticated()
|
|
|
-// .and().csrf().disable()
|
|
|
- .csrf().disable()
|
|
|
+ .authorizeRequests()
|
|
|
+ .anyRequest().authenticated()
|
|
|
+ .and().csrf().disable()
|
|
|
.authorizeRequests().antMatchers("/login", "/logout", "/favicon.ico", "/error", "/file/**").permitAll()
|
|
|
.and().addFilterBefore(jwtAuthenticationTokenFilter, SessionManagementFilter.class);
|
|
|
|
|
@@ -270,8 +272,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
AuthenticationException authException) throws IOException {
|
|
|
//原生返回 response.sendError(HttpServletResponse.SC_UNAUTHORIZED,"Authentication Failed: " + authException.getMessage());
|
|
|
//cookie失效
|
|
|
- HttpUtil.error(request, response, CmsWebAPICode.ACCESS_DENIED);
|
|
|
+ HttpUtil.error(request, response, CmsWebAPICode.AUTHORIZED_FAILD);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|