Skip to content

Commit 3aa29a8

Browse files
committed
added security for stats and context parameter
1 parent 16f5dbf commit 3aa29a8

7 files changed

Lines changed: 52 additions & 8 deletions

File tree

src/main/java/de/unirostock/sems/cbarchive/web/Fields.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ else if (desiredLogLevel.equals ("NONE"))
160160
// max stats age
161161
STATS_MAX_AGE = parseLong( context.getInitParameter("MAX_STATS_AGE"), STATS_MAX_AGE );
162162

163+
// public stats
164+
String statsPublic = context.getInitParameter("STATS_PUBLIC");
165+
if( statsPublic != null && statsPublic.isEmpty() == false ) {
166+
statsPublic = statsPublic.toLowerCase();
167+
if( statsPublic.equals("true") || statsPublic.equals("1") )
168+
STATS_PUBLIC = true;
169+
else
170+
STATS_PUBLIC = false;
171+
}
172+
173+
String statsSecret = context.getInitParameter("STATS_SECRET");
174+
if( statsSecret != null && statsSecret.isEmpty() == false )
175+
STATS_SECRET = statsSecret;
176+
else
177+
STATS_SECRET = null;
178+
163179
// feedback Url
164180
String feedbackUrl = context.getInitParameter("FEEDBACK_URL");
165181
if( feedbackUrl != null && feedbackUrl.isEmpty() == true )

src/main/java/de/unirostock/sems/cbarchive/web/rest/RestApi.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public Response getStats( @CookieParam(Fields.COOKIE_PATH) String userPath, @Que
189189
return buildErrorResponse(500, null, "user not creatable!", e.getMessage() );
190190
}
191191

192+
// only fetch user stats, if they are avialable
192193
StatisticData stats = null;
193194
if( user != null )
194195
stats = QuotaManager.getInstance().getUserStats(user);
@@ -198,6 +199,10 @@ public Response getStats( @CookieParam(Fields.COOKIE_PATH) String userPath, @Que
198199
// if secret is corret -> enable full stats
199200
if( secret != null && Fields.STATS_SECRET != null && secret.equals(Fields.STATS_SECRET) )
200201
stats.setFullStats(true);
202+
else if( Fields.STATS_PUBLIC == false ) {
203+
// stats are not public and no secret was provided
204+
return buildErrorResponse(400, user, "no or wrong secret was provided.", "public stats are disabled");
205+
}
201206

202207
return buildResponse(200, user).entity(stats).build();
203208
}

src/main/webapp/WEB-INF/Index.jsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@
7474
<div class="nav-container">
7575
<small>The current workspace contains the following archives:</small>
7676
<div style="clear: both;"></div>
77-
<ul id="nav-workspace" style="float: left; width: 65%;">
77+
<ul id="nav-workspace">
7878
{{# _.each(entries, function(entry) { }}
7979
<li><a class="mainLinks archive-link archives" data-linktype="archive" data-archiveid="{{# print(entry.id); }}" id="nav-archivelink-{{# print(entry.id); }}" title="Archive {{# print(escape(entry.name)); }} in current Workspace">{{# print(escape(entry.name)); }}</a></li>
8080
{{# }); }}
8181
</ul>
82-
<ul id="nav-main" style="float: right; width: 34%;">
82+
<ul id="nav-main">
8383
<li><a class="mainLinks command-link highlight" data-linktype="page" data-page="start-page" id="nav-startlink">start</a></li>
8484
<li><a class="mainLinks command-link" data-linktype="page" data-page="about-page" id="nav-aboutlink">about</a></li>
8585
<% if( Fields.STATS_PUBLIC ) { %>

src/main/webapp/WEB-INF/web.xml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,28 @@
3232
<description>sets the persistent storage directory.</description>
3333
</context-param>
3434

35+
<context-param>
36+
<param-name>FEEDBACK_URL</param-name>
37+
<param-value>https://sems.uni-rostock.de/trac/combinearchive-web/newticket?from=WEBCAT-INTERFACE</param-value>
38+
</context-param>
39+
40+
<context-param>
41+
<param-name>SEDML_WEBTOOLS</param-name>
42+
<param-value></param-value>
43+
</context-param>
44+
3545
<context-param>
3646
<param-name>MAX_STATS_AGE</param-name>
3747
<param-value>180</param-value>
3848
</context-param>
3949

4050
<context-param>
41-
<param-name>FEEDBACK_URL</param-name>
42-
<param-value>https://sems.uni-rostock.de/trac/combinearchive-web/newticket?from=WEBCAT-INTERFACE</param-value>
51+
<param-name>STATS_PUBLIC</param-name>
52+
<param-value>true</param-value>
4353
</context-param>
4454

4555
<context-param>
46-
<param-name>SEDML_WEBTOOLS</param-name>
56+
<param-name>STATS_SECRET</param-name>
4757
<param-value></param-value>
4858
</context-param>
4959

src/main/webapp/res/css/css.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ nav .highlight
9898
font-weight: bold;
9999
}
100100

101+
#nav-workspace {
102+
float: left;
103+
width: 65%;
104+
}
105+
#nav-main {
106+
float: right;
107+
width: calc(35% - 5px);
108+
text-align: right;
109+
}
110+
101111
div.nav-container
102112
{
103113
background-color: #fafafa;

src/main/webapp/res/js/models.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,8 @@ var StatsView = Backbone.View.extend({
20372037
return;
20382038

20392039
this.timeout = null;
2040+
messageView.removeMessages("stats-error");
2041+
20402042
var self = this;
20412043
this.model.fetch({
20422044
success: function(model, response, options) {
@@ -2047,9 +2049,9 @@ var StatsView = Backbone.View.extend({
20472049
error: function(model, response, options) {
20482050
self.$el.fadeOut();
20492051
if( response.responseJSON !== undefined && response.responseJSON.status == "error" )
2050-
messageView.error("Error while fetching stats", response.responseJSON.errors);
2052+
messageView.error("Error while fetching stats", response.responseJSON.errors, "stats-error");
20512053
else
2052-
messageView.error("Error while fetching stats!");
2054+
messageView.error("Error while fetching stats!", "stats-error");
20532055

20542056
}
20552057
});

src/main/webapp/res/js/router.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ var PageRouter = Backbone.Router.extend({
1515
// init views
1616
workspaceArchives = new ArchiveCollection();
1717
navigationView = new NavigationView({ collection: workspaceArchives });
18+
messageView = new MessageView();
19+
1820
archiveView = new ArchiveView();
1921
startView = new StartView();
2022
createView = new CreateView();
2123
statsView = new StatsView();
2224
aboutView = new AboutView();
23-
messageView = new MessageView();
2425

2526
workspaceArchives.once("sync", function(eventName) {
2627
Backbone.history.start();

0 commit comments

Comments
 (0)