-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add Thymeleaf dialect with tags to get and process banner and footer - Add additional properties for skin settings - Add additional web flow support for adding new properties to flow scope - Add ala theme properties - Add i18n messages for ALA login screen - Add image for ALA login screen - Set default theme to ALA
- Loading branch information
1 parent
9b98720
commit e7d16df
Showing
16 changed files
with
462 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/main/kotlin/au/org/ala/cas/delegated/AlaPac4jAuthenticationConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package au.org.ala.cas.thymeleaf | ||
|
||
import org.thymeleaf.dialect.AbstractProcessorDialect | ||
import org.thymeleaf.processor.IProcessor | ||
|
||
class AlaDialect(val alaTemplateClient: AlaTemplateClient) : AbstractProcessorDialect("ALA Dialect", "ala", 10) { | ||
|
||
override fun getProcessors(dialectPrefix: String): MutableSet<IProcessor> { | ||
return mutableSetOf( | ||
AlaHeaderFooterTagProcessor(dialectPrefix, "banner", alaTemplateClient), | ||
AlaHeaderFooterTagProcessor(dialectPrefix, "footer", alaTemplateClient) | ||
) | ||
} | ||
|
||
|
||
//override fun getExpressionObjectFactory() = AlaExpressionFactory(skinConfig) | ||
} | ||
|
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/au/org/ala/cas/thymeleaf/AlaHeaderFooterTagProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package au.org.ala.cas.thymeleaf | ||
|
||
import org.thymeleaf.context.ITemplateContext | ||
import org.thymeleaf.context.WebEngineContext | ||
import org.thymeleaf.model.IProcessableElementTag | ||
import org.thymeleaf.processor.element.AbstractElementTagProcessor | ||
import org.thymeleaf.processor.element.IElementTagStructureHandler | ||
import org.thymeleaf.templatemode.TemplateMode | ||
|
||
class AlaHeaderFooterTagProcessor( | ||
dialectPrefix: String, | ||
val tagName: String, | ||
val alaTemplateClient: AlaTemplateClient) : | ||
AbstractElementTagProcessor( | ||
TemplateMode.HTML, | ||
dialectPrefix, | ||
tagName, // the tag name to match | ||
true, // apply dialect prefix to tag name | ||
null, // attribute name | ||
false, // apply dialect prefix to attribute name | ||
PRECEDENCE // precedence inside dialect's precedence | ||
) { | ||
|
||
companion object { | ||
const val PRECEDENCE = 1000 | ||
} | ||
|
||
override fun doProcess(context: ITemplateContext, tag: IProcessableElementTag, structureHandler: IElementTagStructureHandler) { | ||
val request = when (context) { | ||
is WebEngineContext -> context.request | ||
else -> null | ||
} | ||
val content = alaTemplateClient.load(tagName, request) | ||
if (content == null) { | ||
structureHandler.replaceWith("<div th:replace=\"fragments/$tagName\"></div>", true) | ||
} else { | ||
structureHandler.replaceWith(content, false) | ||
} | ||
} | ||
|
||
|
||
} |
87 changes: 87 additions & 0 deletions
87
src/main/kotlin/au/org/ala/cas/thymeleaf/AlaTemplateClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package au.org.ala.cas.thymeleaf | ||
|
||
import au.org.ala.cas.SkinProperties | ||
import au.org.ala.utils.logger | ||
import com.github.benmanes.caffeine.cache.Caffeine | ||
import org.apereo.cas.web.support.WebUtils | ||
import org.springframework.webflow.execution.RequestContextHolder | ||
import java.io.Reader | ||
import java.net.URI | ||
import java.util.concurrent.TimeUnit | ||
import javax.servlet.http.HttpServletRequest | ||
|
||
class AlaTemplateClient(val skinConfig: SkinProperties, val cookieName: String) { | ||
|
||
companion object { | ||
const val LOGGED_IN_CLASS = "logged-in" | ||
const val LOGGED_OUT_CLASS = "not-logged-in" | ||
|
||
val log = logger<AlaHeaderFooterTagProcessor>() | ||
} | ||
|
||
val uri = URI(skinConfig.headerFooterUrl) | ||
val cache = Caffeine.newBuilder().expireAfterWrite(skinConfig.cacheDuration, TimeUnit.MILLISECONDS).build(this::loadTemplate) | ||
|
||
fun loadTemplate(template: String) = uri.resolve("./$template.html").toURL().openStream().reader().use(Reader::readText) | ||
|
||
fun load(name: String, request: HttpServletRequest?, fluidLayout: Boolean = false): String? { | ||
val cached = try { | ||
cache[name] | ||
} catch (e: Exception) { | ||
log.error("Couldn't load {}", name, e) | ||
null | ||
} | ||
|
||
if (cached == null || cached.isBlank()) { | ||
return null | ||
} | ||
var content = cached.replace("::headerFooterServer::", skinConfig.headerFooterUrl) | ||
.replace("::centralServer::", skinConfig.baseUrl) | ||
.replace("::searchServer::", skinConfig.bieBaseUrl) | ||
.replace("::searchPath::", skinConfig.bieSearchPath) | ||
.replace("::authStatusClass::", if (isLoggedIn(request)) LOGGED_IN_CLASS else LOGGED_OUT_CLASS) | ||
if (fluidLayout) { | ||
content = content.replace("class=\"container\"", "class=\"container-fluid\"") | ||
} | ||
if (content.contains("::loginLogoutListItem::")) { | ||
// only do the work if it is needed | ||
content = content.replace("::loginLogoutListItem::", buildLoginoutLink(request)) | ||
} | ||
return content | ||
} | ||
|
||
fun isLoggedIn(request: HttpServletRequest?): Boolean { | ||
val ctx = RequestContextHolder.getRequestContext() | ||
return if (ctx != null) { | ||
// TODO pass in the request context | ||
WebUtils.getCredential(ctx) != null | ||
// (request.cookies?.any { it.name == cookieName } ?: false) || request.userPrincipal != null | ||
} else { false } | ||
} | ||
|
||
/** | ||
* Builds the login or logout link based on current login status. | ||
* @param attrs any specified params to override defaults | ||
* @return | ||
*/ | ||
fun buildLoginoutLink(request: HttpServletRequest?): String { | ||
// val requestUri = removeContext(grailServerURL) + request.forwardURI | ||
// val logoutUrl = attrs.logoutUrl ?: grailServerURL + "/session/logout" | ||
// val logoutReturnToUrl = attrs.logoutReturnToUrl ?: requestUri | ||
// def casLogoutUrl = attrs.casLogoutUrl ?: casLogoutUrl | ||
// | ||
// // TODO should this be attrs.logoutReturnToUrl? | ||
// if (!attrs.loginReturnToUrl && request.queryString) { | ||
// logoutReturnToUrl += "?" + URLEncoder.encode(request.queryString, "UTF-8") | ||
// } | ||
|
||
return if (isLoggedIn(request)) { | ||
val casLogoutUrl = request?.servletContext?.contextPath + "/logout" | ||
"<a href=\"$casLogoutUrl\">Logout</a>" | ||
} else { | ||
// currently logged out | ||
val casLoginUrl = request?.servletContext?.contextPath + "/login" | ||
"<a href=\"$casLoginUrl\">Log in</a>" | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/au/org/ala/cas/thymeleaf/AlaThymeleafConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package au.org.ala.cas.thymeleaf | ||
|
||
import au.org.ala.cas.AlaCasProperties | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
@EnableConfigurationProperties(AlaCasProperties::class) | ||
open class AlaThymeleafConfiguration { | ||
|
||
@Autowired | ||
lateinit var alaCasProperties: AlaCasProperties | ||
|
||
@Bean | ||
open fun alaTemplateClient() = AlaTemplateClient(alaCasProperties.skin, alaCasProperties.cookie.name) | ||
|
||
@Bean | ||
open fun alaDialect(alaTemplateClient: AlaTemplateClient) = AlaDialect(alaTemplateClient) | ||
|
||
// @Autowired | ||
// lateinit var templateEngine: SpringTemplateEngine | ||
// | ||
// @PostConstruct | ||
// fun extension() { | ||
// templateEngine.addDialect(alaDialect(alaTemplateClient())) | ||
// val resolver = UrlTemplateResolver() | ||
// resolver.prefix = alaCasProperties.skin.headerFooterUrl ?: "https://www.ala.org.au/commonui" | ||
// resolver.suffix = ".html" | ||
// resolver.setTemplateMode("HTML5") | ||
// resolver.order = templateEngine.templateResolvers.size | ||
// resolver.isCacheable = true | ||
// templateEngine.addTemplateResolver(resolver) | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.