springSecurity报错:Cannot pass a null GrantedAuthority collection

       Cannot pass a null GrantedAuthority collection,意思是不能传递一个空的已授权的集合,这是因为在配置类中没有配置角色,也就是没有给用户授予权限,它的权限集合是空的:

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("admin")
                .password("123")
                .and()
                .withUser("qxf")
                .password("123");

    }

 

解决办法就是给每个用户都配置角色,也就是授权:

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("admin")
                .password("123").roles("admin")
                .and()
                .withUser("qxf")
                .password("123").roles("user");

    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章