Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法将永久性记住我添加到Spring应用程序_Java_Spring_Spring Boot_Remember Me - Fatal编程技术网

Java 无法将永久性记住我添加到Spring应用程序

Java 无法将永久性记住我添加到Spring应用程序,java,spring,spring-boot,remember-me,Java,Spring,Spring Boot,Remember Me,我随后在SpringBoot2应用程序上设置了一个记住我的机制,但没有成功。即使我在登录时选中“记住我”复选框,也不会生成“记住我”cookie。没有抛出异常 这是我的SecurityConfiguration.java: import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation

我随后在SpringBoot2应用程序上设置了一个记住我的机制,但没有成功。即使我在登录时选中“记住我”复选框,也不会生成“记住我”cookie。没有抛出异常

这是我的SecurityConfiguration.java:

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;

import it.niuma.cse.service.UserDetailsServiceImp;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    public UserDetailsServiceImp  userDetailsService;

    @Autowired
    DataSource dataSource;

     @Bean
        public BCryptPasswordEncoder passwordEncoder() {
            BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
            return bCryptPasswordEncoder;
        }

    @Override
    protected void configure(AuthenticationManagerBuilder auth)
            throws Exception {
        auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
         http.csrf().disable();
        http.authorizeRequests().antMatchers("/", "/loginMe", "/logout").permitAll()
        .antMatchers("/fornitore/**").hasRole("USER")
        .antMatchers("/ruolo/**").hasRole("ADMIN")
        .anyRequest().authenticated();

        http.authorizeRequests().and().exceptionHandling().accessDeniedPage("/accessDenied");

        http.authorizeRequests().and().formLogin()//
         // Submit URL of login page.
        .loginProcessingUrl("/j_spring_security_check") // Submit URL
        .loginPage("/loginMe")//
        .defaultSuccessUrl("/loginOK")//
        .failureUrl("/loginMe?error=true")//
        .usernameParameter("username")//
        .passwordParameter("password")
         // Config for Logout Page
        .and()
        .rememberMe()
            .rememberMeCookieName("remember-me")
            .tokenValiditySeconds(24 * 60 * 60)
            .tokenRepository(persistentTokenRepository())
         .and().logout().logoutUrl("/logout").logoutSuccessUrl("/loginMe");
    }

    @Bean
    public PersistentTokenRepository persistentTokenRepository() {
        JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl();
        tokenRepository.setDataSource(dataSource);
        return tokenRepository;
    }

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