春季安全性-用于授权和取消授权用户的主页设置

时间:2020-03-12 06:22:40

标签: spring-boot spring-security

我陷入了弹簧安全配置。谁能帮助我寻求更好的解决方案。我有2个jsp页面,一个用于登录用户,另一个用于简单用户。其中登录用户可以选择注销,而在其他jsp中则可以选择登录和注册。

我的安全配置类

@Configuration
@EnableWebSecurity
public class SecureConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    UserDetailsService userDetailsService;

    @Value("${winni.auth.exit}")
    private String authExit;

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

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

        http.csrf().disable().requestMatchers()
                .antMatchers("/login","/web/**" ,"/exit","/action/**","/cart/**","/cart/xhr/**","/buyer/**")
                .and()
                .authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .formLogin().permitAll().and()
                .logout().logoutSuccessUrl(authExit);
    }

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

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/assets/**","/account/**","/start/**");
    }
}

家庭控制器是

@RequestMapping("/")
    public String sayHello(Principal principal) {
        if (principal != null) {
            return "login_user";
        } else {
            return "simple_user";
        }

    }

在每种情况下,主体对象也为null。如何解决这个问题。

0 个答案:

没有答案