diff options
author | Martin Spielmann <martin.spielmann@pingunaut.com> | 2017-01-06 01:09:37 +0100 |
---|---|---|
committer | Martin Spielmann <martin.spielmann@pingunaut.com> | 2017-01-06 01:09:37 +0100 |
commit | d79f5630c82a0d89ec5b2d3a1f0365bf72668a78 (patch) | |
tree | 9001acce02ffcd38fb5110aca6f801ba7992917a | |
parent | a6ae27a472af1260ab078edb7199f60086b56a4b (diff) | |
download | gitblit-d79f5630c82a0d89ec5b2d3a1f0365bf72668a78.tar.gz gitblit-d79f5630c82a0d89ec5b2d3a1f0365bf72668a78.zip |
extracted method
-rw-r--r-- | src/main/java/com/gitblit/manager/UserManager.java | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/main/java/com/gitblit/manager/UserManager.java b/src/main/java/com/gitblit/manager/UserManager.java index 2e68e40d..d661c9b4 100644 --- a/src/main/java/com/gitblit/manager/UserManager.java +++ b/src/main/java/com/gitblit/manager/UserManager.java @@ -121,15 +121,10 @@ public class UserManager implements IUserManager { // typical file path configuration File realmFile = runtimeManager.getFileOrFolder(Keys.realm.userService, "${baseFolder}/users.conf"); service = createUserService(realmFile); - } catch (InstantiationException | IllegalAccessException e1) { - logger.error("failed to instantiate user service {}: {}. Trying once again with IRuntimeManager constructor", realm, e1.getMessage()); - //try once again with IRuntimeManager constructor. This adds support for subclasses of ConfigUserService and other custom IUserServices - try { - Constructor<?> constructor = Class.forName(realm).getConstructor(IRuntimeManager.class); - service = (IUserService) constructor.newInstance(runtimeManager); - } catch (NoSuchMethodException | SecurityException | ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e2) { - logger.error("failed to instantiate user service {}: {}", realm, e2.getMessage()); - } + } catch (InstantiationException | IllegalAccessException e) { + logger.error("failed to instantiate user service {}: {}. Trying once again with IRuntimeManager constructor", realm, e.getMessage()); + //try once again with IRuntimeManager constructor. This adds support for subclasses of ConfigUserService and other custom IUserServices + service = createIRuntimeManagerAwareUserService(realm); } } setUserService(service); @@ -137,6 +132,22 @@ public class UserManager implements IUserManager { return this; } + /** + * Tries to create an {@link IUserService} with {@link #runtimeManager} as a constructor parameter + * + * @param realm the class name of the {@link IUserService} to be instantiated + * @return the {@link IUserService} or {@code null} if instantiation fails + */ + private IUserService createIRuntimeManagerAwareUserService(String realm) { + try { + Constructor<?> constructor = Class.forName(realm).getConstructor(IRuntimeManager.class); + return (IUserService) constructor.newInstance(runtimeManager); + } catch (NoSuchMethodException | SecurityException | ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + logger.error("failed to instantiate user service {}: {}", realm, e.getMessage()); + return null; + } + } + protected IUserService createUserService(File realmFile) { IUserService service = null; if (realmFile.getName().toLowerCase().endsWith(".conf")) { |