Skip to content

Commit

Permalink
Added option to provide specific redis username when initialising the…
Browse files Browse the repository at this point in the history
… adapter
  • Loading branch information
alordtas committed Mar 27, 2024
1 parent b487cc0 commit 353daba
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/main/java/org/casbin/adapter/RedisAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ public class RedisAdapter implements Adapter, BatchAdapter{
private String key;
private Jedis jedis;

public RedisAdapter(String host, int port) { newRedisAdapter(host, port, "casbin_rules", null); }
public RedisAdapter(String host, int port) { newRedisAdapter(host, port, "casbin_rules", null, null); }

public RedisAdapter(String host, int port, String password) {
newRedisAdapter(host, port, "casbin_rules", password);
newRedisAdapter(host, port, "casbin_rules", null, password);

Check warning on line 43 in src/main/java/org/casbin/adapter/RedisAdapter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/adapter/RedisAdapter.java#L43

Added line #L43 was not covered by tests
}

public RedisAdapter(String host, int port, String key, String password) {
newRedisAdapter(host, port, key, password);
newRedisAdapter(host, port, key, null, password);
}

Check warning on line 48 in src/main/java/org/casbin/adapter/RedisAdapter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/adapter/RedisAdapter.java#L47-L48

Added lines #L47 - L48 were not covered by tests

public RedisAdapter(String host, int port, String key, String username, String password) {
newRedisAdapter(host, port, key, username, password);

Check warning on line 51 in src/main/java/org/casbin/adapter/RedisAdapter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/adapter/RedisAdapter.java#L50-L51

Added lines #L50 - L51 were not covered by tests
}

/**
Expand Down Expand Up @@ -159,12 +163,17 @@ public void selectDb(int dbIndex) {
}
}

private void newRedisAdapter(String host, int port, String key, String password) {
private void newRedisAdapter(String host, int port, String key, String username, String password) {
this.key = key;

jedis = new Jedis(host, port);
if (password != null) {
jedis.auth(password);
if (username != null) {
jedis.auth(username, password);

Check warning on line 172 in src/main/java/org/casbin/adapter/RedisAdapter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/adapter/RedisAdapter.java#L172

Added line #L172 was not covered by tests
}
else {
jedis.auth(password);

Check warning on line 175 in src/main/java/org/casbin/adapter/RedisAdapter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/adapter/RedisAdapter.java#L175

Added line #L175 was not covered by tests
}
}

Util.logPrintf("Redis service is running ", jedis.ping());
Expand Down

0 comments on commit 353daba

Please sign in to comment.