Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- recentHub cookie only set when hub is not default hub
- looks into cookie to get recent hub
- logout url configurable based on auth environment
- removed deprecated URL
  • Loading branch information
temi committed Dec 1, 2023
1 parent 582dd09 commit b158331
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
15 changes: 7 additions & 8 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 @@ -40,7 +40,7 @@ environments {
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,7 +51,7 @@ 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}"

security.cas.appServerName=serverName
security.cas.contextPath=
Expand All @@ -64,14 +64,13 @@ environments {
security.jwt.discoveryUri="${casBaseUrl}/cas/oidc/.well-known"
userDetails.url = "${casBaseUrl}/userdetails/userDetails/"
userDetailsSingleUrl = "${userDetails.Url}getUserDetails"
userDetailsUrl = "${userDetatails.url}getUserListFull"
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()
}
}

0 comments on commit b158331

Please sign in to comment.