Skip to content

Commit

Permalink
[ISSUE apache#9133] Credentials enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
zeyu-zh committed Jan 15, 2025
1 parent 14ca1ce commit 3ffbca0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@
import static org.apache.rocketmq.acl.common.SessionCredentials.SIGNATURE;

public class AclClientRPCHook implements RPCHook {
private final SessionCredentials sessionCredentials;
private final SessionCredentialsProvider sessionCredentialsProvider;

public AclClientRPCHook(SessionCredentials sessionCredentials) {
this.sessionCredentials = sessionCredentials;
this.sessionCredentialsProvider = new StaticSessionCredentialsProvider(sessionCredentials);
}

public AclClientRPCHook(SessionCredentialsProvider sessionCredentialsProvider) {
this.sessionCredentialsProvider = sessionCredentialsProvider;
}

@Override
public void doBeforeRequest(String remoteAddr, RemotingCommand request) {
SessionCredentials sessionCredentials = this.sessionCredentialsProvider.getSessionCredentials();
// Add AccessKey and SecurityToken into signature calculating.
request.addExtField(ACCESS_KEY, sessionCredentials.getAccessKey());
// The SecurityToken value is unnecessary,user can choose this one.
Expand All @@ -59,6 +64,6 @@ protected SortedMap<String, String> parseRequestContent(RemotingCommand request)
}

public SessionCredentials getSessionCredentials() {
return sessionCredentials;
return this.sessionCredentialsProvider.getSessionCredentials();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.apache.rocketmq.acl.common;

public interface SessionCredentialsProvider {
SessionCredentials getSessionCredentials();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.apache.rocketmq.acl.common;

public class StaticSessionCredentialsProvider implements SessionCredentialsProvider {
private final SessionCredentials sessionCredentials;

public StaticSessionCredentialsProvider(SessionCredentials sessionCredentials) {
this.sessionCredentials = sessionCredentials;
}

@Override
public SessionCredentials getSessionCredentials() {
return this.sessionCredentials;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class AclClientRPCHookTest {
protected ConcurrentHashMap<Class<? extends CommandCustomHeader>, Field[]> fieldCache =
new ConcurrentHashMap<>();
private AclClientRPCHook aclClientRPCHook = new AclClientRPCHook(null);
private AclClientRPCHook aclClientRPCHook = new AclClientRPCHook((SessionCredentials) null);

@Test
public void testParseRequestContent() {
Expand Down

0 comments on commit 3ffbca0

Please sign in to comment.