-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Support mariadb datasource #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49e2499
feat: add support for mariadb datasource, added unit test, added cons…
happenedIn 41a57fe
feat: simplify check for database types
happenedIn 685e2de
feat: simplify tests to use mariadb datasource
happenedIn 2926a9b
feat: changes from feedback
happenedIn 6db7900
feat: add apache license header
happenedIn f69accd
Update HibernateAdapterDatasourceTest.java
hsluoyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
src/test/java/org/casbin/test/HibernateAdapterDatasourceTest.java
This file contains hidden or 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,36 @@ | ||
package org.casbin.test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import java.sql.SQLException; | ||
import org.casbin.adapter.HibernateAdapter; | ||
import org.casbin.jcasbin.main.Enforcer; | ||
import org.junit.Test; | ||
import org.mariadb.jdbc.MariaDbDataSource; | ||
|
||
public class HibernateAdapterDatasourceTest { | ||
|
||
private static final String URL = "jdbc:mariadb://localhost:3306/casbin?serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true"; | ||
private static final String USERNAME = "root"; | ||
private static final String PASSWORD = "casbin_test"; | ||
|
||
@Test | ||
public void testInitDBfromMariaDBDatasource() throws SQLException { | ||
MariaDbDataSource mariaDbDataSource = new MariaDbDataSource(); | ||
mariaDbDataSource.setUrl(URL); | ||
mariaDbDataSource.setUser(USERNAME); | ||
mariaDbDataSource.setPassword(PASSWORD); | ||
|
||
Enforcer e = new Enforcer("examples/rbac_with_domains_model.conf", new HibernateAdapter(mariaDbDataSource)); | ||
hsluoyz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
e.savePolicy(); //clear table | ||
|
||
e.addPolicy("admin", "domain1", "data1", "read"); | ||
e.addGroupingPolicy("alice", "admin", "domain1"); | ||
|
||
testDomainEnforce(e, "alice", "domain1", "data1", "read", true); | ||
} | ||
|
||
private void testDomainEnforce(Enforcer e, String sub, String dom, String obj, String act, boolean res) { | ||
assertEquals(res, e.enforce(sub, dom, obj, act)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.