Skip to content

Commit cfd5a62

Browse files
committed
adding plugin version to track the reload count
1 parent 41dbd77 commit cfd5a62

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ public final class AuthorizationFramework {
7171
*/
7272
List<AuthorizationPluginWrapper> plugins;
7373

74+
/**
75+
* Keeping track of the number of reloads in this framework. This can be
76+
* used by the plugins to invalidate the session and force reload the
77+
* authorization values.
78+
*
79+
* Starting at 0 and increases with every reload.
80+
*
81+
* The plugin should call RuntimeEnvironment.getPluginVersion() to get this
82+
* number.
83+
*
84+
* @see RuntimeEnvironment#getPluginVersion()
85+
*/
86+
private int pluginVersion = 0;
87+
7488
/**
7589
* Plugin directory is set through RuntimeEnvironment.
7690
*
@@ -483,6 +497,9 @@ public Object run() {
483497
// clean all plugins
484498
removeAll();
485499

500+
// increase the current plugin version tracked by the framework
501+
increasePluginVersion();
502+
486503
// add spaces with configured plugins - leaving null just to obtain the correct order of execution
487504
for (AuthorizationCheck check : RuntimeEnvironment.getInstance().getPluginConfiguration()) {
488505
plugins.add(new AuthorizationPluginWrapper(check, null));
@@ -496,6 +513,39 @@ public Object run() {
496513
loadAllPlugins();
497514
}
498515

516+
/**
517+
* Returns the current plugins version in this framework. This can be used
518+
* by the plugins to invalidate the session and force reload the
519+
* authorization values.
520+
*
521+
* This number changes with every plugin reload.
522+
*
523+
* The plugin should call RuntimeEnvironment.getPluginVersion() to get this
524+
* number and act upon if it needs to renew the session.
525+
*
526+
* @return the current version number
527+
* @see RuntimeEnvironment#getPluginVersion()
528+
*/
529+
public int getPluginVersion() {
530+
return pluginVersion;
531+
}
532+
533+
/**
534+
* Changes the plugin version to the next version.
535+
*/
536+
public void increasePluginVersion() {
537+
this.pluginVersion++;
538+
}
539+
540+
/**
541+
* Sets the plugin version to an arbitrary number.
542+
*
543+
* @param pluginVersion the number
544+
*/
545+
public void setPluginVersion(int pluginVersion) {
546+
this.pluginVersion = pluginVersion;
547+
}
548+
499549
/**
500550
* Checks if the request should have an access to a resource.
501551
*

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,16 @@ public void loadStatistics(InputStream in) throws IOException, ParseException {
15341534
}
15351535
}
15361536

1537+
/**
1538+
* Return the current plugin version tracked by the authorization framework.
1539+
*
1540+
* @return the version
1541+
* @see AuthorizationFramework#getPluginVersion()
1542+
*/
1543+
public int getPluginVersion() {
1544+
return AuthorizationFramework.getInstance().getPluginVersion();
1545+
}
1546+
15371547
private ServerSocket configServerSocket;
15381548

15391549
/**

0 commit comments

Comments
 (0)