I have implemented saml-adfs service provider using spring-security-saml2. SAML-ADFS authentication happens properly. After authentication I am trying to redirect it to a landing page, which has few variables such as UserID dynamically populating based on logged in user information. For html pages rendering, I am using spring-boot-started-thymeleaf lib. I have gone through various articles and done below configs. All my html files are present in src/main/resources/templates.
I am getting "Circular view path[landing],Check your ViewResolver setup! error.
If I change it to a static html page, which is present in src/main/resources/static folder, then it is loading the content.
Please guide me how I can resolve this issue. I have dependency of spring-boot-starter-web and spring-boot-starter-thymeleaf in my build.gradle
landing.html page
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Landing!</title>
</head>
<body>
<h1>You are logged as <span th:text="${username}">null</span>!</h1>
<p>
<a th:href="@{/saml/logout}">Global Logout</a><br/>
<a th:href="@{/saml/logout?local=true}">Local Logout</a>
</p>
</body>
</html>
@Controller
public class LandingController {
@RequestMapping("/landing")`enter code here`
public String landing(@CurrentUser User user, Model model) {
model.addAttribute("username", user.getUsername());
return "landing";
}
First check that your view resolver is configured correctly.Try configuring your thymeleaf view resolver like :
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Bean
public ClassLoaderTemplateResolver templateResolver() {
var templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("templates/");
templateResolver.setCacheable(false);
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML5");
templateResolver.setCharacterEncoding("UTF-8");
return templateResolver;
}
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
templateEngine.setTemplateEngineMessageSource(messageSource());
return templateEngine;
}
@Bean
public ViewResolver viewResolver() {
var viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine());
viewResolver.setCharacterEncoding("UTF-8");
return viewResolver;
}
}
This is the basic configuration and you can change the location of your templates etc in this configuration according to your project structure.
When you provide this configuration the Thymeleafview resolver will handle resolving the uri for accessing the html which should solve your issue.