You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2024/05/10 03:01:07 UTC
(servicecomb-fence) 01/03: update to 3.x
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-fence.git
commit a74a437f7360f13fa0d44441bc9c3c3d28d87480
Author: liubao <bi...@qq.com>
AuthorDate: Wed May 8 11:28:21 2024 +0800
update to 3.x
---
authentication-server/pom.xml | 4 +-
.../fence/AuthenticationServerApplication.java | 2 -
.../AuthenticationConfiguration.java | 2 +-
.../fence/authentication/GithubOAuthService.java | 11 +++--
.../authentication/GithubOAuthServiceRegister.java | 39 +++++++++++++----
.../fence/authentication/GithubTokenGranter.java | 15 ++++---
.../fence/authentication/PasswordTokenGranter.java | 9 ++--
.../authentication/RefreshTokenTokenGranter.java | 9 ++--
.../fence/authentication/TokenEndpoint.java | 11 ++---
.../servicecomb/fence/EdgeServiceApplication.java | 2 -
.../apache/servicecomb/fence/edge/AuthHandler.java | 51 ++++++++++++++--------
.../fence/edge/AuthenticationFilter.java | 25 +++++++----
.../fence/edge/InternalAccessHandler.java | 31 +++++++++----
.../fence/edge/StaticWebpageDispatcher.java | 9 ++--
.../fence/AuthenticationClientMain.java | 2 -
.../fence/tests/ITUriTemplateHandler.java | 14 +++---
pom.xml | 31 +++++--------
.../fence/ResourceServerApplication.java | 2 -
.../fence/resource/ResourceAuthHandler.java | 24 +++++++---
19 files changed, 168 insertions(+), 125 deletions(-)
diff --git a/authentication-server/pom.xml b/authentication-server/pom.xml
index 13f93a0..b09bf40 100644
--- a/authentication-server/pom.xml
+++ b/authentication-server/pom.xml
@@ -44,11 +44,11 @@
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
- <artifactId>solution-basic</artifactId>
+ <artifactId>java-chassis-spring-boot-starter-standalone</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
- <artifactId>java-chassis-spring-boot-starter-standalone</artifactId>
+ <artifactId>registry-local</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
diff --git a/authentication-server/src/main/java/org/apache/servicecomb/fence/AuthenticationServerApplication.java b/authentication-server/src/main/java/org/apache/servicecomb/fence/AuthenticationServerApplication.java
index c2cd1bc..4aee6bb 100644
--- a/authentication-server/src/main/java/org/apache/servicecomb/fence/AuthenticationServerApplication.java
+++ b/authentication-server/src/main/java/org/apache/servicecomb/fence/AuthenticationServerApplication.java
@@ -17,13 +17,11 @@
package org.apache.servicecomb.fence;
-import org.apache.servicecomb.springboot2.starter.EnableServiceComb;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
-@EnableServiceComb
public class AuthenticationServerApplication {
public static void main(String[] args) {
try {
diff --git a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/AuthenticationConfiguration.java b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/AuthenticationConfiguration.java
index f89bf7c..6315eb5 100644
--- a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/AuthenticationConfiguration.java
+++ b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/AuthenticationConfiguration.java
@@ -35,7 +35,7 @@ import org.springframework.security.jwt.crypto.sign.SignerVerifier;
public class AuthenticationConfiguration {
@Bean(name = CommonConstants.BEAN_AUTH_PASSWORD_ENCODER)
public PasswordEncoder authPasswordEncoder() {
- return new Pbkdf2PasswordEncoder();
+ return Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_8();
}
@Bean(name = {CommonConstants.BEAN_AUTH_SIGNER, CommonConstants.BEAN_AUTH_SIGNATURE_VERIFIER})
diff --git a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/GithubOAuthService.java b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/GithubOAuthService.java
index 108aff6..e4b03d3 100644
--- a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/GithubOAuthService.java
+++ b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/GithubOAuthService.java
@@ -17,17 +17,16 @@
package org.apache.servicecomb.fence.authentication;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-
import org.springframework.http.MediaType;
-import io.swagger.annotations.Api;
+import jakarta.ws.rs.FormParam;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
//see: https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/
@Path("/login/oauth")
-@Api(produces = MediaType.APPLICATION_JSON_VALUE)
+@Produces(MediaType.APPLICATION_JSON_VALUE)
public interface GithubOAuthService {
@POST
@Path("/access_token")
diff --git a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/GithubOAuthServiceRegister.java b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/GithubOAuthServiceRegister.java
index f9a232a..27c760e 100644
--- a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/GithubOAuthServiceRegister.java
+++ b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/GithubOAuthServiceRegister.java
@@ -17,17 +17,40 @@
package org.apache.servicecomb.fence.authentication;
-import org.apache.servicecomb.provider.pojo.registry.ThirdServiceWithInvokerRegister;
-import org.springframework.stereotype.Component;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.servicecomb.config.BootStrapProperties;
+import org.apache.servicecomb.localregistry.RegistryBean;
+import org.apache.servicecomb.localregistry.RegistryBean.Instance;
+import org.apache.servicecomb.localregistry.RegistryBean.Instances;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
//see: https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/
-@Component
-public class GithubOAuthServiceRegister extends ThirdServiceWithInvokerRegister {
- private static final String GITHUB_ENDPOINT = "rest://github.com:443?sslEnabled=true";
+@Configuration
+public class GithubOAuthServiceRegister {
+ public static final String GITHUB_ENDPOINT = "rest://github.com:443?sslEnabled=true";
+
+ public static final String GITHUB_SERVICE_NAME = "github";
+
+ public static final String GITHUB_SERVICE_VERSION = "1.0";
- public GithubOAuthServiceRegister() {
- super("GithubOAuthService");
+ @Bean
+ public RegistryBean githubOAuthServiceRegistryBean(@Autowired Environment environment) {
+ List<String> endpoints = new ArrayList<>();
+ endpoints.add(GITHUB_ENDPOINT);
+ List<Instance> instances = new ArrayList<>();
+ instances.add(new Instance().setEndpoints(endpoints));
- addSchema("GithubOAuthService", GithubOAuthService.class);
+ return new RegistryBean()
+ .setServiceName(GITHUB_SERVICE_NAME)
+ .setId(GITHUB_SERVICE_NAME)
+ .setVersion(GITHUB_SERVICE_VERSION)
+ .setAppId(BootStrapProperties.readApplication(environment))
+ .addSchemaInterface("GithubOAuthService", GithubOAuthService.class)
+ .setInstances(new Instances().setInstances(instances));
}
}
diff --git a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/GithubTokenGranter.java b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/GithubTokenGranter.java
index e3a7473..1ff67ed 100644
--- a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/GithubTokenGranter.java
+++ b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/GithubTokenGranter.java
@@ -27,6 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.core.env.Environment;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@@ -36,15 +37,16 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
-import org.springframework.web.client.RestTemplate;
+import org.springframework.web.client.RestOperations;
import org.springframework.web.util.UriUtils;
-import com.netflix.config.DynamicPropertyFactory;
-
@Component
public class GithubTokenGranter implements ThirdPartyTokenGranter {
private static final Logger LOGGER = LoggerFactory.getLogger(GithubTokenGranter.class);
+ @Autowired
+ private Environment environment;
+
@Autowired
@Qualifier(CommonConstants.BEAN_AUTH_USER_DETAILS_SERVICE)
private UserDetailsService userDetailsService;
@@ -56,13 +58,12 @@ public class GithubTokenGranter implements ThirdPartyTokenGranter {
@RpcReference(microserviceName = "githubAuthService", schemaId = "githubAuthService")
GithubOAuthService githubOAuthService;
- RestTemplate githubRestTemplate = RestTemplateBuilder.create();
+ RestOperations githubRestTemplate = RestTemplateBuilder.create();
@Override
public boolean enabled() {
- return DynamicPropertyFactory.getInstance()
- .getBooleanProperty(AuthenticationServerConstants.CONFIG_GRANTER_THIRD_GITHUB_ENABLED, true)
- .get();
+ return environment.getProperty(AuthenticationServerConstants.CONFIG_GRANTER_THIRD_GITHUB_ENABLED, boolean.class,
+ true);
}
@Override
diff --git a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/PasswordTokenGranter.java b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/PasswordTokenGranter.java
index a2f90a9..57d8694 100644
--- a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/PasswordTokenGranter.java
+++ b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/PasswordTokenGranter.java
@@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.fence.token.AbstractOpenIDTokenStore;
import org.apache.servicecomb.fence.token.OpenIDToken;
import org.apache.servicecomb.fence.util.CommonConstants;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.core.userdetails.UserDetails;
@@ -31,8 +32,6 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
-import com.netflix.config.DynamicPropertyFactory;
-
@Component
public class PasswordTokenGranter implements TokenGranter {
@Autowired
@@ -77,9 +76,7 @@ public class PasswordTokenGranter implements TokenGranter {
@Override
public boolean enabled() {
- return DynamicPropertyFactory.getInstance()
- .getBooleanProperty(AuthenticationServerConstants.CONFIG_GRANTER_PASSWORD_ENABLED, true)
- .get();
+ return LegacyPropertyFactory
+ .getBooleanProperty(AuthenticationServerConstants.CONFIG_GRANTER_PASSWORD_ENABLED, true);
}
-
}
diff --git a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/RefreshTokenTokenGranter.java b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/RefreshTokenTokenGranter.java
index 3df4065..9fdad86 100644
--- a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/RefreshTokenTokenGranter.java
+++ b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/RefreshTokenTokenGranter.java
@@ -24,14 +24,13 @@ import org.apache.servicecomb.fence.token.AbstractOpenIDTokenStore;
import org.apache.servicecomb.fence.token.OpenIDToken;
import org.apache.servicecomb.fence.token.Token;
import org.apache.servicecomb.fence.util.CommonConstants;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;
-import com.netflix.config.DynamicPropertyFactory;
-
@Component
public class RefreshTokenTokenGranter implements TokenGranter {
@Autowired
@@ -44,9 +43,8 @@ public class RefreshTokenTokenGranter implements TokenGranter {
@Override
public boolean enabled() {
- return DynamicPropertyFactory.getInstance()
- .getBooleanProperty(AuthenticationServerConstants.CONFIG_GRANTER_REFRESH_TOKEN_ENABLED, true)
- .get();
+ return LegacyPropertyFactory
+ .getBooleanProperty(AuthenticationServerConstants.CONFIG_GRANTER_REFRESH_TOKEN_ENABLED, true);
}
@Override
@@ -72,5 +70,4 @@ public class RefreshTokenTokenGranter implements TokenGranter {
}
return null;
}
-
}
diff --git a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/TokenEndpoint.java b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/TokenEndpoint.java
index da4c30b..b4734f8 100644
--- a/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/TokenEndpoint.java
+++ b/authentication-server/src/main/java/org/apache/servicecomb/fence/authentication/TokenEndpoint.java
@@ -21,13 +21,11 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response.Status;
-
import org.apache.servicecomb.fence.token.OpenIDToken;
import org.apache.servicecomb.fence.token.OpenIDTokenStore;
import org.apache.servicecomb.fence.util.CommonConstants;
import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -36,6 +34,9 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response.Status;
+
@RestSchema(schemaId = "TokenEndpoint")
@RequestMapping(path = "/v1/token")
public class TokenEndpoint implements TokenService {
@@ -70,8 +71,8 @@ public class TokenEndpoint implements TokenService {
try {
return result.get();
} catch (Exception e) {
- throw new InvocationException(Status.INTERNAL_SERVER_ERROR, "internal unexpected error.");
+ throw new InvocationException(Status.INTERNAL_SERVER_ERROR,
+ new CommonExceptionData("internal unexpected error."));
}
}
-
}
diff --git a/edge-service/src/main/java/org/apache/servicecomb/fence/EdgeServiceApplication.java b/edge-service/src/main/java/org/apache/servicecomb/fence/EdgeServiceApplication.java
index f194014..7b8fd78 100644
--- a/edge-service/src/main/java/org/apache/servicecomb/fence/EdgeServiceApplication.java
+++ b/edge-service/src/main/java/org/apache/servicecomb/fence/EdgeServiceApplication.java
@@ -17,13 +17,11 @@
package org.apache.servicecomb.fence;
-import org.apache.servicecomb.springboot2.starter.EnableServiceComb;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
-@EnableServiceComb
public class EdgeServiceApplication {
public static void main(String[] args) {
try {
diff --git a/edge-service/src/main/java/org/apache/servicecomb/fence/edge/AuthHandler.java b/edge-service/src/main/java/org/apache/servicecomb/fence/edge/AuthHandler.java
index 4ab93cd..eb4f15d 100644
--- a/edge-service/src/main/java/org/apache/servicecomb/fence/edge/AuthHandler.java
+++ b/edge-service/src/main/java/org/apache/servicecomb/fence/edge/AuthHandler.java
@@ -19,24 +19,39 @@ package org.apache.servicecomb.fence.edge;
import java.util.concurrent.CompletableFuture;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.core.filter.AbstractFilter;
+import org.apache.servicecomb.core.filter.EdgeFilter;
+import org.apache.servicecomb.core.filter.FilterNode;
import org.apache.servicecomb.fence.token.JWTToken;
import org.apache.servicecomb.fence.token.OpenIDToken;
import org.apache.servicecomb.fence.token.OpenIDTokenStore;
import org.apache.servicecomb.fence.util.CommonConstants;
-import org.apache.servicecomb.core.Handler;
-import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
+import org.apache.servicecomb.swagger.invocation.Response;
+import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
-public class AuthHandler implements Handler {
+import jakarta.ws.rs.core.Response.Status;
+
+public class AuthHandler extends AbstractFilter implements EdgeFilter {
+ @Override
+ public int getOrder() {
+ return super.getOrder();
+ }
+
@Override
- public void handle(Invocation invocation, AsyncResponse asyncResponse) throws Exception {
+ public String getName() {
+ return super.getName();
+ }
+
+ @Override
+ public CompletableFuture<Response> onFilter(Invocation invocation, FilterNode nextNode) {
String token = invocation.getContext(CommonConstants.CONTEXT_HEADER_AUTHORIZATION);
String tokenType = invocation.getContext(CommonConstants.CONTEXT_HEADER_AUTHORIZATION_TYPE);
if (token == null) {
- asyncResponse.consumerFail(new InvocationException(403, "forbidden", "not authenticated"));
- return;
+ return CompletableFuture.failedFuture(new InvocationException(Status.FORBIDDEN,
+ new CommonExceptionData("not authenticated")));
}
OpenIDTokenStore openIDTokenStore = BeanUtils.getBean(CommonConstants.BEAN_AUTH_OPEN_ID_TOKEN_STORE);
@@ -44,33 +59,31 @@ public class AuthHandler implements Handler {
if (CommonConstants.AUTHORIZATION_TYPE_ID_TOKEN.equals(tokenType)) {
JWTToken jwtToken = openIDTokenStore.createIDTokenByValue(token);
if (jwtToken == null || jwtToken.isExpired()) {
- asyncResponse.consumerFail(new InvocationException(403, "forbidden", "token expired or not valid."));
- return;
+ return CompletableFuture.failedFuture(new InvocationException(Status.FORBIDDEN,
+ new CommonExceptionData("token expired or not valid")));
}
// send id_token to services to apply state less validation
invocation.addContext(CommonConstants.CONTEXT_HEADER_AUTHORIZATION, jwtToken.getValue());
- invocation.next(asyncResponse);
+ return nextNode.onFilter(invocation);
} else if (CommonConstants.AUTHORIZATION_TYPE_ACCESS_TOKEN.equals(tokenType)) {
CompletableFuture<OpenIDToken> openIDTokenFuture = openIDTokenStore.readTokenByAccessToken(token);
+ CompletableFuture<Void> result = new CompletableFuture<>();
openIDTokenFuture.whenComplete((res, ex) -> {
if (openIDTokenFuture.isCompletedExceptionally() || res == null || res.isExpired()) {
- asyncResponse.consumerFail(new InvocationException(403, "forbidden", "not authenticated"));
+ result.completeExceptionally(new InvocationException(Status.FORBIDDEN,
+ new CommonExceptionData("not authenticated")));
return;
}
// send id_token to services to apply state less validation
invocation.addContext(CommonConstants.CONTEXT_HEADER_AUTHORIZATION, res.getIdToken().getValue());
- try {
- invocation.next(asyncResponse);
- } catch (Exception e) {
- asyncResponse.consumerFail(new InvocationException(403, "forbidden", "not authenticated"));
- return;
- }
+ result.complete(null);
});
+ return result.thenCompose((v) -> nextNode.onFilter(invocation));
} else {
- asyncResponse.consumerFail(new InvocationException(403, "forbidden", "not authenticated"));
- return;
+ return CompletableFuture.failedFuture(new InvocationException(Status.FORBIDDEN,
+ new CommonExceptionData("not authenticated")));
}
}
}
diff --git a/edge-service/src/main/java/org/apache/servicecomb/fence/edge/AuthenticationFilter.java b/edge-service/src/main/java/org/apache/servicecomb/fence/edge/AuthenticationFilter.java
index 9d95200..cca1123 100644
--- a/edge-service/src/main/java/org/apache/servicecomb/fence/edge/AuthenticationFilter.java
+++ b/edge-service/src/main/java/org/apache/servicecomb/fence/edge/AuthenticationFilter.java
@@ -17,13 +17,16 @@
package org.apache.servicecomb.fence.edge;
-import org.apache.servicecomb.fence.util.CommonConstants;
-import org.apache.servicecomb.common.rest.filter.HttpServerFilter;
+import java.util.concurrent.CompletableFuture;
+
import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
+import org.apache.servicecomb.core.filter.AbstractFilter;
+import org.apache.servicecomb.core.filter.EdgeFilter;
+import org.apache.servicecomb.core.filter.FilterNode;
+import org.apache.servicecomb.fence.util.CommonConstants;
import org.apache.servicecomb.swagger.invocation.Response;
-public class AuthenticationFilter implements HttpServerFilter {
+public class AuthenticationFilter extends AbstractFilter implements EdgeFilter {
@Override
public int getOrder() {
@@ -31,9 +34,14 @@ public class AuthenticationFilter implements HttpServerFilter {
}
@Override
- public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
- String authentication = requestEx.getHeader(CommonConstants.HTTP_HEADER_AUTHORIZATION);
- String type = requestEx.getHeader(CommonConstants.HTTP_HEADER_AUTHORIZATION_TYPE);
+ public String getName() {
+ return "authentication";
+ }
+
+ @Override
+ public CompletableFuture<Response> onFilter(Invocation invocation, FilterNode nextNode) {
+ String authentication = invocation.getRequestEx().getHeader(CommonConstants.HTTP_HEADER_AUTHORIZATION);
+ String type = invocation.getRequestEx().getHeader(CommonConstants.HTTP_HEADER_AUTHORIZATION_TYPE);
if (authentication != null) {
String[] tokens = authentication.split(" ");
if (tokens.length == 2) {
@@ -44,7 +52,6 @@ public class AuthenticationFilter implements HttpServerFilter {
}
}
}
- return null;
+ return nextNode.onFilter(invocation);
}
-
}
diff --git a/edge-service/src/main/java/org/apache/servicecomb/fence/edge/InternalAccessHandler.java b/edge-service/src/main/java/org/apache/servicecomb/fence/edge/InternalAccessHandler.java
index db91ead..f09cd12 100644
--- a/edge-service/src/main/java/org/apache/servicecomb/fence/edge/InternalAccessHandler.java
+++ b/edge-service/src/main/java/org/apache/servicecomb/fence/edge/InternalAccessHandler.java
@@ -17,21 +17,36 @@
package org.apache.servicecomb.fence.edge;
-import org.apache.servicecomb.core.Handler;
+import java.util.concurrent.CompletableFuture;
+
import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
+import org.apache.servicecomb.core.filter.AbstractFilter;
+import org.apache.servicecomb.core.filter.EdgeFilter;
+import org.apache.servicecomb.core.filter.FilterNode;
+import org.apache.servicecomb.swagger.invocation.Response;
+import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
-public class InternalAccessHandler implements Handler {
+import jakarta.ws.rs.core.Response.Status;
+
+public class InternalAccessHandler extends AbstractFilter implements EdgeFilter {
+ @Override
+ public int getOrder() {
+ return super.getOrder();
+ }
+
+ @Override
+ public String getName() {
+ return super.getName();
+ }
@Override
- public void handle(Invocation invocation, AsyncResponse asyncReponse) throws Exception {
+ public CompletableFuture<Response> onFilter(Invocation invocation, FilterNode nextNode) {
if (invocation.getOperationMeta().getSwaggerOperation().getTags() != null
&& invocation.getOperationMeta().getSwaggerOperation().getTags().contains("INTERNAL")) {
- asyncReponse.consumerFail(new InvocationException(403, "", "not allowed"));
- return;
+ return CompletableFuture.failedFuture(
+ new InvocationException(Status.FORBIDDEN, new CommonExceptionData("not allowed")));
}
- invocation.next(asyncReponse);
+ return nextNode.onFilter(invocation);
}
-
}
diff --git a/edge-service/src/main/java/org/apache/servicecomb/fence/edge/StaticWebpageDispatcher.java b/edge-service/src/main/java/org/apache/servicecomb/fence/edge/StaticWebpageDispatcher.java
index 09da3d0..8d92120 100644
--- a/edge-service/src/main/java/org/apache/servicecomb/fence/edge/StaticWebpageDispatcher.java
+++ b/edge-service/src/main/java/org/apache/servicecomb/fence/edge/StaticWebpageDispatcher.java
@@ -17,21 +17,19 @@
package org.apache.servicecomb.fence.edge;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.netflix.config.DynamicPropertyFactory;
-
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.StaticHandler;
public class StaticWebpageDispatcher implements VertxHttpDispatcher {
private static final Logger LOGGER = LoggerFactory.getLogger(StaticWebpageDispatcher.class);
- private static final String WEB_ROOT = DynamicPropertyFactory.getInstance()
- .getStringProperty("gateway.webroot", "/var/static")
- .get();
+ private static final String WEB_ROOT = LegacyPropertyFactory
+ .getStringProperty("gateway.webroot", "/var/static");
@Override
public int getOrder() {
@@ -47,5 +45,4 @@ public class StaticWebpageDispatcher implements VertxHttpDispatcher {
LOGGER.error("", context.failure());
}).handler(webpageHandler);
}
-
}
diff --git a/integration-tests/src/main/java/org/apache/servicecomb/fence/AuthenticationClientMain.java b/integration-tests/src/main/java/org/apache/servicecomb/fence/AuthenticationClientMain.java
index b81f052..73cd0ec 100644
--- a/integration-tests/src/main/java/org/apache/servicecomb/fence/AuthenticationClientMain.java
+++ b/integration-tests/src/main/java/org/apache/servicecomb/fence/AuthenticationClientMain.java
@@ -17,13 +17,11 @@
package org.apache.servicecomb.fence;
-import org.apache.servicecomb.springboot2.starter.EnableServiceComb;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
-@EnableServiceComb
public class AuthenticationClientMain {
public static void main(String[] args) {
try {
diff --git a/integration-tests/src/main/java/org/apache/servicecomb/fence/tests/ITUriTemplateHandler.java b/integration-tests/src/main/java/org/apache/servicecomb/fence/tests/ITUriTemplateHandler.java
index 24325ec..cb95757 100644
--- a/integration-tests/src/main/java/org/apache/servicecomb/fence/tests/ITUriTemplateHandler.java
+++ b/integration-tests/src/main/java/org/apache/servicecomb/fence/tests/ITUriTemplateHandler.java
@@ -19,9 +19,9 @@ package org.apache.servicecomb.fence.tests;
import java.net.URI;
import java.util.Map;
-@SuppressWarnings("deprecation")
-// TODO : upgrade to spring 5 will having warning's , we'll fix it later
-public class ITUriTemplateHandler extends org.springframework.web.util.DefaultUriTemplateHandler {
+import org.springframework.web.util.DefaultUriBuilderFactory;
+
+public class ITUriTemplateHandler extends DefaultUriBuilderFactory {
private String urlPrefix;
public ITUriTemplateHandler(String urlPrefix) {
@@ -29,13 +29,13 @@ public class ITUriTemplateHandler extends org.springframework.web.util.DefaultUr
}
@Override
- protected URI expandInternal(String uriTemplate, Object... uriVariables) {
- return super.expandInternal(changeUrl(uriTemplate), uriVariables);
+ public URI expand(String uriTemplate, Object... uriVariables) {
+ return super.expand(changeUrl(uriTemplate), uriVariables);
}
@Override
- protected URI expandInternal(String uriTemplate, Map<String, ?> uriVariables) {
- return super.expandInternal(changeUrl(uriTemplate), uriVariables);
+ public URI expand(String uriTemplate, Map<String, ?> uriVariables) {
+ return super.expand(changeUrl(uriTemplate), uriVariables);
}
private String changeUrl(String uriTemplate) {
diff --git a/pom.xml b/pom.xml
index 6240115..6460435 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,9 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <java-chassis-version>2.8.3</java-chassis-version>
+ <servicecomb.version>3.1.0</servicecomb.version>
+ <spring-boot-maven-plugin.version>3.1.3</spring-boot-maven-plugin.version>
+ <maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
</properties>
<modules>
@@ -35,7 +37,7 @@
<module>edge-service</module>
<module>authentication-server</module>
<module>resource-server</module>
- <module>integration-tests</module>
+<!-- <module>integration-tests</module>-->
</modules>
<dependencyManagement>
@@ -43,7 +45,7 @@
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>java-chassis-dependencies</artifactId>
- <version>${java-chassis-version}</version>
+ <version>${servicecomb.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@@ -86,7 +88,7 @@
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
- <artifactId>registry-service-center</artifactId>
+ <artifactId>registry-zookeeper</artifactId>
</dependency>
</dependencies>
@@ -96,35 +98,22 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.10.1</version>
+ <version>${maven-compiler-plugin.version}</version>
<configuration>
<compilerArgument>-parameters</compilerArgument>
- <source>1.8</source>
- <target>1.8</target>
- <showDeprecation>true</showDeprecation>
- <showWarnings>true</showWarnings>
- <compilerArgs>
- <arg>-Werror</arg>
- <arg>-Xlint:all</arg>
- <!--not care for jdk8/jdk7 compatible problem-->
- <arg>-Xlint:-classfile</arg>
- <!--not care for annotations not processed-->
- <arg>-Xlint:-processing</arg>
- </compilerArgs>
+ <source>17</source>
+ <target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
- <version>2.7.0</version>
+ <version>${spring-boot-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
- <configuration>
- <mainClass>${main.class}</mainClass>
- </configuration>
</execution>
</executions>
</plugin>
diff --git a/resource-server/src/main/java/org/apache/servicecomb/fence/ResourceServerApplication.java b/resource-server/src/main/java/org/apache/servicecomb/fence/ResourceServerApplication.java
index 37041fc..969be66 100644
--- a/resource-server/src/main/java/org/apache/servicecomb/fence/ResourceServerApplication.java
+++ b/resource-server/src/main/java/org/apache/servicecomb/fence/ResourceServerApplication.java
@@ -17,13 +17,11 @@
package org.apache.servicecomb.fence;
-import org.apache.servicecomb.springboot2.starter.EnableServiceComb;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
-@EnableServiceComb
public class ResourceServerApplication {
public static void main(String[] args) {
try {
diff --git a/resource-server/src/main/java/org/apache/servicecomb/fence/resource/ResourceAuthHandler.java b/resource-server/src/main/java/org/apache/servicecomb/fence/resource/ResourceAuthHandler.java
index 096e2bc..ca1f55e 100644
--- a/resource-server/src/main/java/org/apache/servicecomb/fence/resource/ResourceAuthHandler.java
+++ b/resource-server/src/main/java/org/apache/servicecomb/fence/resource/ResourceAuthHandler.java
@@ -17,16 +17,28 @@
package org.apache.servicecomb.fence.resource;
-import org.apache.servicecomb.core.Handler;
+import java.util.concurrent.CompletableFuture;
+
import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
+import org.apache.servicecomb.core.filter.AbstractFilter;
+import org.apache.servicecomb.core.filter.FilterNode;
+import org.apache.servicecomb.core.filter.ProviderFilter;
+import org.apache.servicecomb.swagger.invocation.Response;
-public class ResourceAuthHandler implements Handler {
+public class ResourceAuthHandler extends AbstractFilter implements ProviderFilter {
+ @Override
+ public int getOrder() {
+ return super.getOrder();
+ }
@Override
- public void handle(Invocation invocation, AsyncResponse asyncResponse) throws Exception {
- AuthFiltersBean.getAuthFilters().forEach(authFilter -> authFilter.doFilter(invocation));
- invocation.next(asyncResponse);
+ public String getName() {
+ return super.getName();
}
+ @Override
+ public CompletableFuture<Response> onFilter(Invocation invocation, FilterNode nextNode) {
+ AuthFiltersBean.getAuthFilters().forEach(authFilter -> authFilter.doFilter(invocation));
+ return nextNode.onFilter(invocation);
+ }
}