nodece commented on code in PR #19359:
URL: https://github.com/apache/pulsar/pull/19359#discussion_r1093971890
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderBasic.java:
##########
@@ -177,4 +196,55 @@ public String getPassword() {
return password;
}
}
+
+ private static class BasicAuthenticationState implements
AuthenticationState {
+
+ private final AuthenticationProviderBasic authenticationProvider;
+ private final SocketAddress remoteAddress;
+ private final SSLSession sslSession;
+ private String role;
+ private AuthenticationDataSource authenticationDataSource;
+
+ public BasicAuthenticationState(SocketAddress remoteAddress,
SSLSession sslSession,
+ AuthenticationProviderBasic
authenticationProvider) {
+ this.remoteAddress = remoteAddress;
+ this.sslSession = sslSession;
+ this.authenticationProvider = authenticationProvider;
+ }
+
+ @Override
+ public String getAuthRole() throws AuthenticationException {
+ if (authenticationDataSource == null) {
+ throw new AuthenticationException("Must authenticate before
calling getAuthRole");
+ }
+
+ return role;
+ }
+
+ @Override
+ public AuthData authenticate(AuthData authData) throws
AuthenticationException {
+ AuthenticationDataSource dataSource =
+ new AuthenticationDataCommand(new
String(authData.getBytes(), StandardCharsets.UTF_8),
+ remoteAddress, sslSession);
+ role = authenticationProvider.authenticationBasic(dataSource);
+ authenticationDataSource = dataSource;
+
+ return null;
+ }
+
+ @Override
+ public AuthenticationDataSource getAuthDataSource() {
+ return authenticationDataSource;
+ }
+
+ @Override
+ public boolean isComplete() {
+ return authenticationDataSource != null;
+ }
+
+ @Override
+ public boolean isExpired() {
+ return false;
+ }
Review Comment:
Good explanation!
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]