-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: RBAC Subject and Cluster level binding
- Loading branch information
Ludovic BOUTROS
committed
Jul 9, 2021
1 parent
73c18ea
commit 151cae4
Showing
7 changed files
with
92 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/purbon/kafka/topology/api/mds/MDSRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.purbon.kafka.topology.api.mds; | ||
|
||
public class MDSRequest { | ||
private final String url; | ||
private final String jsonEntity; | ||
|
||
public MDSRequest(String url, String jsonEntity) { | ||
this.url = url; | ||
this.jsonEntity = jsonEntity; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public String getJsonEntity() { | ||
return jsonEntity; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/test/java/com/purbon/kafka/topology/api/mds/MDSApiClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.purbon.kafka.topology.api.mds; | ||
|
||
import static com.purbon.kafka.topology.roles.rbac.RBACPredefinedRoles.DEVELOPER_READ; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
import com.purbon.kafka.topology.roles.TopologyAclBinding; | ||
import org.junit.Test; | ||
|
||
public class MDSApiClientTest { | ||
MDSApiClient apiClient = new MDSApiClient("http://not_used:8090"); | ||
|
||
@Test | ||
public void testBindSubjectRole() { | ||
String principal = "User:foo"; | ||
String subject = "topic-value"; | ||
|
||
TopologyAclBinding binding = | ||
apiClient | ||
.bind(principal, DEVELOPER_READ) | ||
.forSchemaSubject(subject) | ||
.apply("Subject", subject); | ||
|
||
MDSRequest mdsRequest = apiClient.buildRequest(binding); | ||
|
||
assertThat(mdsRequest.getUrl()).isEqualTo("User:foo/roles/DeveloperRead/bindings"); | ||
assertThat(mdsRequest.getJsonEntity()) | ||
.isEqualTo( | ||
"{\"resourcePatterns\":[{\"name\":\"Subject:topic-value\",\"patternType\":\"LITERAL\",\"resourceType\":\"Subject\"}],\"scope\":{\"clusters\":{\"kafka-cluster\":\"\",\"schema-registry-cluster\":\"\"}}}"); | ||
} | ||
|
||
@Test | ||
public void testBindSubjectRoleWithoutResourceType() { | ||
String principal = "User:foo"; | ||
String subject = "topic-value"; | ||
|
||
TopologyAclBinding binding = | ||
apiClient.bind(principal, DEVELOPER_READ).forSchemaSubject(subject).apply(); | ||
|
||
MDSRequest mdsRequest = apiClient.buildRequest(binding); | ||
|
||
assertThat(mdsRequest.getUrl()).isEqualTo("User:foo/roles/DeveloperRead/bindings"); | ||
assertThat(mdsRequest.getJsonEntity()) | ||
.isEqualTo( | ||
"{\"resourcePatterns\":[{\"name\":\"Subject:topic-value\",\"patternType\":\"LITERAL\",\"resourceType\":\"Subject\"}],\"scope\":{\"clusters\":{\"kafka-cluster\":\"\",\"schema-registry-cluster\":\"\"}}}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters