Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Spring security 使用spring引导配置的spring安全性_Spring Security_Spring Boot - Fatal编程技术网

Spring security 使用spring引导配置的spring安全性

Spring security 使用spring引导配置的spring安全性,spring-security,spring-boot,Spring Security,Spring Boot,我有一个SpringBoot应用程序,它使用SpringSecurity,配置了Java配置。理想情况下,我会有一个customer UserDetails服务,这样我就可以添加/修改用户。在此之前,我无法正确配置 我正在使用以下依赖项: compile("org.springframework.boot:spring-boot-starter-web:1.1.1.RELEASE") compile("org.springframework.boot:spring-boot:1.0.1.RELE

我有一个SpringBoot应用程序,它使用SpringSecurity,配置了Java配置。理想情况下,我会有一个customer UserDetails服务,这样我就可以添加/修改用户。在此之前,我无法正确配置

我正在使用以下依赖项:

compile("org.springframework.boot:spring-boot-starter-web:1.1.1.RELEASE")
compile("org.springframework.boot:spring-boot:1.0.1.RELEASE")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-data-jpa:1.1.1.RELEASE")
compile("org.springframework.security:spring-security-web:4.0.0.M1")
compile("org.springframework.security:spring-security-config:4.0.0.M1")
我有以下配置

@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
@Configuration
@EnableWebMvcSecurity
public class ApplicationSecurity extends WebSecurityConfigurerAdapter {

    @Autowired
    private DataSource datasource;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/").permitAll()
                .antMatchers("/resources/**").permitAll()
                .antMatchers("/css/**").permitAll();

        http
                .formLogin().failureUrl("/login?error")
                .defaultSuccessUrl("/")
                .loginPage("/login")
                .permitAll()
                .and()
                .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/")
                .permitAll();

        http
                .authorizeRequests().anyRequest().authenticated();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        JdbcUserDetailsManager userDetailsService = jdbcUserService();
//        userDetailsService.setDataSource(datasource);
//        PasswordEncoder encoder = new BCryptPasswordEncoder();

        auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
        auth.jdbcAuthentication().dataSource(datasource);
    }

    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    @Bean
    public org.springframework.security.provisioning.JdbcUserDetailsManager jdbcUserService() throws Exception {
        JdbcUserDetailsManager jdbcUserDetailsManager = new JdbcUserDetailsManager();
        jdbcUserDetailsManager.setDataSource(datasource);
        jdbcUserDetailsManager.setAuthenticationManager(authenticationManagerBean());
        return jdbcUserDetailsManager;
    }
}

@Order(Ordered.HIGHEST_PRECEDENCE)
@Configuration
public class AuthenticationSecurity extends GlobalAuthenticationConfigurerAdapter {

    @Autowired
    private DataSource dataSource;

    @Override
    public void init(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .jdbcAuthentication()
                .dataSource( dataSource );
    }
}
因此,我意识到我的配置是错误的,但并不确定如何最好地修复它们。症状是,当我登录到我的Thymeleaf UI时,会话从不存在


我使用了各种在线资源来学习和实施spring安全性。不幸的是,我仍然不明白为什么这是不正确的。

您似乎正在配置3个筛选器链(3个
websecurityConfigureAdapters
),但其中只有一个配置了
HttpSecurity
。那可能不是你想做的。也许可以合并成
WebSecurityConfigurerAdapter
和一个
globalaauthenticationconfigureradapter
,看看它能给你带来什么。

我根据你的建议合并了我的安全配置(我修改了我原来的帖子)。但是,我不知道如何超时用户会话或事件限制一个用户/会话的登录。我确实在spring引导文档中看到了“server.session timeout”,但没有看到最大会话数。这些是您以前没有提到的全新功能。建议你坚持原来的主题,为其他人打开新的主题。戴夫,事实上,原来的帖子中没有暂停。针对每个用户的限制会话提出的观点-我对混淆表示歉意。