You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/10/27 05:17:24 UTC
[GitHub] [pulsar] codelipenghui commented on a diff in pull request #18130: [fix][broker] Fix update authentication data
codelipenghui commented on code in PR #18130:
URL: https://github.com/apache/pulsar/pull/18130#discussion_r1006411215
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java:
##########
@@ -676,73 +678,90 @@ private void completeConnect(int clientProtoVersion, String clientVersion, boole
}
// According to auth result, send newConnected or newAuthChallenge command.
- private State doAuthentication(AuthData clientData,
- int clientProtocolVersion,
- String clientVersion) throws Exception {
+ private CompletableFuture<Void> doAuthentication(AuthData clientData, int clientProtocolVersion,
+ String clientVersion) throws AuthenticationException {
+ boolean useOriginalAuthState = (originalAuthState != null);
+ if (state == State.Connected) {
+ // For auth challenge, the authentication state requires to be updated.
+ if (log.isDebugEnabled()) {
+ log.debug("Refreshing authenticate state, original auth state: {}, original auth role: {}, "
+ + "auth role: {}",
+ useOriginalAuthState, originalPrincipal, authRole);
+ }
+ if (useOriginalAuthState) {
+ originalAuthState = originalAuthenticationProvider.newAuthState(clientData, remoteAddress, sslSession);
+ } else {
+ authState = authenticationProvider.newAuthState(clientData, remoteAddress, sslSession);
+ }
+ }
// The original auth state can only be set on subsequent auth attempts (and only
// in presence of a proxy and if the proxy is forwarding the credentials).
// In this case, the re-validation needs to be done against the original client
// credentials.
- boolean useOriginalAuthState = (originalAuthState != null);
- AuthenticationState authState = useOriginalAuthState ? originalAuthState : this.authState;
+ AuthenticationState authState = useOriginalAuthState ? originalAuthState : this.authState;
String authRole = useOriginalAuthState ? originalPrincipal : this.authRole;
- AuthData brokerData = authState.authenticate(clientData);
-
- if (log.isDebugEnabled()) {
- log.debug("Authenticate using original auth state : {}, role = {}", useOriginalAuthState, authRole);
- }
- if (authState.isComplete()) {
- // Authentication has completed. It was either:
- // 1. the 1st time the authentication process was done, in which case we'll send
- // a `CommandConnected` response
- // 2. an authentication refresh, in which case we need to refresh authenticationData
-
- String newAuthRole = authState.getAuthRole();
-
- // Refresh the auth data.
- this.authenticationData = authState.getAuthDataSource();
- if (log.isDebugEnabled()) {
- log.debug("[{}] Auth data refreshed for role={}", remoteAddress, this.authRole);
- }
-
- if (!useOriginalAuthState) {
- this.authRole = newAuthRole;
- }
-
- if (log.isDebugEnabled()) {
- log.debug("[{}] Client successfully authenticated with {} role {} and originalPrincipal {}",
- remoteAddress, authMethod, this.authRole, originalPrincipal);
- }
+ CompletableFuture<AuthData> authFuture;
+ if (!authState.isComplete()) {
+ authFuture = authState.authenticateAsync(clientData);
Review Comment:
We can just avoid cherry-pick this PR into branch-2.9 and branch-2.10 directly. Instead, we can create separate PRs for branch-2.9 and branch-2.10.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org