Try to search your question here, if you can't find : Ask Any Question Now ?

Angular 4.0 + Spring boot + Spring Security: TemplateInputException: Error resolving template "login"

HomeCategory: stackoverflowAngular 4.0 + Spring boot + Spring Security: TemplateInputException: Error resolving template "login"
craig asked 2 weeks ago

I am integrating Spring Security in my first Angular project. I followed many articles and examples including this, this, this, this and this. I want my application to have spring security and authenticate from LDAP. If I keep a login.html in srcmainresourcestemplates then I can see the login page. But I want the login page to come from Angular component. So I removed/rename the login.html from srcmainresourcestemplates. When I hit localhost:8080, it goes to my LoginController (yu=ou can see the sysout in the log), Then I am getting below error

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)

I tried many ways after Googling, but no luck yet. Any suggestion please..

My Files:

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'}
    },

If I use .and().formLogin() then I am getting this error:

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)

If I use .httpBasic().and(), then I am getting browser login popup which I don’t want

enter image description here

1 Answers
Best Answer
Mannu answered 2 weeks ago
Your Answer

4 + 8 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com