File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
src/main/java/com/gitblit Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 2626 * Implementations of IUserService control all aspects of UserModel objects and
2727 * user authentication.
2828 *
29+ * Plugins implementing this interface (which are instantiated during {@link com.gitblit.manager.UserManager#start()}) can provide
30+ * a default constructor or might also use {@link IRuntimeManager} as a constructor argument which will be passed automatically then.
31+ *
2932 * @author James Moger
3033 *
3134 */
Original file line number Diff line number Diff line change 1717
1818import java .io .File ;
1919import java .io .IOException ;
20+ import java .lang .reflect .Constructor ;
21+ import java .lang .reflect .InvocationTargetException ;
2022import java .text .MessageFormat ;
2123import java .util .ArrayList ;
2224import java .util .Collection ;
@@ -119,8 +121,15 @@ public UserManager start() {
119121 // typical file path configuration
120122 File realmFile = runtimeManager .getFileOrFolder (Keys .realm .userService , "${baseFolder}/users.conf" );
121123 service = createUserService (realmFile );
122- } catch (InstantiationException | IllegalAccessException e ) {
123- logger .error ("failed to instantiate user service {}: {}" , realm , e .getMessage ());
124+ } catch (InstantiationException | IllegalAccessException e1 ) {
125+ logger .error ("failed to instantiate user service {}: {}. Trying once again with IRuntimeManager constructor" , realm , e1 .getMessage ());
126+ //try once again with file constructor. this adds support for subclasses of ConfigUserService
127+ try {
128+ Constructor <?> constructor = Class .forName (realm ).getConstructor (IRuntimeManager .class );
129+ service = (IUserService ) constructor .newInstance (runtimeManager );
130+ } catch (NoSuchMethodException | SecurityException | ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e2 ) {
131+ logger .error ("failed to instantiate user service {}: {}" , realm , e2 .getMessage ());
132+ }
124133 }
125134 }
126135 setUserService (service );
You can’t perform that action at this time.
0 commit comments