Skip to content

Commit

Permalink
Requiring authentication for admin pages (using HTTP Basic authentica…
Browse files Browse the repository at this point in the history
…tion). Fixes issue #17.
  • Loading branch information
chriskuehl committed Apr 22, 2013
1 parent cd4d84e commit cd61d11
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/server/BrowseRight/grails-app/conf/filters/AdminFilters.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package filters

import org.codehaus.groovy.grails.commons.GrailsApplication
import grails.util.GrailsUtil

class AdminFilters {
def request
def response

def filters = {
adminFilter(uri: "/dev/**") {
before = {
if (true || GrailsUtil.getEnvironment().equals(GrailsApplication.ENV_PRODUCTION)) {
// check the provided username and password
def success = false
def auth = request.getHeader("Authorization")

if (auth) {
def b64 = auth - 'Basic '
def raw = new String(new sun.misc.BASE64Decoder().decodeBuffer(b64));
def parts = raw.split(':')

if (parts.size() == 2 && parts[0].length() > 0 && parts[1].length() > 0 && System.env["BROWSERIGHT_ADMIN_" + parts[0].toUpperCase()] == parts[1]) {
success = true
}
}

if (! success) {
response.addHeader("WWW-Authenticate", "Basic realm=\"BrowseRight Admin Panel\"")
render(view: "/denied", status: 401)
return false
}
}
}
}
}
}

0 comments on commit cd61d11

Please sign in to comment.