Skip to content

Commit 5051bf0

Browse files
[ZEPPELIN-6251] Refactor AuthenticationService binding using factory method
### What is this PR for? This PR refactors the conditional binding logic for AuthenticationService in ZeppelinServer.java. Previously, the binding decision between ShiroAuthenticationService and NoAuthenticationService was handled via an inline if-else block. To improve readability and maintainability, this logic has been moved to a new AuthenticationServiceFactory class that encapsulates the decision process. This change simplifies the server initialization logic and promotes better separation of concerns. ### What type of PR is it? Refactoring ### Todos * [x] - Add AuthenticationServiceFactory class * [x] - Replace inline if-else binding logic in ZeppelinServer ### What is the Jira issue? * Jira: https://issues.apache.org/jira/browse/ZEPPELIN-6251 ### How should this be tested? There should be no functional change. ### Screenshots (if appropriate) N/A ### Questions: * Does the license files need to update? No. * Is there breaking changes for older versions? No. * Does this needs documentation? No. Closes #4988 from ParkGyeongTae/ZEPPELIN-6251. Signed-off-by: Philipp Dallig <philipp.dallig@gmail.com>
1 parent e4f4cc8 commit 5051bf0

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
import org.apache.zeppelin.search.SearchService;
9393
import org.apache.zeppelin.service.*;
9494
import org.apache.zeppelin.service.AuthenticationService;
95+
import org.apache.zeppelin.service.auth.AuthenticationServiceFactory;
9596
import org.apache.zeppelin.socket.ConnectionManager;
9697
import org.apache.zeppelin.socket.NotebookServer;
9798
import org.apache.zeppelin.socket.SessionConfigurator;
@@ -188,13 +189,9 @@ protected void configure() {
188189
bindAsContract(AuthorizationService.class).in(Singleton.class);
189190
bindAsContract(ConnectionManager.class).in(Singleton.class);
190191
bindAsContract(NoteManager.class).in(Singleton.class);
191-
// TODO(jl): Will make it more beautiful
192-
if (!StringUtils.isBlank(zConf.getShiroPath())) {
193-
bind(ShiroAuthenticationService.class).to(AuthenticationService.class).in(Singleton.class);
194-
} else {
195-
// TODO(jl): Will be added more type
196-
bind(NoAuthenticationService.class).to(AuthenticationService.class).in(Singleton.class);
197-
}
192+
bind(AuthenticationServiceFactory.getAuthServiceClass(zConf))
193+
.to(AuthenticationService.class)
194+
.in(Singleton.class);
198195
bindAsContract(HeliumBundleFactory.class).in(Singleton.class);
199196
bindAsContract(HeliumApplicationFactory.class).in(Singleton.class);
200197
bindAsContract(ConfigurationService.class).in(Singleton.class);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.zeppelin.service.auth;
19+
20+
import org.apache.zeppelin.conf.ZeppelinConfiguration;
21+
import org.apache.zeppelin.service.AuthenticationService;
22+
import org.apache.zeppelin.service.NoAuthenticationService;
23+
import org.apache.zeppelin.service.ShiroAuthenticationService;
24+
25+
public class AuthenticationServiceFactory {
26+
27+
public static Class<? extends AuthenticationService> getAuthServiceClass(ZeppelinConfiguration zConf) {
28+
if (!zConf.getShiroPath().isBlank()) {
29+
return ShiroAuthenticationService.class;
30+
} else {
31+
return NoAuthenticationService.class;
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)