Skip to content

Commit 5990576

Browse files
author
Vladimir Kotal
committed
use only plugin stack from constructor in AuthorizationFramework
fixes #1918
1 parent 687e133 commit 5990576

File tree

5 files changed

+14
-27
lines changed

5 files changed

+14
-27
lines changed

plugins/LdapPlugin/src/opengrok/auth/plugin/AbstractLdapPlugin.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@
3232
import opengrok.auth.plugin.ldap.AbstractLdapProvider;
3333
import opengrok.auth.plugin.ldap.FakeLdapFacade;
3434
import opengrok.auth.plugin.ldap.LdapFacade;
35-
import org.opensolaris.opengrok.authorization.AuthorizationFramework;
3635
import org.opensolaris.opengrok.authorization.IAuthorizationPlugin;
3736
import org.opensolaris.opengrok.configuration.Group;
3837
import org.opensolaris.opengrok.configuration.Project;
39-
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
4038

4139
/**
4240
* Abstract class for all plug-ins working with LDAP. Takes care of

src/org/opensolaris/opengrok/authorization/AuthorizationFramework.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ public final class AuthorizationFramework {
8686
* stored in HTTP session.
8787
*
8888
* Starting at 0 and increases with every reload.
89-
*
90-
* External consumers should call RuntimeEnvironment.getPluginVersion()
91-
* to get this number.
92-
*
93-
* @see RuntimeEnvironment#getPluginVersion()
9489
*/
9590
private long pluginVersion = 0;
9691

@@ -550,7 +545,7 @@ public Object run() {
550545
});
551546

552547
// clone a new stack not interfering with the current stack
553-
AuthorizationStack newStack = RuntimeEnvironment.getInstance().getPluginStack().clone();
548+
AuthorizationStack newStack = getStack().clone();
554549

555550
// load all other possible plugin classes
556551
loadClasses(newStack,
@@ -595,7 +590,6 @@ public Object run() {
595590
* Assumes the {@code lock} is held for reading.
596591
*
597592
* @return the current version number
598-
* @see RuntimeEnvironment#getPluginVersion()
599593
*/
600594
private long getPluginVersion() {
601595
return pluginVersion;
@@ -642,9 +636,9 @@ private boolean isSessionInvalid(HttpSession session) {
642636
* <h3>Order of plugin invocation</h3>
643637
*
644638
* <p>
645-
* The order of plugin invocation is given by the configuration
646-
* {@link RuntimeEnvironment#getPluginStack()} and appropriate actions are
647-
* taken when traversing the stack with set of keywords, such as:</p>
639+
* The order of plugin invocation is given by the stack and appropriate
640+
* actions are taken when traversing the stack with set of keywords,
641+
* such as:</p>
648642
*
649643
* <h4>required</h4>
650644
* Failure of such a plugin will ultimately lead to the authorization

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ public void loadStatistics(InputStream in) throws IOException, ParseException {
16631663
*/
16641664
synchronized public AuthorizationFramework getAuthorizationFramework() {
16651665
if (authFramework == null) {
1666-
authFramework = new AuthorizationFramework(threadConfig.get().getPluginDirectory());
1666+
authFramework = new AuthorizationFramework(getPluginDirectory(), getPluginStack());
16671667
}
16681668
return authFramework;
16691669
}
@@ -1750,6 +1750,7 @@ public void applyConfig(Configuration config, boolean reindex) {
17501750

17511751
// set the new plugin directory and reload the authorization framework
17521752
getAuthorizationFramework().setPluginDirectory(config.getPluginDirectory());
1753+
getAuthorizationFramework().setStack(config.getPluginStack());
17531754
getAuthorizationFramework().reload();
17541755
}
17551756

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* CDDL HEADER END
1818
*/
1919

20-
/*
20+
/*
2121
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.web;
@@ -80,7 +80,7 @@ public void contextInitialized(final ServletContextEvent servletContextEvent) {
8080
* (reading the configuration) failed then the plugin directory is
8181
* possibly {@code null} causing the framework to allow every request.
8282
*/
83-
env.setAuthorizationFramework(new AuthorizationFramework(env.getPluginDirectory()));
83+
env.setAuthorizationFramework(new AuthorizationFramework(env.getPluginDirectory(), env.getPluginStack()));
8484

8585
String address = context.getInitParameter("ConfigAddress");
8686
if (address != null && address.length() > 0) {

test/org/opensolaris/opengrok/authorization/AuthorizationFrameworkReloadTest.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,8 @@ public void testReloadCycle() {
107107
stack.add(new AuthorizationPlugin(AuthControlFlag.REQUIRED,
108108
"opengrok.auth.plugin.FalsePlugin"));
109109
stack.setForProjects(projectName);
110-
RuntimeEnvironment re = RuntimeEnvironment.getInstance();
111-
// Unfortunately even though the AuthorizationFramework is instantiated with given stack,
112-
// this does not work because the reload() method called from the constructor grabs
113-
// the stack from RuntimeEnvironment and not from the AuthorizationFramework itself.
114-
re.setPluginStack(stack);
115-
re.setPluginDirectory(pluginDirectory.getPath());
116-
117110
AuthorizationFramework framework =
118-
new AuthorizationFramework(pluginDirectory.getPath());
111+
new AuthorizationFramework(pluginDirectory.getPath(), stack);
119112

120113
// Perform simple sanity check before long run is entered. If this fails,
121114
// it will be waste of time to continue with the test.
@@ -125,13 +118,14 @@ public void testReloadCycle() {
125118

126119
// Create a thread that does reload() every now and then.
127120
runThread = true;
121+
final int maxReloadSleep = 10;
128122
Thread t = new Thread(new Runnable() {
129123
@Override
130124
public void run() {
131125
while (runThread) {
132126
framework.reload();
133127
try {
134-
Thread.sleep(10);
128+
Thread.sleep((long) (Math.random() % maxReloadSleep) + 1);
135129
} catch (InterruptedException ex) {
136130
}
137131
}
@@ -142,12 +136,12 @@ public void run() {
142136
reloads = stats.getRequest("authorization_stack_reload");
143137
assertNotNull(reloads);
144138
// Process number or requests and check that framework decision is consistent.
145-
for (int i = 0; i < 100; i++) {
139+
for (int i = 0; i < 1000; i++) {
146140
req = new DummyHttpServletRequest();
147141
assertFalse(framework.isAllowed(req, p));
148142
try {
149-
// XXX random sleep
150-
Thread.sleep(50);
143+
// Should run more frequently than the thread performing reload().
144+
Thread.sleep((long) (Math.random() % (maxReloadSleep / 3)) + 1);
151145
} catch (InterruptedException ex) {
152146
}
153147
}

0 commit comments

Comments
 (0)