diff options
author | de4c9d <martin.spielmann@kiongroup.com> | 2016-12-30 17:09:16 +0100 |
---|---|---|
committer | de4c9d <martin.spielmann@kiongroup.com> | 2016-12-30 18:12:27 +0100 |
commit | da6a2611ed8cb73856ad41a39a322596fdd9ea05 (patch) | |
tree | 7475c5a1a605a6fc37aee13f192f4cf914fccc11 /src/main | |
parent | 99b4a1898f0c3533062263cda18b456f099ee2cf (diff) | |
download | gitblit-da6a2611ed8cb73856ad41a39a322596fdd9ea05.tar.gz gitblit-da6a2611ed8cb73856ad41a39a322596fdd9ea05.zip |
update user manager to support instantiation if IUserService with IRuntimeManager as a parameter
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/gitblit/IUserService.java | 3 | ||||
-rw-r--r-- | src/main/java/com/gitblit/manager/UserManager.java | 13 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/main/java/com/gitblit/IUserService.java b/src/main/java/com/gitblit/IUserService.java index 6f3c5423..468f968f 100644 --- a/src/main/java/com/gitblit/IUserService.java +++ b/src/main/java/com/gitblit/IUserService.java @@ -26,6 +26,9 @@ import com.gitblit.models.UserModel; * Implementations of IUserService control all aspects of UserModel objects and
* user authentication.
*
+ * Plugins implementing this interface (which are instantiated during {@link com.gitblit.manager.UserManager#start()}) can provide
+ * a default constructor or might also use {@link IRuntimeManager} as a constructor argument which will be passed automatically then.
+ *
* @author James Moger
*
*/
diff --git a/src/main/java/com/gitblit/manager/UserManager.java b/src/main/java/com/gitblit/manager/UserManager.java index e88ac93c..ba0cb35e 100644 --- a/src/main/java/com/gitblit/manager/UserManager.java +++ b/src/main/java/com/gitblit/manager/UserManager.java @@ -17,6 +17,8 @@ package com.gitblit.manager; import java.io.File; import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; @@ -119,8 +121,15 @@ 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 e) { - logger.error("failed to instantiate user service {}: {}", realm, e.getMessage()); + } catch (InstantiationException | IllegalAccessException e1) { + logger.error("failed to instantiate user service {}: {}. Trying once again with IRuntimeManager constructor", realm, e1.getMessage()); + //try once again with file constructor. this adds support for subclasses of ConfigUserService + 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()); + } } } setUserService(service); |