Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- clear hub parameter when generating login/logout link
  • Loading branch information
temi committed Apr 22, 2024
1 parent da643fc commit 6d07101
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions grails-app/taglib/au/org/ala/biocollect/TemplateTagLib.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package au.org.ala.biocollect

import au.org.ala.biocollect.merit.SettingService
import au.org.ala.biocollect.merit.UserService
import org.grails.web.servlet.mvc.GrailsWebRequest
import org.springframework.context.MessageSource

class TemplateTagLib {
Expand Down Expand Up @@ -134,6 +135,11 @@ class TemplateTagLib {
}
break;
case 'login':
// HubAwareLinkGenerator adds hub parameter to the link which causes subsequent URL parsing to return null in Pac4J filter.
// This causes the app to redirect to root page. And, BioCollect root page is redirected to Wordpress.
// Taking the user outside the application. This is a workaround to fix the issue. First, remove the
// hub parameter before link is generated and set it afterwards.
def hub = clearHubParameter()
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
Expand Down Expand Up @@ -161,6 +167,7 @@ class TemplateTagLib {
)
out << "</li>";
}
setHubParameter(hub)
break;
case 'newproject':
if (bs4) {
Expand Down Expand Up @@ -427,4 +434,21 @@ class TemplateTagLib {
private String getCurrentURL(Map hubConfig){
getCurrentURLFromRequest()
}

private String clearHubParameter(){
def request = GrailsWebRequest.lookup()
def hub = request?.params?.hub
if(hub){
request.params.remove('hub')
}

hub
}

private void setHubParameter(String hub) {
def request = GrailsWebRequest.lookup()
if (hub && request.params) {
request.params.hub = hub
}
}
}

1 comment on commit 6d07101

@jack-brinkman
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍🏼

Please sign in to comment.