Skip to content

Commit

Permalink
Merge pull request #1583 from AtlasOfLivingAustralia/hotfix/6.7.1-iss…
Browse files Browse the repository at this point in the history
…ue1580

#1580
  • Loading branch information
temi authored Apr 18, 2024
2 parents b0bed74 + 31c35e1 commit 22af54e
Show file tree
Hide file tree
Showing 14 changed files with 958 additions and 127 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
biocollectVersion=6.8-i18n-SNAPSHOT
biocollectVersion=6.8-LOGIN-SNAPSHOT
grailsVersion=5.1.9
grailsGradlePluginVersion=5.1.5
assetPipelineVersion=3.3.4
Expand Down
21 changes: 10 additions & 11 deletions grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ environments {
temp.dir = "/data/biocollect/temp"
// system level config
server.port = 8087
serverURL = "http://devt.ala.org.au:8087"
serverURL = "http://localhost:8087"
biocollect.system.email.replyTo = "biocollect-dev<no-reply>@ala.org.au"
sender = "[email protected]"
debugUI = true
Expand All @@ -36,11 +36,10 @@ environments {
}

test {
spring.autoconfigure.exclude="au.org.ala.ws.security.AlaWsSecurityConfiguration"
debugUI = false
loggerLevel = "DEBUG"
server.port = "8087"
grails.host = "http://devt.ala.org.au"
grails.host = "http://localhost"
serverName = "${grails.host}:${server.port}"
grails.serverURL = serverName
server.serverURL = serverName
Expand All @@ -51,8 +50,8 @@ environments {
grails.config.locations = []
security.oidc.discoveryUri = "http://localhost:${wiremock.port}/cas/oidc/.well-known"
security.oidc.allowUnsignedIdTokens = true
def casBaseUrl = "http://devt.ala.org.au:${wiremock.port}"

def casBaseUrl = "http://localhost:${wiremock.port}"
ehcache.directory = './ehcache'
security.cas.appServerName=serverName
security.cas.contextPath=
security.cas.casServerName="${casBaseUrl}"
Expand All @@ -61,17 +60,17 @@ environments {
security.cas.loginUrl="${security.cas.casServerUrlPrefix}/login"
security.cas.casLoginUrl="${security.cas.casServerUrlPrefix}/login"
security.cas.logoutUrl="${security.cas.casServerUrlPrefix}/logout"
userDetails.api.url = "${casBaseUrl}/userdetails/userDetails/"
security.jwt.discoveryUri="${casBaseUrl}/cas/oidc/.well-known"
userDetails.url = "${casBaseUrl}/userdetails/userDetails/"
userDetailsSingleUrl = "${userDetails.Url}getUserDetails"
userDetailsUrl = "${userDetatails.url}getUserListFull"
userDetailsSingleUrl = "${userDetails.url}getUserDetails"
logging.dir = '.'
upload.images.path = '/tmp'
upload.images.url = grails.serverURL+'/image/'
ecodata.baseUrl = 'http://devt.ala.org.au:8080/'
ecodata.baseURL = 'http://devt.ala.org.au:8080'
ecodata.service.url = 'http://devt.ala.org.au:8080/ws'
pdfgen.baseURL = "http://devt.ala.org.au:${wiremock.port}/"
ecodata.baseUrl = 'http://localhost:8080/'
ecodata.baseURL = 'http://localhost:8080'
ecodata.service.url = 'http://localhost:8080/ws'
pdfgen.baseURL = "http://localhost:${wiremock.port}/"
api_key='testapikey'
grails.cache.config = {
diskStore {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ class SettingService {
}

def loadHubConfig(hub) {

def defaultHub = grailsApplication.config.getProperty('app.default.hub', String, 'default')
if (!hub) {
hub = grailsApplication.config.app.default.hub?:'default'
hub = cookieService.getCookie(LAST_ACCESSED_HUB)
hub = hub ?: defaultHub
}
else {
// Hub value in multiple places like url path and in parameter causes Array to be passed instead of String.
Expand Down Expand Up @@ -131,7 +132,10 @@ class SettingService {
)
}

cookieService.setCookie(LAST_ACCESSED_HUB, settings?.urlPath, -1 /* -1 means the cookie expires when the browser is closed */)
// Do not set cookie value to default hub since it overwrites genuine hub selection when calls are made with default hub.
// This usually happens when calls are made without hub parameter like downloading images.
if (settings?.urlPath != defaultHub)
cookieService.setCookie(LAST_ACCESSED_HUB, settings?.urlPath, -1 /* -1 means the cookie expires when the browser is closed */, '/')
GrailsWebRequest.lookup().params.hub = settings?.urlPath
SettingService.setHubConfig(settings)
}
Expand Down
33 changes: 28 additions & 5 deletions grails-app/taglib/au/org/ala/biocollect/TemplateTagLib.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,30 @@ class TemplateTagLib {
}
break;
case 'login':
def logoutReturnToUrl = getCurrentURL( attrs.hubConfig )
if (grailsApplication.config.getProperty("security.oidc.logoutAction",String, "CAS") == "cognito") {
// cannot use createLink since it adds hub query parameter and cognito will not consider it valid
logoutReturnToUrl = grailsApplication.config.getProperty("grails.serverURL") + grailsApplication.config.getProperty("logoutReturnToUrl",String, "/hub/index")
}

if (bs4) {
out << "<li itemscope=\"itemscope\" itemtype=\"https://www.schema.org/SiteNavigationElement\" class=\"menu-item nav-item ${classes}\">";
out << auth.loginLogout(
ignoreCookie: "true", cssClass: "btn btn-primary btn-sm nav-button custom-header-login-logout",
logoutUrl: "${createLink(controller: 'logout', action: 'logout')}",
// cannot use createLink since it adds hub query parameter and eventually creates malformed URL with two ? characters
logoutUrl: "/logout",
loginReturnToUrl: getCurrentURL( attrs.hubConfig ),
logoutReturnToUrl: getCurrentURL( attrs.hubConfig )
logoutReturnToUrl: logoutReturnToUrl
)
out << "</li>";
} else {
out << "<li class=\"main-menu ${classes}\">";
out << auth.loginLogout(
ignoreCookie: "true",
logoutUrl: "${createLink(controller: 'logout', action: 'logout')}",
// cannot use createLink since it adds hub query parameter and eventually creates malformed URL with two ? characters
logoutUrl: "/logout",
loginReturnToUrl: getCurrentURL( attrs.hubConfig ),
logoutReturnToUrl: getCurrentURL( attrs.hubConfig )
logoutReturnToUrl: logoutReturnToUrl
)
out << "</li>";
}
Expand Down Expand Up @@ -319,6 +327,21 @@ class TemplateTagLib {
}
}

String getCurrentURLFromRequest() {
String requestURL = request.getRequestURL().toString()
// Construct the complete URL
StringBuilder url = new StringBuilder()
url.append(requestURL)

String queryString = request.getQueryString()
// Include the query string if present
if (queryString != null) {
url.append("?").append(queryString)
}

url.toString()
}


private String getLinkUrl (Map link){
String url;
Expand Down Expand Up @@ -402,6 +425,6 @@ class TemplateTagLib {
}

private String getCurrentURL(Map hubConfig){
g.createLink(absolute: true, uri: '/').toString()
getCurrentURLFromRequest()
}
}
Loading

0 comments on commit 22af54e

Please sign in to comment.