Skip to content

Commit eb34cc1

Browse files
committed
feat:support auth.
1 parent eb478f6 commit eb34cc1

File tree

44 files changed

+2188
-8
lines changed

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

+2188
-8
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>polaris-auth</artifactId>
7+
<groupId>com.tencent.polaris</groupId>
8+
<version>${revision}</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>polaris-auth-api</artifactId>
14+
<name>Polaris Auth API</name>
15+
<description>Polaris Auth API JAR</description>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.tencent.polaris</groupId>
20+
<artifactId>polaris-plugin-api</artifactId>
21+
<version>${project.version}</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>com.tencent.polaris</groupId>
25+
<artifactId>polaris-client</artifactId>
26+
<version>${project.version}</version>
27+
</dependency>
28+
</dependencies>
29+
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package com.tencent.polaris.auth.api.core;
19+
20+
import com.tencent.polaris.api.exception.PolarisException;
21+
import com.tencent.polaris.auth.api.rpc.AuthRequest;
22+
import com.tencent.polaris.auth.api.rpc.AuthResponse;
23+
24+
import java.io.Closeable;
25+
26+
public interface AuthAPI extends AutoCloseable, Closeable {
27+
28+
/**
29+
* 鉴权
30+
*
31+
* @param authRequest 鉴权请求(服务及标签信息)
32+
* @return 鉴权通过情况
33+
* @throws PolarisException 异常信息
34+
*/
35+
AuthResponse authenticate(AuthRequest authRequest) throws PolarisException;
36+
37+
/**
38+
* 清理并释放资源
39+
*/
40+
void destroy();
41+
42+
@Override
43+
default void close() {
44+
destroy();
45+
}
46+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package com.tencent.polaris.auth.api.flow;
19+
20+
import com.tencent.polaris.api.exception.PolarisException;
21+
import com.tencent.polaris.auth.api.rpc.AuthRequest;
22+
import com.tencent.polaris.auth.api.rpc.AuthResponse;
23+
import com.tencent.polaris.client.flow.AbstractFlow;
24+
25+
public interface AuthFlow extends AbstractFlow {
26+
27+
/**
28+
* 鉴权
29+
*
30+
* @param authRequest 鉴权请求(服务及标签信息)
31+
* @return 鉴权通过情况
32+
* @throws PolarisException 异常信息
33+
*/
34+
default AuthResponse authenticate(AuthRequest authRequest) {
35+
return null;
36+
}
37+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package com.tencent.polaris.auth.api.rpc;
19+
20+
import com.tencent.polaris.api.rpc.RequestBaseEntity;
21+
import com.tencent.polaris.metadata.core.manager.MetadataContext;
22+
23+
/**
24+
* 鉴权请求
25+
*
26+
* @author Haotian Zhang
27+
*/
28+
public class AuthRequest extends RequestBaseEntity {
29+
30+
private final String namespace;
31+
32+
private final String service;
33+
34+
private final String path;
35+
36+
private final String protocol;
37+
38+
private final String method;
39+
40+
private final MetadataContext metadataContext;
41+
42+
public AuthRequest(String namespace, String service, String path, String protocol, String method, MetadataContext metadataContext) {
43+
this.namespace = namespace;
44+
this.service = service;
45+
this.path = path;
46+
this.protocol = protocol;
47+
this.method = method;
48+
this.metadataContext = metadataContext;
49+
}
50+
51+
public String getNamespace() {
52+
return namespace;
53+
}
54+
55+
public String getService() {
56+
return service;
57+
}
58+
59+
public String getPath() {
60+
return path;
61+
}
62+
63+
public String getProtocol() {
64+
return protocol;
65+
}
66+
67+
public String getMethod() {
68+
return method;
69+
}
70+
71+
public MetadataContext getMetadataContext() {
72+
return metadataContext;
73+
}
74+
75+
@Override
76+
public String toString() {
77+
return "AuthRequest{" +
78+
"namespace='" + namespace + '\'' +
79+
", service='" + service + '\'' +
80+
", path='" + path + '\'' +
81+
", protocol='" + protocol + '\'' +
82+
", method='" + method + '\'' +
83+
", metadataContext=" + metadataContext +
84+
'}';
85+
}
86+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package com.tencent.polaris.auth.api.rpc;
19+
20+
import com.tencent.polaris.api.plugin.auth.AuthResult;
21+
22+
/**
23+
* 鉴权响应
24+
*
25+
* @author Haotian Zhang
26+
*/
27+
public class AuthResponse {
28+
29+
private final AuthResult authResult;
30+
31+
public AuthResponse(AuthResult authResult) {
32+
this.authResult = authResult;
33+
}
34+
35+
public AuthResult getAuthResult() {
36+
return authResult;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return "AuthResponse{" +
42+
"authResult=" + authResult +
43+
'}';
44+
}
45+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>polaris-auth</artifactId>
7+
<groupId>com.tencent.polaris</groupId>
8+
<version>${revision}</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>polaris-auth-client</artifactId>
14+
<name>Polaris Auth Client</name>
15+
<description>Polaris Auth Client JAR</description>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.tencent.polaris</groupId>
20+
<artifactId>polaris-auth-api</artifactId>
21+
<version>${project.version}</version>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>org.slf4j</groupId>
26+
<artifactId>slf4j-api</artifactId>
27+
<version>${slf4j.version}</version>
28+
<scope>provided</scope>
29+
</dependency>
30+
</dependencies>
31+
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package com.tencent.polaris.auth.client.api;
19+
20+
import com.tencent.polaris.api.exception.PolarisException;
21+
import com.tencent.polaris.auth.api.core.AuthAPI;
22+
import com.tencent.polaris.auth.api.flow.AuthFlow;
23+
import com.tencent.polaris.auth.api.rpc.AuthRequest;
24+
import com.tencent.polaris.auth.api.rpc.AuthResponse;
25+
import com.tencent.polaris.auth.client.utils.AuthValidator;
26+
import com.tencent.polaris.client.api.BaseEngine;
27+
import com.tencent.polaris.client.api.SDKContext;
28+
29+
/**
30+
* 默认的鉴权API实现
31+
*
32+
* @author Haotian Zhang
33+
*/
34+
public class DefaultAuthAPI extends BaseEngine implements AuthAPI {
35+
36+
private AuthFlow authFlow;
37+
38+
public DefaultAuthAPI(SDKContext sdkContext) {
39+
super(sdkContext);
40+
}
41+
42+
@Override
43+
protected void subInit() {
44+
authFlow = sdkContext.getOrInitFlow(AuthFlow.class);
45+
}
46+
47+
@Override
48+
public AuthResponse authenticate(AuthRequest authRequest) throws PolarisException {
49+
checkAvailable("AuthFlow");
50+
AuthValidator.validateAuthRequest(authRequest);
51+
return authFlow.authenticate(authRequest);
52+
}
53+
}

0 commit comments

Comments
 (0)