forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIP-30: interface for mutual authentication (apache#3677)
This is to implement the mutual auth api discussed in "PIP-30: change authentication provider API to support mutual authentication" Mainly provide 2 new command CommandAuthResponse and CommandAuthChallenge in proto, to support it.
- Loading branch information
Showing
17 changed files
with
2,411 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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 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 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
53 changes: 53 additions & 0 deletions
53
...ker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationState.java
This file contains 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,53 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.pulsar.broker.authentication; | ||
|
||
import javax.naming.AuthenticationException; | ||
import org.apache.pulsar.common.api.AuthData; | ||
|
||
/** | ||
* Interface for authentication state. | ||
* | ||
* It tell broker whether the authentication is completed or not, | ||
* if completed, what is the AuthRole is. | ||
*/ | ||
public interface AuthenticationState { | ||
/** | ||
* After the authentication between client and broker completed, | ||
* get authentication role represent for the client. | ||
* It should throw exception if auth not complete. | ||
*/ | ||
String getAuthRole() throws AuthenticationException; | ||
|
||
/** | ||
* Challenge passed in auth data and get response data. | ||
*/ | ||
AuthData authenticate(AuthData authData) throws AuthenticationException; | ||
|
||
/** | ||
* Return AuthenticationDataSource. | ||
*/ | ||
AuthenticationDataSource getAuthDataSource(); | ||
|
||
/** | ||
* Whether the authentication is completed or not | ||
*/ | ||
boolean isComplete(); | ||
} |
68 changes: 68 additions & 0 deletions
68
...on/src/main/java/org/apache/pulsar/broker/authentication/OneStageAuthenticationState.java
This file contains 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,68 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.pulsar.broker.authentication; | ||
|
||
import java.net.SocketAddress; | ||
import javax.naming.AuthenticationException; | ||
import javax.net.ssl.SSLSession; | ||
import org.apache.pulsar.common.api.AuthData; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
/** | ||
* Interface for authentication state. | ||
* | ||
* It tell broker whether the authentication is completed or not, | ||
* if completed, what is the AuthRole is. | ||
*/ | ||
public class OneStageAuthenticationState implements AuthenticationState { | ||
|
||
private final AuthenticationDataSource authenticationDataSource; | ||
private final String authRole; | ||
|
||
public OneStageAuthenticationState(AuthData authData, | ||
SocketAddress remoteAddress, | ||
SSLSession sslSession, | ||
AuthenticationProvider provider) throws AuthenticationException { | ||
this.authenticationDataSource = new AuthenticationDataCommand( | ||
new String(authData.getBytes(), UTF_8), remoteAddress, sslSession);; | ||
this.authRole = provider.authenticate(authenticationDataSource); | ||
} | ||
|
||
@Override | ||
public String getAuthRole() { | ||
return authRole; | ||
} | ||
|
||
@Override | ||
public AuthenticationDataSource getAuthDataSource() { | ||
return authenticationDataSource; | ||
} | ||
|
||
@Override | ||
public AuthData authenticate(AuthData authData) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isComplete() { | ||
return true; | ||
} | ||
} |
Oops, something went wrong.