Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions polaris-auth/polaris-auth-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>polaris-auth</artifactId>
<groupId>com.tencent.polaris</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>polaris-auth-api</artifactId>
<name>Polaris Auth API</name>
<description>Polaris Auth API JAR</description>

<dependencies>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>polaris-plugin-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>polaris-client</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package com.tencent.polaris.auth.api.core;

import com.tencent.polaris.api.exception.PolarisException;
import com.tencent.polaris.auth.api.rpc.AuthRequest;
import com.tencent.polaris.auth.api.rpc.AuthResponse;

import java.io.Closeable;

public interface AuthAPI extends AutoCloseable, Closeable {

/**
* 鉴权
*
* @param authRequest 鉴权请求(服务及标签信息)
* @return 鉴权通过情况
* @throws PolarisException 异常信息
*/
AuthResponse authenticate(AuthRequest authRequest) throws PolarisException;

/**
* 清理并释放资源
*/
void destroy();

@Override
default void close() {
destroy();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package com.tencent.polaris.auth.api.flow;

import com.tencent.polaris.api.exception.PolarisException;
import com.tencent.polaris.auth.api.rpc.AuthRequest;
import com.tencent.polaris.auth.api.rpc.AuthResponse;
import com.tencent.polaris.client.flow.AbstractFlow;

public interface AuthFlow extends AbstractFlow {

/**
* 鉴权
*
* @param authRequest 鉴权请求(服务及标签信息)
* @return 鉴权通过情况
* @throws PolarisException 异常信息
*/
default AuthResponse authenticate(AuthRequest authRequest) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package com.tencent.polaris.auth.api.rpc;

import com.tencent.polaris.api.rpc.RequestBaseEntity;
import com.tencent.polaris.metadata.core.manager.MetadataContext;

/**
* 鉴权请求
*
* @author Haotian Zhang
*/
public class AuthRequest extends RequestBaseEntity {

private final String namespace;

private final String service;

private final String path;

private final String protocol;

private final String method;

private final MetadataContext metadataContext;

public AuthRequest(String namespace, String service, String path, String protocol, String method, MetadataContext metadataContext) {
this.namespace = namespace;
this.service = service;
this.path = path;
this.protocol = protocol;
this.method = method;
this.metadataContext = metadataContext;
}

public String getNamespace() {
return namespace;
}

public String getService() {
return service;
}

public String getPath() {
return path;
}

public String getProtocol() {
return protocol;
}

public String getMethod() {
return method;
}

public MetadataContext getMetadataContext() {
return metadataContext;
}

@Override
public String toString() {
return "AuthRequest{" +
"namespace='" + namespace + '\'' +
", service='" + service + '\'' +
", path='" + path + '\'' +
", protocol='" + protocol + '\'' +
", method='" + method + '\'' +
", metadataContext=" + metadataContext +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package com.tencent.polaris.auth.api.rpc;

import com.tencent.polaris.api.plugin.auth.AuthResult;

/**
* 鉴权响应
*
* @author Haotian Zhang
*/
public class AuthResponse {

private final AuthResult authResult;

public AuthResponse(AuthResult authResult) {
this.authResult = authResult;
}

public AuthResult getAuthResult() {
return authResult;
}

@Override
public String toString() {
return "AuthResponse{" +
"authResult=" + authResult +
'}';
}
}
31 changes: 31 additions & 0 deletions polaris-auth/polaris-auth-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>polaris-auth</artifactId>
<groupId>com.tencent.polaris</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>polaris-auth-client</artifactId>
<name>Polaris Auth Client</name>
<description>Polaris Auth Client JAR</description>

<dependencies>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>polaris-auth-api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package com.tencent.polaris.auth.client.api;

import com.tencent.polaris.api.exception.PolarisException;
import com.tencent.polaris.auth.api.core.AuthAPI;
import com.tencent.polaris.auth.api.flow.AuthFlow;
import com.tencent.polaris.auth.api.rpc.AuthRequest;
import com.tencent.polaris.auth.api.rpc.AuthResponse;
import com.tencent.polaris.auth.client.utils.AuthValidator;
import com.tencent.polaris.client.api.BaseEngine;
import com.tencent.polaris.client.api.SDKContext;

/**
* 默认的鉴权API实现
*
* @author Haotian Zhang
*/
public class DefaultAuthAPI extends BaseEngine implements AuthAPI {

private AuthFlow authFlow;

public DefaultAuthAPI(SDKContext sdkContext) {
super(sdkContext);
}

@Override
protected void subInit() {
authFlow = sdkContext.getOrInitFlow(AuthFlow.class);
}

@Override
public AuthResponse authenticate(AuthRequest authRequest) throws PolarisException {
checkAvailable("AuthFlow");
AuthValidator.validateAuthRequest(authRequest);
return authFlow.authenticate(authRequest);
}
}
Loading
Loading