|
17 | 17 |
|
18 | 18 | import java.io.File;
|
19 | 19 | import java.io.IOException;
|
| 20 | +import java.lang.reflect.Constructor; |
| 21 | +import java.lang.reflect.InvocationTargetException; |
20 | 22 | import java.text.MessageFormat;
|
21 | 23 | import java.util.ArrayList;
|
22 | 24 | import java.util.Collection;
|
@@ -119,15 +121,33 @@ public UserManager start() {
|
119 | 121 | // typical file path configuration
|
120 | 122 | File realmFile = runtimeManager.getFileOrFolder(Keys.realm.userService, "${baseFolder}/users.conf");
|
121 | 123 | service = createUserService(realmFile);
|
122 |
| - } catch (InstantiationException | IllegalAccessException e) { |
123 |
| - logger.error("failed to instantiate user service {}: {}", realm, e.getMessage()); |
| 124 | + } catch (InstantiationException | IllegalAccessException e) { |
| 125 | + logger.error("failed to instantiate user service {}: {}. Trying once again with IRuntimeManager constructor", realm, e.getMessage()); |
| 126 | + //try once again with IRuntimeManager constructor. This adds support for subclasses of ConfigUserService and other custom IUserServices |
| 127 | + service = createIRuntimeManagerAwareUserService(realm); |
124 | 128 | }
|
125 | 129 | }
|
126 | 130 | setUserService(service);
|
127 | 131 | }
|
128 | 132 | return this;
|
129 | 133 | }
|
130 | 134 |
|
| 135 | + /** |
| 136 | + * Tries to create an {@link IUserService} with {@link #runtimeManager} as a constructor parameter |
| 137 | + * |
| 138 | + * @param realm the class name of the {@link IUserService} to be instantiated |
| 139 | + * @return the {@link IUserService} or {@code null} if instantiation fails |
| 140 | + */ |
| 141 | + private IUserService createIRuntimeManagerAwareUserService(String realm) { |
| 142 | + try { |
| 143 | + Constructor<?> constructor = Class.forName(realm).getConstructor(IRuntimeManager.class); |
| 144 | + return (IUserService) constructor.newInstance(runtimeManager); |
| 145 | + } catch (NoSuchMethodException | SecurityException | ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { |
| 146 | + logger.error("failed to instantiate user service {}: {}", realm, e.getMessage()); |
| 147 | + return null; |
| 148 | + } |
| 149 | + } |
| 150 | + |
131 | 151 | protected IUserService createUserService(File realmFile) {
|
132 | 152 | IUserService service = null;
|
133 | 153 | if (realmFile.getName().toLowerCase().endsWith(".conf")) {
|
|
0 commit comments