###本事象内容
Spring Securityを使用してログイン機能を付けたWebアプリを作成し、Github経由でHerokuにデプロイしました。
しかし、サイトを開きいざログインを試すとエラーとなります。
logを確認すると以下のスタックトレースが確認取れました。
log
12021-04-26T10:14:13.631236+00:00 app[web.1]: 2021-04-26 10:14:13.630 ERROR 4 --- [io-42656-exec-2] w.a.UsernamePasswordAuthenticationFilter : An internal error occurred while trying to authenticate the user. 22021-04-26T10:14:13.631258+00:00 app[web.1]: 32021-04-26T10:14:13.631260+00:00 app[web.1]: org.springframework.security.authentication.InternalAuthenticationServiceException: Invalid bound statement (not found): com.worksSystem.ohtajyuki.dao.mst.UserMstDao.select 42021-04-26T10:14:13.631260+00:00 app[web.1]: at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:108) ~[spring-security-core-5.4.6.jar!/:5.4.6] 52021-04-26T10:14:13.631326+00:00 app[web.1]: at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:133) ~[spring-security-core-5.4.6.jar!/:5.4.6] 62021-04-26T10:14:13.631537+00:00 app[web.1]: at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:182) ~[spring-security-core-5.4.6.jar!/:5.4.6] 72021-04-26T10:14:13.631538+00:00 app[web.1]: at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.4.6.jar!/:5.4.6] 82021-04-26T10:14:13.631548+00:00 app[web.1]: at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:110) [spring-security-web-5.4.6.jar!/:5.4.6] 92021-04-26T10:14:13.631549+00:00 app[web.1]: at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:80) [spring-security-web-5.4.6.jar!/:5.4.6] 102021-04-26T10:14:13.631549+00:00 app[web.1]: at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.4.6.jar!/:5.4.6] 112021-04-26T10:14:13.631549+00:00 app[web.1]: at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:55) [spring-security-web-5.4.6.jar!/:5.4.6] 122021-04-26T10:14:13.631550+00:00 app[web.1]: at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.3.6.jar!/:5.3.6] 132021-04-26T10:14:13.631550+00:00 app[web.1]: at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.4.6.jar!/:5.4.6] 142021-04-26T10:14:13.631555+00:00 app[web.1]: at org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:133) [spring-security-web-5.4.6.jar!/:5.4.6] 152021-04-26T10:14:13.631555+00:00 app[web.1]: at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.4.6.jar!/:5.4.6] 162021-04-26T10:14:13.631556+00:00 app[web.1]: at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:211) [spring-security-web-5.4.6.jar!/:5.4.6] 172021-04-26T10:14:13.631556+00:00 app[web.1]: at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:183) [spring-security-web-5.4.6.jar!/:5.4.6] 182021-04-26T10:14:13.631556+00:00 app[web.1]: at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358) [spring-web-5.3.6.jar!/:5.3.6] 192021-04-26T10:14:13.631557+00:00 app[web.1]: at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271) [spring-web-5.3.6.jar!/:5.3.6] 202021-04-26T10:14:13.631557+00:00 app[web.1]: at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.45.jar!/:na] 212021-04-26T10:14:13.631557+00:00 app[web.1]: at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.45.jar!/:na] 222021-04-26T10:14:13.631558+00:00 app[web.1]: at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) [spring-web-5.3.6.jar!/:5.3.6] 232021-04-26T10:14:13.631558+00:00 app[web.1]: at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.3.6.jar!/:5.3.6] 242021-04-26T10:14:13.631559+00:00 app[web.1]: at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.45.jar!/:na] 252021-04-26T10:14:13.631559+00:00 app[web.1]: at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.45.jar!/:na] 262021-04-26T10:14:13.631559+00:00 app[web.1]: at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) [spring-web-5.3.6.jar!/:5.3.6] 272021-04-26T10:14:13.631559+00:00 app[web.1]: at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.3.6.jar!/:5.3.6] 282021-04-26T10:14:13.631560+00:00 app[web.1]: at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.45.jar!/:na] 292021-04-26T10:14:13.631560+00:00 app[web.1]: at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.45.jar!/:na] 302021-04-26T10:14:13.631560+00:00 app[web.1]: at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.3.6.jar!/:5.3.6] 312021-04-26T10:14:13.631561+00:00 app[web.1]: at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.3.6.jar!/:5.3.6] 322021-04-26T10:14:13.631561+00:00 app[web.1]: at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.45.jar!/:na] 332021-04-26T10:14:13.631561+00:00 app[web.1]: at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.45.jar!/:na] 342021-04-26T10:14:13.631562+00:00 app[web.1]: at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) [tomcat-embed-core-9.0.45.jar!/:na] 352021-04-26T10:14:13.631562+00:00 app[web.1]: at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.45.jar!/:na] 362021-04-26T10:14:13.631562+00:00 app[web.1]: at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) [tomcat-embed-core-9.0.45.jar!/:na] 372021-04-26T10:14:13.631563+00:00 app[web.1]: at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) [tomcat-embed-core-9.0.45.jar!/:na] 382021-04-26T10:14:13.631563+00:00 app[web.1]: at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.45.jar!/:na] 392021-04-26T10:14:13.631563+00:00 app[web.1]: at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.45.jar!/:na] 402021-04-26T10:14:13.631564+00:00 app[web.1]: at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:764) 3.5.6.jar!/:3.5.6] 412021-04-26T10:14:13.631573+00:00 app[web.1]: at com.sun.proxy.$Proxy58.select(Unknown Source) ~[na:na] 422021-04-26T10:14:13.631573+00:00 app[web.1]: at
ローカル開発環境ではログイン機能がうまく動作していたはずなのに本番環境(Heroku)ではちゃんと機能せず、ログインすることができません。
また、mapperクラスとmapper.xmlを用意して接続するようにしています。
java
1@Configuration 2@EnableWebSecurity 3public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 4 5 @Autowired 6 private UserDetailsServiceImpl userDetailsService; 7 8 @Bean 9 public BCryptPasswordEncoder passwordEncoder() { 10 BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); 11 12 return bCryptPasswordEncoder; 13 } 14 15 @Override 16 public void configure(WebSecurity web) throws Exception { 17 18 web.ignoring().antMatchers("/images/**", "/css/**", "/js/**", "/felica/**"); 19 } 20 21 @Override 22 protected void configure(HttpSecurity http) throws Exception { 23 24 DelegatingRequestMatcherHeaderWriter headerWriter = new DelegatingRequestMatcherHeaderWriter(matcher, 25 new XFrameOptionsHeaderWriter(XFrameOptionsMode.SAMEORIGIN)); 26 27 http 28 .requiresChannel() 29 .requestMatchers(r -> r.getHeader("X-Forwarded-Proto") != null) 30 .requiresSecure() 31 .and() 32 .authorizeRequests() 33 .anyRequest().authenticated() 34 .and() 35 .formLogin() 36 .loginPage("/login") 37 .loginProcessingUrl("/sign_in") 38 .usernameParameter("userId") 39 .passwordParameter("password") 40 //.successForwardUrl("/loginRedirect") 41 .failureUrl("/login?error") 42 .permitAll() 43 .and() 44 .logout() 45 .logoutUrl("/logout") 46 .deleteCookies("JSESSIONID") 47 .invalidateHttpSession(true) 48 .logoutSuccessUrl("/login?logout") 49 .permitAll() 50 .and() 51 .headers().addHeaderWriter(headerWriter); 52 53 } 54 55 @Autowired 56 public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 57 BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); 58 auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder); 59 } 60 61}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。