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");

    }

 

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