Skip to content

Commit

Permalink
fix: rename package and improve ci
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan Liu <nodeces@gmail.com>
  • Loading branch information
nodece committed May 21, 2022
1 parent 4ac0027 commit 0349994
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 27 deletions.
23 changes: 15 additions & 8 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,35 @@ on: [ push, pull_request ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 11, 17 ]
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: maven
- name: Build and test with Maven
run: mvn --batch-mode --update-snapshots verify
- name: Build
run: mvn -B clean install -DskipTests

integration-test:
timeout-minutes: 5
runs-on: ubuntu-latest
strategy:
matrix:
pulsar: [ 2.9.2, 2.10.0 ]
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn --batch-mode --update-snapshots clean package
- name: Run integration test
run: integration-test/run-integration-test.sh
env:
PULSAR_VERSION: ${{ matrix.pulsar }}
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# pulsar-casbin-authz
# Pulsar-authz

An authorization plugin for pulsar broker based on casbin.
An authorization plugin for Apache Pulsar.

## TODO
**Note:** This plugin requires Pulsar 2.9 or higher.

- [ ] add integration tests
### Enable Casbin authorization on Broker

```ini
authorizationEnabled=true
authorizationProvider=org.casbin.pulsar.authorization.AuthorizationProvider
```
3 changes: 2 additions & 1 deletion integration-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM apachepulsar/pulsar:latest
ARG PULSAR_VERSION
FROM apachepulsar/pulsar:$PULSAR_VERSION

COPY target/*-shade.jar /pulsar/lib/
COPY integration-test/my-secret.key /pulsar/conf/
Expand Down
6 changes: 4 additions & 2 deletions integration-test/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
version: "2.4"
services:
pulsar-casbin-authz-intergation-test:
container_name: pulsar-casbin-authz-intergation-test
casbin-pulsar-authz-intergation-test:
container_name: casbin-pulsar-authz-intergation-test
build:
context: ../
dockerfile: integration-test/Dockerfile
args:
PULSAR_VERSION: ${PULSAR_VERSION}
ports:
- 8080:8080
- 6650:6650
2 changes: 1 addition & 1 deletion integration-test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export PULSAR_PREFIX_tokenSecretKey=file:///pulsar/conf/my-secret.key
# authorization for broker
export PULSAR_PREFIX_authorizationEnabled=true
export PULSAR_PREFIX_superUserRoles=admin
export PULSAR_PREFIX_authorizationProvider=com.github.nodece.pulsar.casbin.authz.AuthorizationProvider
export PULSAR_PREFIX_authorizationProvider=org.casbin.pulsar.authorization.AuthorizationProvider

# authorization for client
export PULSAR_PREFIX_brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.AuthenticationToken
Expand Down
4 changes: 2 additions & 2 deletions integration-test/run-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ set -e
ROOT=$(git rev-parse --show-toplevel)
cd "${ROOT}"

mvn --batch-mode --update-snapshots clean package -DskipTests
mvn -B clean package -DskipTests
docker-compose -f integration-test/docker-compose.yaml up --remove-orphan --build --force-recreate -d

CONTAINER_NAME="pulsar-casbin-authz-intergation-test"
CONTAINER_NAME="casbin-pulsar-authz-intergation-test"
PULSAR_ADMIN="docker exec -d ${CONTAINER_NAME} /pulsar/bin/pulsar-admin"

echo "Waiting for Pulsar service ..."
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.nodece</groupId>
<artifactId>pulsar-casbin-authz</artifactId>
<groupId>org.casbin.pulsar.authorization</groupId>
<artifactId>casbin-pulsar-authz</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.nodece.pulsar.casbin.authz;
package org.casbin.pulsar.authorization;

import static com.google.common.base.Preconditions.checkNotNull;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -341,10 +341,10 @@ private CompletableFuture<Void> addPolicy(Set<String> subjects, TopicName topicN
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).whenComplete((__, ex) -> {
if (ex == null) {
log.info("Successfully granted access for role {} on topic {}: {} {}", subjects,
topicName.getPartitionedTopicName(), actions, AuthorizationProvider.DEFAULT_FILL);
topicName.getPartitionedTopicName(), actions, DEFAULT_FILL);
} else {
log.error("Failed to grant access for role {} on topic {}: {} {}", subjects,
topicName.getPartitionedTopicName(), actions, AuthorizationProvider.DEFAULT_FILL, ex);
topicName.getPartitionedTopicName(), actions, DEFAULT_FILL, ex);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.github.nodece.pulsar.casbin.authz;
package integrations;

import static org.assertj.core.api.Assertions.assertThat;
import java.nio.charset.StandardCharsets;
import java.util.Random;
import lombok.Cleanup;
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.api.PulsarClient;
Expand All @@ -13,6 +10,12 @@
import org.testng.annotations.Test;
import org.testng.collections.Sets;

import java.nio.charset.StandardCharsets;
import java.util.Random;

import static org.assertj.core.api.Assertions.assertThat;

@Test(groups = "integrations")
public class AuthTest {
private final String ADMIN_TOKEN =
"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiJ9.mAEZVpz87oZ7vXsqLl-Ue8P9I4SOhqIF7nf8n1f5TZc";
Expand Down

0 comments on commit 0349994

Please sign in to comment.