Skip to content

Commit

Permalink
Reworked postMultipart auth check implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-brinkman committed Jul 31, 2024
1 parent ec704d2 commit 0a8b4ac
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions grails-app/services/au/org/ala/biocollect/merit/WebService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,21 @@ class WebService {
grailsApplication.config.webservice.readTimeout as int
}

private void addAuthForAllowedDomains(URLConnection conn) {
def host = conn.getURL().getHost()
private boolean isDomainWhitelisted(URL url) {
def host = url.getHost()
for (int domIndex = 0; domIndex < WHITE_LISTED_DOMAINS.size(); domIndex++) {
if (host.endsWith(WHITE_LISTED_DOMAINS[domIndex])) {
conn.setRequestProperty("Authorization", getAuthHeader())
break
return true
}
}

return false
}

private void addAuthForAllowedDomains(URLConnection conn) {
if (isDomainWhitelisted(conn.getURL())) {
conn.setRequestProperty("Authorization", getAuthHeader())
}
}

private URLConnection configureConnection(String url, boolean includeUserId, Integer timeout = null) {
Expand Down Expand Up @@ -475,6 +482,7 @@ class WebService {
def user = userService.getUser()

HTTPBuilder builder = new HTTPBuilder(url)

builder.request(Method.POST) { request ->
requestContentType : 'multipart/form-data'
MultipartEntity content = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE)
Expand All @@ -485,8 +493,12 @@ class WebService {
}
}

if (isDomainWhitelisted(new URL(url))) {
headers."Authorization" = getAuthHeader()
}

addHubUrlPath(headers)
addAuthForAllowedDomains(conn)


if (user) {
headers[grailsApplication.config.app.http.header.userId] = user.userId
Expand Down

0 comments on commit 0a8b4ac

Please sign in to comment.