feat: 升级SpringBoot和SpringCloud版本
This commit is contained in:
@@ -37,15 +37,14 @@
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-websocket</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
+6
-6
@@ -5,7 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
||||
import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer;
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
|
||||
@@ -52,10 +52,10 @@ public class DefaultResourceServerConf extends ResourceServerConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.AuthorizedUrl authorizedUrl = setHttp(http)
|
||||
.authorizeRequests()
|
||||
.antMatchers(securityProperties.getIgnore().getUrls()).permitAll()
|
||||
.antMatchers(HttpMethod.OPTIONS).permitAll()
|
||||
AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizedUrl authorizedUrl = setHttp(http)
|
||||
.authorizeHttpRequests()
|
||||
.requestMatchers(securityProperties.getIgnore().getUrls()).permitAll()
|
||||
.requestMatchers(HttpMethod.OPTIONS).permitAll()
|
||||
.anyRequest();
|
||||
setAuthenticate(authorizedUrl);
|
||||
|
||||
@@ -72,7 +72,7 @@ public class DefaultResourceServerConf extends ResourceServerConfigurerAdapter {
|
||||
* url权限控制,默认是认证就通过,可以重写实现个性化
|
||||
* @param authorizedUrl
|
||||
*/
|
||||
public HttpSecurity setAuthenticate(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.AuthorizedUrl authorizedUrl) {
|
||||
public HttpSecurity setAuthenticate(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizedUrl authorizedUrl) {
|
||||
return authorizedUrl.authenticated().and();
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -10,9 +10,8 @@ import org.springframework.security.oauth2.provider.expression.OAuth2WebSecurity
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@@ -47,7 +46,7 @@ public class DefaultSecurityHandlerConfig {
|
||||
return new OAuth2AccessDeniedHandler() {
|
||||
|
||||
@Override
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException authException) throws IOException, ServletException {
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException authException) throws IOException {
|
||||
ResponseUtil.responseFailed(objectMapper, response, authException.getMessage());
|
||||
}
|
||||
};
|
||||
|
||||
+1
-2
@@ -1,12 +1,11 @@
|
||||
package com.central.oauth2.common.config;
|
||||
|
||||
import com.central.oauth2.common.util.AuthUtils;
|
||||
import jakarta.websocket.server.ServerEndpointConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
/**
|
||||
* webSocket鉴权配置
|
||||
*
|
||||
|
||||
+2
@@ -4,6 +4,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
@@ -17,6 +18,7 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
@Getter
|
||||
@ConfigurationProperties(prefix = "zlt.security")
|
||||
@RefreshScope
|
||||
@Component
|
||||
public class SecurityProperties {
|
||||
private AuthProperties auth = new AuthProperties();
|
||||
|
||||
|
||||
+2
@@ -4,6 +4,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Token配置
|
||||
@@ -19,6 +20,7 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
@Getter
|
||||
@ConfigurationProperties(prefix = "zlt.oauth2.token.store")
|
||||
@RefreshScope
|
||||
@Component
|
||||
public class TokenStoreProperties {
|
||||
/**
|
||||
* token存储类型(redis/db/authJwt/resJwt)
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ import org.springframework.security.oauth2.common.exceptions.UnapprovedClientAut
|
||||
import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
||||
import org.springframework.security.oauth2.provider.token.TokenStore;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user