Skip to content

Commit 30de21d

Browse files
tulinkryVladimir Kotal
authored andcommitted
perform any necessary action when the configuration is read from a file (#1616)
fixes #1609
1 parent 273207d commit 30de21d

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ public final class RuntimeEnvironment {
132132
private Statistics statistics = new Statistics();
133133

134134
/**
135-
* Instance of authorization framework. Allowing every request by default.
135+
* Instance of authorization framework.
136136
*/
137-
private AuthorizationFramework authFramework = new AuthorizationFramework(null);
137+
private AuthorizationFramework authFramework;
138138

139139
/* Get thread pool used for top-level repository history generation. */
140140
public static synchronized ExecutorService getHistoryExecutor() {
@@ -1552,15 +1552,18 @@ public void loadStatistics(InputStream in) throws IOException, ParseException {
15521552
* @see AuthorizationFramework#getPluginVersion()
15531553
*/
15541554
public int getPluginVersion() {
1555-
return authFramework.getPluginVersion();
1555+
return getAuthorizationFramework().getPluginVersion();
15561556
}
15571557

15581558
/**
15591559
* Return the authorization framework used in this environment.
15601560
*
15611561
* @return the framework
15621562
*/
1563-
public AuthorizationFramework getAuthorizationFramework() {
1563+
synchronized public AuthorizationFramework getAuthorizationFramework() {
1564+
if (authFramework == null) {
1565+
authFramework = new AuthorizationFramework(threadConfig.get().getPluginDirectory());
1566+
}
15641567
return authFramework;
15651568
}
15661569

@@ -1570,7 +1573,7 @@ public AuthorizationFramework getAuthorizationFramework() {
15701573
*
15711574
* @param fw the new framework
15721575
*/
1573-
public void setAuthorizationFramework(AuthorizationFramework fw) {
1576+
synchronized public void setAuthorizationFramework(AuthorizationFramework fw) {
15741577
if (this.authFramework != null) {
15751578
this.authFramework.removeAll(this.authFramework.getStack());
15761579
}
@@ -1637,8 +1640,8 @@ public void applyConfig(Configuration config, boolean reindex) {
16371640
config.refreshDateForLastIndexRun();
16381641
}
16391642

1640-
authFramework.setPluginDirectory(config.getPluginDirectory());
1641-
authFramework.reload();
1643+
getAuthorizationFramework().setPluginDirectory(config.getPluginDirectory());
1644+
getAuthorizationFramework().reload();
16421645
}
16431646

16441647
/**
@@ -1805,7 +1808,7 @@ public FileVisitResult postVisitDirectory(Path d, IOException exc) throws IOExce
18051808
}
18061809
if (reload) {
18071810
Thread.sleep(THREAD_SLEEP_TIME); // experimental wait if file is being written right now
1808-
authFramework.reload();
1811+
getAuthorizationFramework().reload();
18091812
}
18101813
if (!key.reset()) {
18111814
break;

src/org/opensolaris/opengrok/web/WebappListener.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import javax.servlet.ServletRequestEvent;
3838
import javax.servlet.ServletRequestListener;
3939
import org.json.simple.parser.ParseException;
40+
import org.opensolaris.opengrok.authorization.AuthorizationFramework;
4041
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
4142
import org.opensolaris.opengrok.logger.LoggerFactory;
4243

@@ -74,6 +75,13 @@ public void contextInitialized(final ServletContextEvent servletContextEvent) {
7475
}
7576
}
7677

78+
/**
79+
* Create a new instance of authorization framework. If the code above
80+
* (reading the configuration) failed then the plugin directory is
81+
* possibly {@code null} causing the framework to allow every request.
82+
*/
83+
env.setAuthorizationFramework(new AuthorizationFramework(env.getPluginDirectory()));
84+
7785
String address = context.getInitParameter("ConfigAddress");
7886
if (address != null && address.length() > 0) {
7987
LOGGER.log(Level.CONFIG, "Will listen for configuration on [{0}]", address);

0 commit comments

Comments
 (0)