角度4.0+;弹簧靴&x2B;Spring安全性:TemplateInputException:解析模板时出错;“登录”;
我正在我的第一个Angular项目中集成Spring Security。我遵循了许多文章和示例,包括、、和。我希望我的应用程序具有spring安全性,并通过LDAP进行身份验证。如果我将login.html保存在\src\main\resources\templates中,则可以看到登录页面。但是我希望登录页面来自Angular组件。因此,我从\src\main\resources\templates中删除/重命名了login.html。当我点击localhost:8080时,它会转到我的LoginController(yu=ou可以在日志中看到sysout),然后我会看到下面的错误角度4.0+;弹簧靴&x2B;Spring安全性:TemplateInputException:解析模板时出错;“登录”;,spring,angular,spring-boot,spring-security,Spring,Angular,Spring Boot,Spring Security,我正在我的第一个Angular项目中集成Spring Security。我遵循了许多文章和示例,包括、、和。我希望我的应用程序具有spring安全性,并通过LDAP进行身份验证。如果我将login.html保存在\src\main\resources\templates中,则可以看到登录页面。但是我希望登录页面来自Angular组件。因此,我从\src\main\resources\templates中删除/重命名了login.html。当我点击localhost:8080时,它会转到我的Log
018-04-28 07:30:34.610 DEBUG 11520 --- [nio-8080-exec-9] o.s.s.w.a.i.FilterSecurityInterceptor : RunAsManager did not change Authentication object
2018-04-28 07:30:34.610 DEBUG 11520 --- [nio-8080-exec-9] o.s.security.web.FilterChainProxy : /login reached end of additional filter chain; proceeding with original chain
>>>>>>>>>>>> LoginController.login()...
2018-04-28 07:30:34.611 ERROR 11520 --- [nio-8080-exec-9] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-9] Exception processing template "login": Error resolving template "login", template might not exist or might not be accessible by any of the configured Template Resolvers
2018-04-28 07:30:34.611 DEBUG 11520 --- [nio-8080-exec-9] w.c.HttpSessionSecurityContextRepository : SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
2018-04-28 07:30:34.611 DEBUG 11520 --- [nio-8080-exec-9] s.s.w.c.SecurityContextPersistenceFilter : SecurityContextHolder now cleared, as request processing completed
2018-04-28 07:30:34.612 ERROR 11520 --- [nio-8080-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "login", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "login", template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:246)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060)
在谷歌搜索之后,我尝试了很多方法,但都没有成功。有什么建议吗
我的文件:
LoginController.java
@RequestMapping("/login")
String login(){
System.out.println(">>>>>>>>>>>> LoginController.login()...");
return "login";
}
WebSecurityConfiguration.java
@Override
protected void configure(HttpSecurity http) throws Exception {
http
//.httpBasic().and()
.authorizeRequests()
// .antMatchers("/**").permitAll()
.antMatchers("/index.html", "/", "/home", "/login").permitAll()
.anyRequest().authenticated()
.and().formLogin().loginPage("/login")
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
/*http
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/resources/**", "/assets/**", "/css/**", "/js/**", "/fonts/**")
//.antMatchers("/**")
.permitAll()
.and()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.successHandler(authenticationSuccessHandler)
.permitAll()
.and()
.logout()
.logoutUrl("/logout")
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.and()
.httpBasic();
//http.cors();
*/ }
app-routing.module.ts
const routes: Routes = [
{ path: 'login', component: LoginComponent },
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'dashboard', redirectTo: '/home', pathMatch: 'full' },
{
path: 'home',
component: DashboardComponent,
data: { title: 'Dashboard' }
},
{
path: 'linesidemonitor',
component: LinesideMonitorComponent,
data: {title: 'Lineside Monitor'}
},
如果使用.and().formLogin(),则会出现以下错误:
2018-04-28 08:32:08.394 DEBUG 10404 --- [nio-8080-exec-6] o.s.s.w.a.ExceptionTranslationFilter : Access is denied (user is anonymous); redirecting to authentication entry point
org.springframework.security.access.AccessDeniedException: Access is denied
at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:84)
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:233)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:124)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
如果我使用.httpBasic()和(),那么我将得到我不想要的浏览器登录弹出窗口 @SK 出现以下异常的原因是您使用的是控制器,而不是RestController org.thymeleaf.exceptions.TemplateInputException:解析模板“登录”时出错,模板可能不存在,或者任何已配置的模板解析程序都无法访问模板 位于org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:246) 位于org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104) 因此,它不是直接将输出作为JSON写入浏览器,而是使用ViewResolver来解析MVC的视图部分 用RestController替换Controller将使
.formLogin().login页面(“/login”)
使用login发出浏览器请求,并且在允许的情况下,您将获得登录页面
httpBasic,这是浏览器弹出窗口的本质,因为它会得到401响应代码。我改变了方法。我再也没有了。所以我们无法测试这一点。但是非常感谢你花时间回答这个问题。我真的很感谢你的努力。你有什么样的申请表吗?如果是,请分享(可能是github链接)