无法登录mysql + springBoot + jpa + ftl

时间:2019-03-26 03:08:30

标签: mysql spring-boot spring-mvc spring-security spring-data-jpa

我已设置为使用Spring Boot安全性进行用户登录/注册。

安全配置文件

    @Override
    protected void configure(AuthenticationManagerBuilder auth)
            throws Exception {
        auth.
                jdbcAuthentication()
                .usersByUsernameQuery(usersQuery)
                .authoritiesByUsernameQuery(rolesQuery)
                .dataSource(dataSource)
                .passwordEncoder(bCryptPasswordEncoder);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.
                authorizeRequests()
                .antMatchers("/").permitAll()
                .antMatchers("/login").permitAll()
                .antMatchers("/registration").permitAll()
                .antMatchers("/admin/**").hasAuthority("ADMIN").anyRequest()
                .authenticated().and().csrf().disable().formLogin()
                .loginPage("/login").failureUrl("/login?error=true")
                .defaultSuccessUrl("/admin/home")
                .usernameParameter("email")
                .passwordParameter("password")
                .and().logout()
                .logoutRequestMatcher(new AntPathRequestMatcher("/"))
                .logoutSuccessUrl("/")
                .and().rememberMe()
                .tokenRepository(persistentTokenRepository())
                .tokenValiditySeconds(60*60)
                .and().exceptionHandling().accessDeniedPage("/access_denied");;
    }


    @Bean
    public PersistentTokenRepository persistentTokenRepository() {
        JdbcTokenRepositoryImpl db = new JdbcTokenRepositoryImpl();
        db.setDataSource(dataSource);

        return db;
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web
                .ignoring()
                .antMatchers("/resources/**", "/static/**", "/css/**", "/js/**", "/img/**","/fonts");
    }

我的ftl文件

<form class="form-area contact-form " action="/login" method="POST">
							<div class="col-lg-6 form-group">

								<@spring.formInput path = "user.email"  attributes = "type=email" name="email"  attributes = "placeholder='Введите почту' class='common-input mb-20 form-control'"/>
								<@spring.showErrors "<br>" "class = 'bg-danger' "/>

								<@spring.formInput path = "user.password" type="password" name="password" attributes = "placeholder='Введите пароль' class='common-input mb-20 form-control'"/>
								<@spring.showErrors "<br>" "class = 'bg-danger'" />


							</div>
							<div class="col-lg-12">
								<div class="alert-msg" style="text-align: left;"></div>
								<@spring.showErrors "<br>" "class = 'bg-danger'" />

								<button class="primary-btn" type="submit" style="float: right;">Сохранить</button>
							</div>

					</form>

我的注册工作正常,但是当我无法登录,无法解决问题时,将很乐意为您提供帮助

https://github.com/balamanova/BagytWebSite 这是我的github代表

0 个答案:

没有答案