Skip to content

Commit bac7212

Browse files
authored
Allow not to return sync stat when describe index; TunnelClient: fix readMaxTimesPerRound logic; KnnQuery support minScore and numCandidates; Search: add trackTotalCount; search filter supports; add accessDeniedDetail in TableStoreNoPermissionException; support TunnelClient created by CredentialsProvider (#49)
1 parent 96083be commit bac7212

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+6180
-1075
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
- 阿里云表格存储是阿里云自主研发的NoSQL数据存储服务,提供海量结构化数据的存储和实时访问。
1010

1111
## 版本
12-
- 当前版本:5.17.4
12+
- 当前版本:5.17.5
1313

1414
## 运行环境
1515
- JDK 6及其以上
1616

1717
## 安装
1818
#### Maven方式
19-
下载[最新版JAR包](https://search.maven.org/remotecontent?filepath=com/aliyun/openservices/tablestore/5.17.4/tablestore-5.17.4.jar)或者通过Maven:
19+
下载[最新版JAR包](https://search.maven.org/remotecontent?filepath=com/aliyun/openservices/tablestore/5.17.5/tablestore-5.17.5.jar)或者通过Maven:
2020
```xml
2121
<dependency>
2222
<groupId>com.aliyun.openservices</groupId>
2323
<artifactId>tablestore</artifactId>
24-
<version>5.17.4</version>
24+
<version>5.17.5</version>
2525
</dependency>
2626
```
2727

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.aliyun.openservices</groupId>
55
<artifactId>tablestore</artifactId>
6-
<version>5.17.4</version>
6+
<version>5.17.5</version>
77
<packaging>jar</packaging>
88
<name>AliCloud TableStore SDK for Java</name>
99
<url>http://www.aliyun.com</url>
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package com.alicloud.openservices.tablestore;
2+
3+
import com.alicloud.openservices.tablestore.core.protocol.OtsInternalApi;
4+
5+
public class TableStoreNoPermissionException extends TableStoreException {
6+
7+
private AccessDeniedDetail accessDeniedDetail;
8+
9+
public TableStoreNoPermissionException(String message, Throwable cause,
10+
String errorCode,
11+
String requestId, int httpStatus, OtsInternalApi.AccessDeniedDetail accessDeniedDetail) {
12+
super(message, cause, errorCode, requestId, httpStatus);
13+
this.accessDeniedDetail = new AccessDeniedDetail(
14+
accessDeniedDetail.getAuthAction(),
15+
accessDeniedDetail.getAuthPrincipalType(),
16+
accessDeniedDetail.getAuthPrincipalOwnerId(),
17+
accessDeniedDetail.getAuthPrincipalDisplayName(),
18+
accessDeniedDetail.getPolicyType(),
19+
accessDeniedDetail.getNoPermissionType(),
20+
accessDeniedDetail.getEncodedDiagnosticMessage());
21+
}
22+
23+
public TableStoreNoPermissionException(String message, Throwable cause,
24+
String errorCode,
25+
String requestId, int httpStatus, AccessDeniedDetail accessDeniedDetail) {
26+
super(message, cause, errorCode, requestId, httpStatus);
27+
this.accessDeniedDetail = accessDeniedDetail;
28+
}
29+
30+
public AccessDeniedDetail getAccessDeniedDetail() {
31+
return accessDeniedDetail;
32+
}
33+
34+
public void setAccessDeniedDetail(AccessDeniedDetail accessDeniedDetail) {
35+
this.accessDeniedDetail = accessDeniedDetail;
36+
}
37+
38+
public String toString() {
39+
return super.toString() + ", [AccessDeniedDetail]:" + accessDeniedDetail.toString();
40+
}
41+
42+
public static class AccessDeniedDetail {
43+
44+
private String authAction;
45+
46+
private String authPrincipalType;
47+
48+
private String authPrincipalOwnerId;
49+
50+
private String authPrincipalDisplayName;
51+
52+
private String policyType;
53+
54+
private String noPermissionType;
55+
56+
private String encodedDiagnosticMessage;
57+
58+
public AccessDeniedDetail(String authAction, String authPrincipalType, String authPrincipalOwnerId, String authPrincipalDisplayName, String policyType, String noPermissionType, String encodedDiagnosticMessage) {
59+
this.authAction = authAction;
60+
this.authPrincipalType = authPrincipalType;
61+
this.authPrincipalOwnerId = authPrincipalOwnerId;
62+
this.authPrincipalDisplayName = authPrincipalDisplayName;
63+
this.policyType = policyType;
64+
this.noPermissionType = noPermissionType;
65+
this.encodedDiagnosticMessage = encodedDiagnosticMessage;
66+
}
67+
68+
public String getAuthAction() {
69+
return authAction;
70+
}
71+
72+
public void setAuthAction(String authAction) {
73+
this.authAction = authAction;
74+
}
75+
76+
public String getAuthPrincipalType() {
77+
return authPrincipalType;
78+
}
79+
80+
public void setAuthPrincipalType(String authPrincipalType) {
81+
this.authPrincipalType = authPrincipalType;
82+
}
83+
84+
public String getAuthPrincipalOwnerId() {
85+
return authPrincipalOwnerId;
86+
}
87+
88+
public void setAuthPrincipalOwnerId(String authPrincipalOwnerId) {
89+
this.authPrincipalOwnerId = authPrincipalOwnerId;
90+
}
91+
92+
public String getAuthPrincipalDisplayName() {
93+
return authPrincipalDisplayName;
94+
}
95+
96+
public void setAuthPrincipalDisplayName(String authPrincipalDisplayName) {
97+
this.authPrincipalDisplayName = authPrincipalDisplayName;
98+
}
99+
100+
public String getPolicyType() {
101+
return policyType;
102+
}
103+
104+
public void setPolicyType(String policyType) {
105+
this.policyType = policyType;
106+
}
107+
108+
public String getNoPermissionType() {
109+
return noPermissionType;
110+
}
111+
112+
public void setNoPermissionType(String noPermissionType) {
113+
this.noPermissionType = noPermissionType;
114+
}
115+
116+
public String getEncodedDiagnosticMessage() {
117+
return encodedDiagnosticMessage;
118+
}
119+
120+
public void setEncodedDiagnosticMessage(String encodedDiagnosticMessage) {
121+
this.encodedDiagnosticMessage = encodedDiagnosticMessage;
122+
}
123+
124+
@Override
125+
public String toString() {
126+
return "AccessDeniedDetail{" +
127+
"authAction='" + authAction + '\'' +
128+
", authPrincipalType='" + authPrincipalType + '\'' +
129+
", authPrincipalOwnerId='" + authPrincipalOwnerId + '\'' +
130+
", authPrincipalDisplayName='" + authPrincipalDisplayName + '\'' +
131+
", policyType='" + policyType + '\'' +
132+
", noPermissionType='" + noPermissionType + '\'' +
133+
", encodedDiagnosticMessage='" + encodedDiagnosticMessage + '\'' +
134+
'}';
135+
}
136+
}
137+
}

src/main/java/com/alicloud/openservices/tablestore/TunnelClient.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.Map;
44
import java.util.concurrent.*;
55

6+
import com.alicloud.openservices.tablestore.core.ResourceManager;
7+
import com.alicloud.openservices.tablestore.core.auth.CredentialsProvider;
68
import com.alicloud.openservices.tablestore.core.utils.Preconditions;
79
import com.alicloud.openservices.tablestore.model.tunnel.CreateTunnelRequest;
810
import com.alicloud.openservices.tablestore.model.tunnel.CreateTunnelResponse;
@@ -103,16 +105,28 @@ public TunnelClient(String endpoint, String accessKeyId,
103105
public TunnelClient(String endpoint, String accessKeyId,
104106
String accessKeySecret, String instanceName, ClientConfiguration config, String stsToken,
105107
ExecutorService callbackExecutor) {
106-
if (config != null) {
107-
config.setEnableResponseValidation(false);
108-
} else {
108+
if (config == null) {
109109
config = new ClientConfiguration();
110-
config.setEnableResponseValidation(false);
111110
}
111+
config.setEnableResponseValidation(false);
112+
112113
this.internalClient = new InternalClient(endpoint, accessKeyId, accessKeySecret, instanceName, config,
113114
callbackExecutor, stsToken);
114115
}
115116

117+
/**
118+
* 使用指定的TableStore Endpoint和默认配置构造一个新的{@link TunnelClient}实例。
119+
*/
120+
public TunnelClient(String endpoint, CredentialsProvider credsProvider, String instanceName,
121+
ClientConfiguration config, ResourceManager resourceManager) {
122+
if (config == null) {
123+
config = new ClientConfiguration();
124+
}
125+
config.setEnableResponseValidation(false);
126+
127+
this.internalClient = new InternalClient(endpoint, credsProvider, instanceName, config, resourceManager);
128+
}
129+
116130
TunnelClient(InternalClient internalClient) {
117131
this.internalClient = internalClient;
118132
}
@@ -139,6 +153,15 @@ public String getInstanceName() {
139153
return this.internalClient.getInstanceName();
140154
}
141155

156+
/**
157+
* 返回Client配置
158+
*
159+
* @return client configuration
160+
*/
161+
public ClientConfiguration getClientConfig() {
162+
return this.internalClient.getClientConfig();
163+
}
164+
142165
@Override
143166
public CreateTunnelResponse createTunnel(CreateTunnelRequest request)
144167
throws TableStoreException, ClientException {

src/main/java/com/alicloud/openservices/tablestore/core/CallbackImpledFuture.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.alicloud.openservices.tablestore.TableStoreCallback;
1010
import com.alicloud.openservices.tablestore.TableStoreException;
1111
import com.alicloud.openservices.tablestore.ClientException;
12+
import com.alicloud.openservices.tablestore.TableStoreNoPermissionException;
1213
import com.alicloud.openservices.tablestore.core.utils.Preconditions;
1314

1415
public class CallbackImpledFuture<Req, Res>
@@ -101,7 +102,14 @@ public Res get(long timeout, TimeUnit unit)
101102

102103

103104
private Res getResultWithoutLock() throws TableStoreException, ClientException {
104-
if (this.ex instanceof TableStoreException) {
105+
if (this.ex instanceof TableStoreNoPermissionException) {
106+
// create a new exception as this.ex doesn't has current stack trace
107+
TableStoreNoPermissionException tmp = (TableStoreNoPermissionException) this.ex;
108+
TableStoreNoPermissionException newExp = new TableStoreNoPermissionException(tmp.getMessage(), tmp, tmp.getErrorCode(), tmp.getRequestId(), tmp.getHttpStatus(),tmp.getAccessDeniedDetail());
109+
newExp.setTraceId(tmp.getTraceId());
110+
throw newExp;
111+
}
112+
else if (this.ex instanceof TableStoreException) {
105113
// create a new exception as this.ex doesn't has current stack trace
106114
TableStoreException tmp = (TableStoreException)this.ex;
107115
TableStoreException newExp = new TableStoreException(tmp.getMessage(), tmp, tmp.getErrorCode(), tmp.getRequestId(), tmp.getHttpStatus());

src/main/java/com/alicloud/openservices/tablestore/core/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public class Constants {
66
// ALL HTTP HEADERS SHOULD BE DEFINED IN LOWERCASE
77
// request headers
8-
public static final String USER_AGENT = "ots-java-sdk 5.17.4";
8+
public static final String USER_AGENT = "ots-java-sdk 5.17.5";
99
public static final String OTS_HEADER_API_VERSION = "x-ots-apiversion";
1010
public static final String OTS_HEADER_ACCESS_KEY_ID = "x-ots-accesskeyid";
1111
public static final String OTS_HEADER_OTS_CONTENT_MD5 = "x-ots-contentmd5";

src/main/java/com/alicloud/openservices/tablestore/core/http/ErrorResponseHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.alicloud.openservices.tablestore.ClientException;
88
import com.alicloud.openservices.tablestore.TableStoreException;
9+
import com.alicloud.openservices.tablestore.TableStoreNoPermissionException;
910
import com.alicloud.openservices.tablestore.core.Constants;
1011
import com.alicloud.openservices.tablestore.core.protocol.OtsInternalApi;
1112
import com.alicloud.openservices.tablestore.core.utils.Preconditions;
@@ -53,6 +54,9 @@ public void handle(ResponseMessage responseData) throws TableStoreException, Cli
5354

5455
try {
5556
OtsInternalApi.Error errMsg = OtsInternalApi.Error.parseFrom(errorStream);
57+
if (errMsg.hasAccessDeniedDetail()) {
58+
throw new TableStoreNoPermissionException(errMsg.getMessage(), null, errMsg.getCode(), requestId, httpStatus,errMsg.getAccessDeniedDetail());
59+
}
5660
throw new TableStoreException(errMsg.getMessage(), null, errMsg.getCode(), requestId, httpStatus);
5761
} catch (IOException e) {
5862
throw new ClientException("Network error.", e);

src/main/java/com/alicloud/openservices/tablestore/core/http/OTSValidationResponseHandler.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.alicloud.openservices.tablestore.core.utils.Bytes;
1616
import com.alicloud.openservices.tablestore.core.auth.ServiceCredentials;
1717
import com.alicloud.openservices.tablestore.core.auth.HmacSHA1Signature;
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
1820

1921
import static com.alicloud.openservices.tablestore.core.Constants.*;
2022

@@ -23,7 +25,7 @@
2325
*
2426
*/
2527
public class OTSValidationResponseHandler implements ResponseHandler{
26-
28+
private static final Logger LOG = LoggerFactory.getLogger(OTSValidationResponseHandler.class);
2729
private ServiceCredentials credentials;
2830
private OTSUri uri;
2931

@@ -64,7 +66,6 @@ public void handle(ResponseMessage responseData) throws ClientException {
6466
}
6567
strToSign.append('/');
6668
strToSign.append(uri.getAction());
67-
6869
HmacSHA1Signature signer = new HmacSHA1Signature(Bytes.toBytes(credentials.getAccessKeySecret()));
6970
signer.updateUTF8String(strToSign.toString());
7071
String actualSign = signer.computeSignature();
@@ -74,14 +75,17 @@ public void handle(ResponseMessage responseData) throws ClientException {
7475
int posSign = authHeader.indexOf(actualSign);
7576
if (posSign < 0) {
7677
// cannot find signature
78+
LOG.error("Validate response authorization failed, cannot find signature. headers:{}, accessKeyId:{}, computedSign:{}", headers, credentials.getAccessKeyId(), actualSign);
7779
throw new ClientException("返回结果授权信息验证失败。");
7880
}
7981
if (posSign == 0 || authHeader.charAt(posSign - 1) != ':') {
8082
// cannot find separator ':'
83+
LOG.error("Validate response authorization failed, cannot find separator ':'. headers:{}, accessKeyId:{}, computedSign:{}", headers, credentials.getAccessKeyId(), actualSign);
8184
throw new ClientException("返回结果授权信息验证失败。");
8285
}
8386
if (posSign + actualSign.length() != authHeader.length()) {
8487
// signature is not the last part of authHeader
88+
LOG.error("Validate response authorization failed, signature is not the last part of authHeader. headers:{}, accessKeyId:{}, computedSign:{}", headers, credentials.getAccessKeyId(), actualSign);
8589
throw new ClientException("返回结果授权信息验证失败。");
8690
}
8791
}

0 commit comments

Comments
 (0)