복붙노트

[SPRING] 각도 4.0 + 봄 부팅 + 봄 보안 : TemplateInputException : "로그인"템플릿 해결 오류

SPRING

각도 4.0 + 봄 부팅 + 봄 보안 : TemplateInputException : "로그인"템플릿 해결 오류

첫 번째 Angular 프로젝트에서 Spring Security를 ​​통합하려고합니다. 나는 이것, 이것을 포함하여 많은 기사 및보기를, 이것, 이것 및 이것 따른다. 내 응용 프로그램에서 스프링 보안을 유지하고 LDAP에서 인증되기를 바랍니다. \ src \ main \ resources \ templates에 login.html을 유지하면 로그인 페이지가 표시됩니다. 하지만 Angular 컴포넌트에서 로그인 페이지를 원합니다. 그래서 나는 \ src \ main \ resources \ templates에서 login.html을 삭제했다. localhost : 8080을 클릭하면 내 LoginController (yu = ou는 로그에서 sysout을 볼 수 있음)로 이동합니다. 그런 다음 오류가 발생합니다.

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 (). 및 ()을 사용하면 원하지 않는 브라우저 로그인 팝업이 표시됩니다.

해결법

  1. ==============================

    1.@SK

    @SK

    아래 예외가 발생하는 이유는 RestController가 아닌 Controller를 사용하고 있기 때문입니다.

    그래서 JSON으로 브라우저에 직접 출력하는 대신 ViewResolver를 사용하여 MVC의 뷰 부분을 해결합니다.

    제어기를 RestController로 바꾸면 .formLogin (). loginPage ( "/ login")을 사용하여 브라우저에서 로그인 요청을하게되며 허용 된대로 각도의 로그인 페이지가 표시됩니다.

    httpBasic, 그것은 401 응답 코드를 얻는 것처럼 팝업을위한 브라우저의 특성입니다.

  2. from https://stackoverflow.com/questions/50076941/angular-4-0-spring-boot-spring-security-templateinputexception-error-resol by cc-by-sa and MIT license