Skip to content

Commit

Permalink
make thymeleaf the default, and yet an optional engine for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoayyed committed Feb 12, 2020
1 parent 6d57f72 commit 450991c
Show file tree
Hide file tree
Showing 70 changed files with 858 additions and 538 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public class CasEmbeddedApacheTomcatAjpProperties implements Serializable {
*/
private boolean secure;

/**
* Set the secret that must be included with every request.
*/
private String secret;

/**
* A boolean value which can be used to enable or disable
* the TRACE HTTP method. If not specified, this attribute is set to false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public class CasEmbeddedApacheTomcatHttpProxyProperties implements Serializable
*/
private String protocol = "AJP/1.3";

/**
* Set the secret that must be included with every request.
*/
private String secret;

/**
* Custom attributes to set on the proxy connector.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ public class WebflowProperties implements Serializable {
*/
private Groovy groovy = new Groovy();

/**
* With a base path defined, the algorithm that assigns flow identifiers changes slightly.
* Flows will now be assigned registry identifiers equal to the the path segment between
* their base path and file name. For example, if a flow definition is located
* at {@code /WEB-INF/hotels/booking/booking-flow.xml} and the base path is {@code /WEB-INF} the remaining path
* to this flow is {@code hotels/booking} which becomes the flow id.
* If no base path is not specified or if the flow definition is directly on the base
* path, flow id assignment from the filename (minus the extension) is used. For example,
* if a flow definition file is {@code booking.xml}, the flow identifier is simply {@code booking}.
*/
private String basePath;

@RequiresModule(name = "cas-server-core-webflow", automated = true)
@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public interface CasWebflowConstants {
* The transition state 'yes'.
*/
String TRANSITION_ID_YES = "yes";

/**
* The transition state 'prompt'.
*/
Expand Down Expand Up @@ -240,7 +241,7 @@ public interface CasWebflowConstants {
* The state 'realSubmit'.
*/
String STATE_ID_REAL_SUBMIT = "realSubmit";

/**
* 'finishMfaTrustedAuth' state id.
*/
Expand Down Expand Up @@ -677,7 +678,7 @@ public interface CasWebflowConstants {
* Action id 'initialFlowSetupAction'.
*/
String ACTION_ID_INITIAL_FLOW_SETUP = "initialFlowSetupAction";

/**
* Action id 'verifyRequiredServiceAction'.
*/
Expand Down
2 changes: 1 addition & 1 deletion core/cas-server-core-cookie/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description = "Apereo CAS Cookie Management Core"
dependencies {
implementation libraries.thymeleaf

implementation project(":core:cas-server-core-util-api")
implementation project(":core:cas-server-core-cookie-api")
implementation project(":core:cas-server-core-configuration-api")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.apereo.cas.validation;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.servlet.View;

/**
* This is {@link CasProtocolViewFactory}.
*
* @author Misagh Moayyed
* @since 6.2.0
*/
@FunctionalInterface
public interface CasProtocolViewFactory {
/**
* Create view.
*
* @param applicationContext the application context
* @param viewName the view name
* @param contentType the content type
* @return the view
*/
View create(ConfigurableApplicationContext applicationContext,
String viewName,
String contentType);

/**
* Create view.
*
* @param applicationContext the application context
* @param viewName the view name
* @return the view
*/
default View create(final ConfigurableApplicationContext applicationContext, final String viewName) {
return create(applicationContext, viewName, StringUtils.EMPTY);
}
}
4 changes: 1 addition & 3 deletions core/cas-server-core-web-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ dependencies {
implementation project(":core:cas-server-core-authentication-api")
implementation project(":core:cas-server-core-configuration-api")
implementation project(":core:cas-server-core-util-api")

implementation libraries.thymeleaf

implementation libraries.oshi


testImplementation project(path: ":core:cas-server-core-util-api", configuration: "tests")
testImplementation project(path: ":core:cas-server-core-authentication-api", configuration: "tests")
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

package org.apereo.cas;

import org.apereo.cas.web.support.filters.AddResponseHeadersFilterTests;
import org.apereo.cas.web.support.filters.RequestParameterPolicyEnforcementFilterTests;
import org.apereo.cas.web.view.ChainingTemplateViewResolverTests;
import org.apereo.cas.web.view.RestfulUrlTemplateResolverTests;

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectClasses;
Expand All @@ -17,8 +14,6 @@
* @since 6.0.0-RC3
*/
@SelectClasses({
ChainingTemplateViewResolverTests.class,
RestfulUrlTemplateResolverTests.class,
RequestParameterPolicyEnforcementFilterTests.class,
AddResponseHeadersFilterTests.class
})
Expand Down
1 change: 0 additions & 1 deletion core/cas-server-core-web/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dependencies {
implementation libraries.pac4jcore
implementation libraries.nimbus

implementation libraries.thymeleaf
implementation libraries.snakeyaml
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
package org.apereo.cas.config;

import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.cas.web.view.ChainingTemplateViewResolver;
import org.apereo.cas.web.view.RestfulUrlTemplateResolver;
import org.apereo.cas.web.view.ThemeFileTemplateResolver;

import lombok.val;
import org.apache.commons.lang3.StringUtils;
import org.jooq.lambda.Unchecked;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver;
import org.thymeleaf.templateresolver.AbstractTemplateResolver;
import org.thymeleaf.templateresolver.FileTemplateResolver;

/**
* This is {@link CasCoreViewsConfiguration}.
Expand All @@ -28,53 +14,4 @@
@Configuration(value = "casCoreWebViewsConfiguration", proxyBeanMethods = false)
@EnableConfigurationProperties(CasConfigurationProperties.class)
public class CasCoreViewsConfiguration {

@Autowired
private CasConfigurationProperties casProperties;

@Autowired
private ObjectProvider<ThymeleafProperties> thymeleafProperties;

@Bean
public AbstractTemplateResolver chainingTemplateViewResolver() {
val chain = new ChainingTemplateViewResolver();

val templatePrefixes = casProperties.getView().getTemplatePrefixes();
templatePrefixes.forEach(Unchecked.consumer(prefix -> {
val prefixPath = ResourceUtils.getFile(prefix).getCanonicalPath();
val viewPath = StringUtils.appendIfMissing(prefixPath, "/");

val rest = casProperties.getView().getRest();
if (StringUtils.isNotBlank(rest.getUrl())) {
val url = new RestfulUrlTemplateResolver(casProperties);
configureTemplateViewResolver(url);
chain.addResolver(url);
}

val theme = new ThemeFileTemplateResolver(casProperties);
configureTemplateViewResolver(theme);
theme.setPrefix(viewPath + "themes/%s/");
chain.addResolver(theme);


val file = new FileTemplateResolver();
configureTemplateViewResolver(file);
file.setPrefix(viewPath);
chain.addResolver(file);
}));

chain.initialize();
return chain;
}

private void configureTemplateViewResolver(final AbstractConfigurableTemplateResolver resolver) {
val props = thymeleafProperties.getObject();
resolver.setCacheable(props.isCache());
resolver.setCharacterEncoding(props.getEncoding().name());
resolver.setCheckExistence(props.isCheckTemplateLocation());
resolver.setForceTemplateMode(true);
resolver.setOrder(0);
resolver.setSuffix(".html");
resolver.setTemplateMode(props.getMode());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

package org.apereo.cas;

import org.apereo.cas.web.CasCoreViewsConfigurationTests;
import org.apereo.cas.web.RegisteredServiceResponseHeadersEnforcementFilterTests;
import org.apereo.cas.web.SimpleUrlValidatorFactoryBeanTests;
import org.apereo.cas.web.WebjarValidationTests;
Expand All @@ -19,8 +17,7 @@
@SelectClasses({
RegisteredServiceResponseHeadersEnforcementFilterTests.class,
SimpleUrlValidatorFactoryBeanTests.class,
WebjarValidationTests.class,
CasCoreViewsConfigurationTests.class
WebjarValidationTests.class
})
@RunWith(JUnitPlatform.class)
public class AllTestsSuite {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public class EncryptedTranscoder implements Transcoder {
* Flag to indicate whether to Gzip compression before encryption.
*/
private boolean compression = true;



public EncryptedTranscoder(final CipherBean cipherBean) {
setCipherBean(cipherBean);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apereo.cas.web.flow.executor.WebflowExecutorFactory;

import lombok.val;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -210,17 +211,19 @@ public HandlerMapping loginFlowHandlerMapping() {
@Lazy(false)
@Bean
public FlowDefinitionRegistry logoutFlowRegistry() {
val basePath = StringUtils.defaultIfBlank(casProperties.getWebflow().getBasePath(), CasWebflowConstants.BASE_CLASSPATH_WEBFLOW);
val builder = new FlowDefinitionRegistryBuilder(this.applicationContext, builder());
builder.setBasePath(CasWebflowConstants.BASE_CLASSPATH_WEBFLOW);
builder.setBasePath(basePath);
builder.addFlowLocationPattern("/logout/*-webflow.xml");
return builder.build();
}

@Lazy(false)
@Bean
public FlowDefinitionRegistry loginFlowRegistry() {
val basePath = StringUtils.defaultIfBlank(casProperties.getWebflow().getBasePath(), CasWebflowConstants.BASE_CLASSPATH_WEBFLOW);
val builder = new FlowDefinitionRegistryBuilder(this.applicationContext, builder());
builder.setBasePath(CasWebflowConstants.BASE_CLASSPATH_WEBFLOW);
builder.setBasePath(basePath);
builder.addFlowLocationPattern("/login/*-webflow.xml");
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4789,6 +4789,8 @@ To learn more about this topic, [please review this guide](../webflow/Webflow-Cu
# cas.webflow.alwaysPauseRedirect=false
# cas.webflow.refresh=true
# cas.webflow.redirectSameState=false
# cas.webflow.autoconfigure=true
# cas.webflow.basePath=
```

### Spring Webflow Login Decorations
Expand Down
16 changes: 7 additions & 9 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1398,15 +1398,6 @@ ext.libraries = [
dependencies.create("javax.servlet:jstl:$javaxJstlVersion"),
dependencies.create("javax.transaction:jta:$jtaVersion")
],
thymeleafdialect : [
dependencies.create("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:$thymeleafDialectVersion") {
exclude(group: "org.javassist", module: "javassist")
exclude(group: "org.slf4j", module: "slf4j-api")
exclude(group: "org.codehaus.groovy", module: "groovy")
exclude(group: "org.thymeleaf", module: "thymeleaf")
force = true
}
],
activemq : [
dependencies.create("org.springframework.boot:spring-boot-starter-activemq:$springBootVersion") {
exclude(group: "org.slf4j", module: "slf4j-api")
Expand Down Expand Up @@ -1444,6 +1435,13 @@ ext.libraries = [
exclude(group: "org.springframework", module: "spring-aop")
force = true
},
dependencies.create("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:$thymeleafDialectVersion") {
exclude(group: "org.javassist", module: "javassist")
exclude(group: "org.slf4j", module: "slf4j-api")
exclude(group: "org.codehaus.groovy", module: "groovy")
exclude(group: "org.thymeleaf", module: "thymeleaf")
force = true
},
dependencies.create("org.springframework.boot:spring-boot-starter-thymeleaf:$springBootVersion") {
exclude(group: "com.fasterxml", module: "classmate")
exclude(group: "org.thymeleaf", module: "thymeleaf")
Expand Down
1 change: 1 addition & 0 deletions gradle/webapp.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies {
implementation project(":support:cas-server-support-person-directory")
implementation project(":support:cas-server-support-themes")
implementation project(":support:cas-server-support-validation")
implementation project(":support:cas-server-support-thymeleaf")
implementation project(":support:cas-server-support-pm-webflow")

implementation project(":webapp:cas-server-webapp-config")
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ include "support:cas-server-support-throttle-hazelcast"
include "support:cas-server-support-throttle-jdbc"
include "support:cas-server-support-throttle-mongo"
include "support:cas-server-support-throttle-redis"
include "support:cas-server-support-thymeleaf"
include "support:cas-server-support-token-authentication"
include "support:cas-server-support-token-core-api"
include "support:cas-server-support-token-core"
Expand Down
Loading

0 comments on commit 450991c

Please sign in to comment.