Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Avoiding endless loop if user not 'System Admin' when editing configu…
Browse files Browse the repository at this point in the history
…ration #39

* Plugin will now respond with error message saying user must be 'System Admin'
* Redirecting to login will just cause an endless loop
  • Loading branch information
tomasbjerre committed Aug 7, 2015
1 parent da1c1dd commit 4c1c37c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Changelog of Pull Request Notifier for Stash.

## 1.18
* Avoiding endless loop if user not 'System Admin' when editing configuration
* Triggers can be named. To make it easier to keep track of them in large installations.
* Building against latest Stash version (3.11.1) using latest Atlassian Maven Plugin Suite version (6.0.3)

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/se/bjurr/prnfs/admin/AdminServlet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package se.bjurr.prnfs.admin;

import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;

import java.io.IOException;
import java.net.URI;

Expand Down Expand Up @@ -29,11 +31,12 @@ public AdminServlet(UserManager userManager, LoginUriProvider loginUriProvider,
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
UserProfile user = userManager.getRemoteUser(request);
if (user == null) {
redirectToLogin(request, response);
response.sendRedirect(loginUriProvider.getLoginUri(getUri(request)).toASCIIString());
return;
}
if (!userManager.isSystemAdmin(user.getUserKey())) {
redirectToLogin(request, response);
response.sendError(SC_FORBIDDEN, "Only 'System Admin':s are allowed to edit configuration "
+ loginUriProvider.getLoginUri(getUri(request)).toASCIIString());
return;
}
response.setContentType("text/html;charset=utf-8");
Expand All @@ -48,8 +51,4 @@ private URI getUri(HttpServletRequest request) {
}
return URI.create(builder.toString());
}

private void redirectToLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.sendRedirect(loginUriProvider.getLoginUri(getUri(request)).toASCIIString());
}
}

0 comments on commit 4c1c37c

Please sign in to comment.